SPB Git

Repository Public License

Fixtures.swift 4.2 KB 59 lines swift

1// ORIX Secure2// File: Packages/ORIXSecureEngines/Tests/ORIXSecureEnginesTests/Fixtures.swift3// Description: Synthetic device snapshots and security signals for the engine tests.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation8import ORIXSecureModel9@testable import ORIXSecureEngines1011enum Fixture {12    static let now = Date(timeIntervalSince1970: 1_800_000_000)13    static let gb: Int64 = 1_000_000_0001415    static func device(16        os: String = "26.5", major: Int = 26, sdk: String? = "26.5", simulator: Bool = false, thermal: ThermalLevel = .nominal, lowPower: Bool = false,17        battery: Reading<Double> = .measured(0.8), state: Reading<BatteryChargeState> = .measured(.unplugged), total: Int64 = 256 * gb, free: Int64 = 100 * gb,18        cores: Int = 6, activeCores: Int = 6, bootDaysAgo: Double = 319    ) -> DeviceSnapshot {20        DeviceSnapshot(21            modelIdentifier: "iPhone18,1", modelFamily: "iPhone", idiom: .phone, isSimulator: simulator, systemName: "iOS", systemVersion: os,22            systemMajorVersion: major, builtAgainstSDKVersion: sdk,23            screen: .measured(ScreenInfo(pointWidth: 402, pointHeight: 874, scale: 3, nativePixelWidth: 1206, nativePixelHeight: 2622, maximumFramesPerSecond: 120)),24            processorCount: cores, activeProcessorCount: activeCores, physicalMemory: 12 * gb, appAvailableMemory: .measured(3 * gb),25            appMemoryFootprint: .measured(80_000_000), thermal: thermal, lowPowerMode: lowPower, batteryLevel: battery, batteryState: state,26            volume: VolumeCapacity(total: .measured(total), available: .measured(free), availableForImportantUsage: .measured(free),27                                   availableForOpportunisticUsage: .measured(free)),28            lastBoot: .measured(now.addingTimeInterval(-bootDaysAgo * 86_400)), capturedAt: now)29    }3031    static func signals(32        passcode: Reading<Bool> = .measured(true), biometry: BiometryKind = .faceID, enrolled: Reading<Bool> = .measured(true), lockedOut: Bool = false,33        enclave: Bool = true, attest: Reading<Bool> = .measured(true), debugger: Reading<Bool> = .measured(false), indicators: [IntegrityIndicator] = [],34        checks: Int = 25, protection: Reading<String> = .measured(FileProtectionType.complete.rawValue), captured: Reading<Bool> = .measured(false)35    ) -> SecuritySignals {36        SecuritySignals(passcodeSet: passcode, biometryKind: biometry, biometryEnrolled: enrolled, biometryLockedOut: lockedOut, secureEnclaveAvailable: enclave,37                        appAttestSupported: attest, debuggerAttached: debugger, integrityIndicators: indicators, integrityChecksPerformed: checks,38                        fileProtection: protection, screenCaptured: captured, capturedAt: now)39    }4041    /// Words the product never uses about a device, a link or a file.42    static let forbiddenWords = ["100% secure", "malware-free", "no malware detected", "virus", "infected", "hacked", "your device is safe", "is safe to"]4344    static func assertHonest(_ findings: [Finding]) -> [String] {45        var problems: [String] = []46        for finding in findings {47            if finding.title.isEmpty { problems.append("\(finding.id): empty title") }48            if finding.explanation.isEmpty { problems.append("\(finding.id): empty explanation") }49            if [.verified, .attention, .userConfirmed].contains(finding.state), finding.evidence.isEmpty { problems.append("\(finding.id): no evidence") }50            if finding.state == .attention, finding.severity == .none { problems.append("\(finding.id): attention without severity") }51            if finding.state == .attention, finding.recommendation == nil, finding.id != "device.cores" { problems.append("\(finding.id): attention without recommendation") }52            if finding.state != .attention, finding.severity != .none { problems.append("\(finding.id): severity on a non-attention finding") }53            let text = ([finding.title, finding.explanation, finding.recommendation ?? ""] + finding.notInspected).joined(separator: " ").lowercased()54            for word in forbiddenWords where text.contains(word) { problems.append("\(finding.id): uses “\(word)”") }55        }56        return problems57    }58}59
Files main
Menu

Theme