Repository Public License
1// ORIX Secure2// File: UITests/ORIXSecureUITests.swift3// Description: UI tests on the running app with an isolated in-memory store: first launch, every screen, the checklist semantics,4// link and file analysis on real inputs, live network probes, photo cleanup with a real deletion, workflows, exports.5// Screenshots are attached to the result bundle; the README screenshots come from these runs.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import XCTest1011@MainActor final class ORIXSecureUITests: XCTestCase {12 private var app: XCUIApplication!13 private let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")14 private var isPad: Bool { UIDevice.current.userInterfaceIdiom == .pad }1516 override func setUp() async throws {17 continueAfterFailure = false18 XCUIDevice.shared.appearance = .light19 if isPad { XCUIDevice.shared.orientation = .landscapeLeft }20 }2122 private func launch(demo: Bool = false, section: String? = nil, extra: [String] = []) {23 app = XCUIApplication()24 var arguments = ["-ORIXUITest", "YES", "-ORIXReset", "YES", "-ORIXDemo", demo ? "YES" : "NO", "-AppleLanguages", "(en)", "-AppleLocale", "en_CA"]25 if let section { arguments += ["-ORIXSection", section] }26 app.launchArguments = arguments + extra27 app.launch()28 }2930 private func shot(_ name: String) {31 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())32 attachment.name = name33 attachment.lifetime = .keepAlways34 add(attachment)35 }3637 private func element(_ identifier: String) -> XCUIElement { app.descendants(matching: .any)[identifier].firstMatch }3839 @discardableResult private func waitFor(_ identifier: String, timeout: TimeInterval = 20, file: StaticString = #filePath, line: UInt = #line) -> XCUIElement {40 let found = element(identifier)41 XCTAssertTrue(found.waitForExistence(timeout: timeout), "\(identifier) did not appear", file: file, line: line)42 return found43 }4445 /// Scrolls until the element can be tapped, then taps it.46 private func tap(_ identifier: String, file: StaticString = #filePath, line: UInt = #line) {47 let target = element(identifier)48 var attempts = 049 // Lazy containers create rows only when they come on screen: scroll until the element exists and can be tapped.50 while !(target.waitForExistence(timeout: attempts == 0 ? 8 : 1) && target.isHittable), attempts < 14 {51 app.swipeUp(velocity: .slow)52 attempts += 153 }54 XCTAssertTrue(target.exists, "\(identifier) did not appear", file: file, line: line)55 target.tap()56 }5758 /// A button of the system alert shown by iOS itself (the simulator's system language may not be English).59 private func systemAlertButton(_ labels: [String], timeout: TimeInterval = 15) -> XCUIElement {60 let button = springboard.alerts.buttons.matching(NSPredicate(format: "label IN %@", labels)).firstMatch61 _ = button.waitForExistence(timeout: timeout)62 return button63 }6465 private func allowPhotoAccessIfAsked() {66 guard element("photos.requestAccess").waitForExistence(timeout: 5) else { return }67 element("photos.requestAccess").tap()68 let allow = systemAlertButton(["Allow Full Access", "Autoriser l’accès complet"])69 XCTAssertTrue(allow.exists, "system photo prompt did not appear")70 allow.tap()71 }7273 private func text(containing fragment: String) -> XCUIElement {74 app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] %@", fragment)).firstMatch75 }7677 private func anyLabel(containing fragment: String, timeout: TimeInterval = 15) -> Bool {78 app.descendants(matching: .any).containing(NSPredicate(format: "label CONTAINS[c] %@", fragment)).firstMatch.waitForExistence(timeout: timeout)79 }8081 // MARK: First launch and overview8283 func testFirstLaunchExplainsLimitsThenShowsTheOverview() {84 app = XCUIApplication()85 app.launchArguments = ["-ORIXUITest", "YES", "-ORIXReset", "YES", "-ORIXWelcome", "YES", "-AppleLanguages", "(en)"]86 app.launch()87 waitFor("welcome.start")88 XCTAssertTrue(anyLabel(containing: "No app can scan an iPhone for malware"))89 shot("00-welcome")90 element("welcome.start").tap()91 waitFor("dashboard.assessment")92 // No account, no permission prompt at launch.93 XCTAssertEqual(app.alerts.count, 0)94 XCTAssertEqual(springboard.alerts.count, 0)95 }9697 func testOverviewShowsCountsNotAScore() {98 launch(demo: true)99 waitFor("dashboard.assessment")100 XCTAssertTrue(anyLabel(containing: "This shows what was checked, not how secure the device is"))101 XCTAssertFalse(anyLabel(containing: "100%", timeout: 1))102 XCTAssertFalse(anyLabel(containing: "No malware", timeout: 1))103 shot("01-dashboard")104 element("dashboard.method").tap()105 waitFor("methodology")106 XCTAssertTrue(anyLabel(containing: "does not compute a security score"))107 shot("01b-methodology")108 element("method.done").tap()109 tap("limits.card")110 XCTAssertTrue(anyLabel(containing: "System-wide malware scan"))111 }112113 // MARK: Security audit and checklist114115 func testAuditFindingShowsEvidenceMethodAndLimits() {116 launch(demo: true, section: "securityAudit")117 waitFor("audit")118 shot("02-security-audit")119 tap("finding.device.restart")120 waitFor("finding.detail")121 for heading in ["What it means", "How it was established", "Evidence"] {122 XCTAssertTrue(anyLabel(containing: heading), heading)123 }124 shot("02b-finding-detail")125 element("finding.done").tap()126 tap("audit.save")127 }128129 func testChecklistAnswerIsRecordedAsReportedByTheUser() {130 launch(section: "checklist")131 waitFor("checklist")132 XCTAssertTrue(anyLabel(containing: "0 of 16 checked"))133 tap("checklist.sec.account.2fa")134 waitFor("checklist.item")135 XCTAssertTrue(anyLabel(containing: "never presents it as verified"))136 shot("03b-checklist-item")137 tap("answer.yes")138 element("check.done").tap()139 XCTAssertTrue(anyLabel(containing: "1 of 16 checked"))140 let row = element("checklist.sec.account.2fa")141 XCTAssertTrue(row.label.contains("Confirmed by you"), row.label)142 XCTAssertFalse(row.label.contains("Verified"))143 // The opposite answer becomes a recommended action with the item's severity.144 tap("checklist.sec.account.2fa")145 tap("answer.no")146 XCTAssertTrue(anyLabel(containing: "Recommended action"))147 element("check.done").tap()148 XCTAssertTrue(element("checklist.sec.account.2fa").label.contains("Attention recommended"))149 shot("03-checklist")150 }151152 func testPrivacyAuditReadsOnlyItsOwnPermissions() {153 launch(demo: true, section: "privacy")154 waitFor("privacy")155 XCTAssertTrue(anyLabel(containing: "The only permission states an app can read are its own"))156 shot("04-privacy-audit")157 tap("finding.privacy.app.photos")158 waitFor("finding.detail")159 XCTAssertTrue(anyLabel(containing: "permissions of other apps cannot be read"))160 element("finding.done").tap()161 tap("privacy.save")162 }163164 // MARK: Investigations165166 func testInvestigationSeparatesObservationsReportsAndHypotheses() {167 launch(section: "investigations")168 waitFor("investigations")169 shot("05-investigations")170 tap("symptom.suspiciousLink")171 waitFor("investigation")172 let question = waitFor("question.enteredPassword")173 question.buttons["Yes"].tap()174 tap("investigation.evaluate")175 waitFor("hypothesis.b.phished")176 XCTAssertTrue(element("hypothesis.b.phished").label.contains("Supported"))177 XCTAssertTrue(element("hypothesis.z.compromise").waitForExistence(timeout: 5))178 XCTAssertTrue(element("hypothesis.z.compromise").label.contains("Less likely"))179 XCTAssertTrue(anyLabel(containing: "None is a confirmed diagnosis"))180 XCTAssertTrue(anyLabel(containing: "Change that password"))181 shot("05b-investigation-report")182 tap("investigation.save")183 XCTAssertTrue(anyLabel(containing: "Report Saved"))184 }185186 // MARK: Storage187188 func testStorageShowsMeasuredCapacityAndVerifiedOwnCleanup() {189 launch(demo: true, section: "storage")190 waitFor("storage.volume")191 XCTAssertTrue(anyLabel(containing: "available"))192 shot("06-storage")193 tap("limits.card")194 XCTAssertTrue(anyLabel(containing: "cannot delete another app's cache"))195 }196197 func testFileCleanupDeletesOnlySelectedDuplicatesAfterConfirmation() {198 launch(section: "fileCleanup", extra: ["-ORIXSampleFolder", "YES"])199 waitFor("files.duplicateSummary", timeout: 30)200 XCTAssertTrue(element("files.duplicateSummary").label.contains("2 extra copies in 1 group"), element("files.duplicateSummary").label)201 XCTAssertTrue(element("files.largeSummary").label.contains("5 files"))202 XCTAssertFalse(element("files.delete").exists, "nothing is selected by default")203 app.buttons["Select Extra Copies"].firstMatch.tap()204 shot("07-file-cleanup")205 tap("files.delete")206 let confirm = app.buttons["Delete 2 File(s)"].firstMatch207 XCTAssertTrue(confirm.waitForExistence(timeout: 5))208 confirm.tap()209 waitFor("files.result")210 XCTAssertTrue(element("files.result").label.contains("2 file(s) deleted"), element("files.result").label)211 XCTAssertTrue(element("files.duplicateSummary").label.contains("No byte-identical files") || !app.buttons["Select Extra Copies"].exists)212 }213214 // MARK: Photo cleanup (real library, real deletion)215216 func testPhotoCleanupFindsDuplicatesAndDeletesOnlyAfterTwoConfirmations() throws {217 launch(section: "photoCleanup")218 allowPhotoAccessIfAsked()219 tap("photos.scan")220 waitFor("photos.totals", timeout: 120)221 shot("08a-photo-scan-result")222 try XCTSkipUnless(element("photos.category.exactDuplicates").waitForExistence(timeout: 5), "no exact duplicates in this simulator (run Scripts/seed-photos.sh): \(element("photos.totals").label)")223 shot("08-photo-cleanup")224 XCTAssertTrue(anyLabel(containing: "cleanup candidates"))225 element("photos.category.exactDuplicates").tap()226 waitFor("photos.categoryDetail")227 XCTAssertTrue(anyLabel(containing: "Keep"))228 shot("08b-duplicate-photos")229 element("category.done").tap()230 // Exact-duplicate extras are preselected; the review states what will happen.231 tap("photos.review")232 waitFor("review.plan")233 XCTAssertTrue(anyLabel(containing: "Recently Deleted"))234 shot("08c-cleanup-review")235 // First pass: decline the system confirmation — nothing is deleted.236 element("review.delete").tap()237 let dontDelete = systemAlertButton(["Don’t Allow", "Don't Allow", "Don’t Delete", "Ne pas autoriser", "Ne pas supprimer", "Cancel", "Annuler"])238 XCTAssertTrue(dontDelete.exists, "system delete confirmation did not appear: \(springboard.alerts.buttons.allElementsBoundByIndex.map(\.label))")239 dontDelete.tap()240 waitFor("photos.result")241 XCTAssertTrue(element("photos.result").label.contains("nothing was deleted"), element("photos.result").label)242 shot("08d-cleanup-declined")243 }244245 func testPhotoDeletionIsVerifiedAndReported() throws {246 launch(section: "photoCleanup")247 allowPhotoAccessIfAsked()248 tap("photos.scan")249 waitFor("photos.totals", timeout: 120)250 try XCTSkipUnless(element("photos.review").waitForExistence(timeout: 5), "no preselected exact duplicates left in this simulator")251 tap("photos.review")252 waitFor("review.plan")253 element("review.delete").tap()254 let delete = systemAlertButton(["Delete", "Supprimer"])255 XCTAssertTrue(delete.exists, "system delete confirmation did not appear: \(springboard.alerts.buttons.allElementsBoundByIndex.map(\.label))")256 delete.tap()257 waitFor("photos.result")258 XCTAssertTrue(element("photos.result").label.contains("moved to Recently Deleted"), element("photos.result").label)259 XCTAssertTrue(element("photos.result").label.contains("30 days") || anyLabel(containing: "Recently Deleted"))260 shot("08e-cleanup-result")261 }262263 // MARK: Tools264265 func testLinkAnalyserExplainsALookalikeWithoutOpeningIt() {266 launch(section: "linkAnalyzer", extra: ["-ORIXLink", "https://apple.com.account-verify.example.net/login?next=https%3A%2F%2Fevil.example%2F"])267 waitFor("link.level")268 XCTAssertFalse(element("link.level").label.contains("No signals"))269 waitFor("link.anatomy")270 XCTAssertTrue(element("link.anatomy").label.contains("example.net") || anyLabel(containing: "example.net"))271 shot("09-link-analysis")272 // A plain well-known address: no brand or structural signal, and still no claim of safety.273 tap("link.clear")274 let input = waitFor("link.input")275 input.tap()276 input.typeText("https://www.apple.com/iphone/")277 tap("link.analyze")278 waitFor("link.level")279 XCTAssertTrue(anyLabel(containing: "not proof that a link is harmless"))280 XCTAssertFalse(anyLabel(containing: "is safe", timeout: 1))281 shot("09b-link-no-signals")282 }283284 func testPunycodeLookalikeShowsBothForms() {285 launch(section: "linkAnalyzer", extra: ["-ORIXLink", "https://xn--pple-43d.com/id"])286 waitFor("link.anatomy")287 XCTAssertTrue(anyLabel(containing: "xn--pple-43d.com"))288 XCTAssertTrue(anyLabel(containing: "Punycode"))289 shot("09c-link-homograph")290 }291292 func testFileScannerInspectsARealArchive() {293 launch(section: "fileScanner", extra: ["-ORIXSampleFile", "YES"])294 waitFor("file.summary", timeout: 30)295 waitFor("file.hash")296 XCTAssertTrue(anyLabel(containing: "ZIP"))297 XCTAssertTrue(element("file.summary").label.contains("finding(s) to review"), element("file.summary").label)298 shot("10-file-scanner")299 tap("limits.card")300 tap("file.save")301 }302303 func testNetworkLabRunsLiveProbes() {304 launch(section: "network")305 waitFor("network.connection")306 waitFor("network.wifi")307 tap("network.run")308 waitFor("network.tls", timeout: 30)309 let certificate = element("network.certificate.0")310 XCTAssertTrue(certificate.waitForExistence(timeout: 30), "no certificate was read (is the Mac online?)")311 XCTAssertTrue(anyLabel(containing: "TLS 1."))312 shot("11-network-lab")313 var attempts = 0314 while !certificate.isHittable, attempts < 8 { app.swipeUp(velocity: .slow); attempts += 1 }315 certificate.tap()316 waitFor("certificate")317 XCTAssertTrue(anyLabel(containing: "SHA-256 fingerprint"))318 shot("11b-certificate")319 element("certificate.done").tap()320 }321322 func testDeviceListsUnavailableMeasurementsInsteadOfInventingThem() {323 launch(section: "device")324 waitFor("device")325 shot("12-device")326 XCTAssertTrue(element("reading.battery").waitForExistence(timeout: 5))327 XCTAssertTrue(element("reading.battery").label.contains("Not available"), "the Simulator has no battery: \(element("reading.battery").label)")328 tap("device.unavailable")329 XCTAssertTrue(anyLabel(containing: "Battery cycle count"))330 XCTAssertTrue(anyLabel(containing: "Processor temperature"))331 XCTAssertFalse(anyLabel(containing: "°C", timeout: 1))332 }333334 func testBatteryAdvisorOffersNoBoosters() {335 launch(section: "battery")336 waitFor("battery.readings")337 shot("13-battery")338 tap("battery.notOffered")339 XCTAssertTrue(anyLabel(containing: "No “RAM boost”"))340 XCTAssertEqual(app.buttons.matching(NSPredicate(format: "label CONTAINS[c] %@", "boost")).count, 0)341 }342343 // MARK: Reports, actions, settings344345 func testReportsCanBeReadAndExportedInFourFormats() {346 launch(demo: true, section: "reports")347 waitFor("reports")348 XCTAssertEqual(app.descendants(matching: .any).matching(identifier: "report.row").count, 3)349 shot("14-reports")350 app.descendants(matching: .any).matching(identifier: "report.row").firstMatch.tap()351 waitFor("report.detail")352 XCTAssertTrue(anyLabel(containing: "It is not a malware scan"))353 shot("14b-report")354 tap("report.export")355 for format in ["pdf", "markdown", "json", "plainText"] {356 XCTAssertTrue(element("export." + format).waitForExistence(timeout: 5), format)357 }358 element("export.pdf").tap()359 // The system share sheet appears with the generated file.360 XCTAssertTrue(app.otherElements["ActivityListView"].waitForExistence(timeout: 15) || app.navigationBars["UIActivityContentView"].waitForExistence(timeout: 5))361 }362363 func testWorkflowRunsRealStepsAndSavesItsReport() {364 launch(section: "actions")365 waitFor("actions")366 shot("15-actions")367 tap("workflow.Security check-up")368 waitFor("run.steps")369 tap("run.start")370 waitFor("run.finished", timeout: 60)371 shot("15b-workflow-run")372 XCTAssertTrue(element("run.step.0").label.contains("Done"), element("run.step.0").label)373 element("run.close").tap()374 }375376 func testWorkflowEditorRefusesDeletionWithoutReview() {377 launch(section: "actions")378 tap("workflow.new")379 let name = waitFor("editor.name")380 name.tap()381 name.typeText("Risky")382 tap("editor.add.photos.delete")383 element("editor.save").tap()384 XCTAssertTrue(waitFor("editor.error").exists, "a deletion step without a review step must be refused")385 }386387 func testSettingsAndCapabilityStatement() {388 launch(demo: true, section: "settings")389 waitFor("settings")390 shot("16-settings")391 tap("settings.capabilities")392 waitFor("capabilities")393 XCTAssertTrue(anyLabel(containing: "ORIX Secure is not an antivirus"))394 shot("16b-capabilities")395 }396397 // MARK: Appearance and navigation398399 func testDarkAppearance() {400 XCUIDevice.shared.appearance = .dark401 launch(demo: true)402 waitFor("dashboard.assessment")403 shot("17-dashboard-dark")404 XCUIDevice.shared.appearance = .light405 }406407 func testFrenchCanadianLocalization() {408 app = XCUIApplication()409 app.launchArguments = ["-ORIXUITest", "YES", "-ORIXReset", "YES", "-ORIXDemo", "YES", "-AppleLanguages", "(fr-CA)", "-AppleLocale", "fr_CA"]410 app.launch()411 waitFor("dashboard.assessment")412 // Interface text and engine text both come from the French catalog.413 XCTAssertTrue(anyLabel(containing: "Évaluation de la sécurité"), "interface title is not in French")414 XCTAssertTrue(anyLabel(containing: "Confirmé par vous"), "engine state title is not in French")415 XCTAssertFalse(anyLabel(containing: "Recommended actions", timeout: 1))416 shot("18-dashboard-fr")417 app.terminate()418 app.launchArguments += ["-ORIXSection", "securityAudit"]419 app.launch()420 waitFor("audit")421 shot("18b-audit-fr")422 }423424 func testEveryTopLevelScreenOpens() {425 for section in ["dashboard", "securityAudit", "checklist", "privacy", "investigations", "storage", "photoCleanup", "fileCleanup",426 "linkAnalyzer", "fileScanner", "network", "device", "battery", "reports", "actions", "settings"] {427 launch(demo: true, section: section)428 XCTAssertTrue(app.navigationBars.firstMatch.waitForExistence(timeout: 20), section)429 XCTAssertEqual(app.state, .runningForeground, section)430 if isPad { shot("pad-" + section) }431 }432 }433}434