Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP ID & Card Vault7// File : SPVaultUITests/RealBiometryUITests.swift8// Module : Tests9// Repository : https://git.spboucher.ai/sp-id-card-vault10// Project Website : Not specified11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import XCTest4243/// Exercises the real LocalAuthentication path in the simulator: no `-uiTesting`44/// flag, so the app uses its normal vault directory and `SimulatorKeyProtector`,45/// which evaluates a genuine `LAContext`. The simulator's Face ID is driven from46/// the host by `scripts/biometry-check.sh` (matching or non-matching face).47/// Skipped unless `SPV_REAL_BIOMETRY` is set, because it needs that host script.48@MainActor49final class RealBiometryUITests: XCTestCase {50 private let app = XCUIApplication()51 private let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")52 private static let recovery = "correct horse battery staple 42"5354 override func setUpWithError() throws {55 continueAfterFailure = false56 try XCTSkipUnless(ProcessInfo.processInfo.environment["SPV_REAL_BIOMETRY"] != nil, "host-driven Face ID run only")57 }5859 private func completeOnboardingIfShown() {60 let primary = app.buttons["onboarding.primary"]61 guard primary.waitForExistence(timeout: 8) else { return }62 primary.tap() // welcome63 primary.tap() // protection64 XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "onboarding.biometry.status").firstMatch.waitForExistence(timeout: 5))65 primary.tap() // Face ID ready66 let field = app.secureTextFields["onboarding.passphrase"]67 XCTAssertTrue(field.waitForExistence(timeout: 5))68 field.tap(); field.typeText(Self.recovery)69 let confirmation = app.secureTextFields["onboarding.confirmation"]70 confirmation.tap(); confirmation.typeText(Self.recovery)71 if app.keyboards.buttons["Return"].exists { app.keyboards.buttons["Return"].tap() }72 else if app.keyboards.buttons["return"].exists { app.keyboards.buttons["return"].tap() }73 primary.tap()74 let skip = app.buttons["onboarding.skipNotifications"]75 XCTAssertTrue(skip.waitForExistence(timeout: 5))76 skip.tap()77 }7879 /// Host posts a matching face: the vault is created, then reopens after a80 /// trip to the background, through a real biometric evaluation.81 func testMatchingFaceUnlocks() {82 app.launch()83 completeOnboardingIfShown()84 XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: 30), "vault did not open with a matching face")85 XCUIDevice.shared.press(.home)86 sleep(2)87 app.activate()88 XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: 30), "vault did not reopen with a matching face")89 XCTAssertFalse(app.buttons["lock.unlock"].exists)90 }9192 /// Host posts a non-matching face: the vault stays locked and says so.93 func testNonMatchingFaceStaysLocked() {94 app.launch()95 let unlock = app.buttons["lock.unlock"]96 let deadline = Date().addingTimeInterval(40)97 var sawLockScreen = false98 while Date() < deadline {99 // The system sheet offers "Cancel" after failed attempts.100 for label in ["Cancel", "Annuler"] where springboard.buttons[label].exists { springboard.buttons[label].tap() }101 if unlock.exists, unlock.isHittable { sawLockScreen = true; break }102 XCTAssertFalse(app.tabBars.firstMatch.exists, "the vault opened with a non-matching face")103 usleep(400_000)104 }105 XCTAssertTrue(sawLockScreen, "the lock screen did not come back after the refused attempt")106 XCTAssertFalse(app.tabBars.firstMatch.exists)107 // Dismissing the system sheet is a cancellation, which shows no error108 // text; the state pill must still read "Locked".109 XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "lock.status").firstMatch.waitForExistence(timeout: 5))110 }111}112