Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/ThreemaFrameworkTests/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 3 kB image not shown  

Quelle  AppSetupRecomputeTests.swift   Sprache: JAVA

 

import Testing
@testable import ThreemaFramework

struct AppSetupRecomputeTests {

    @Test("A present identity with a preexisting database becomes .complete and is persisted")
    func presentWithDatabaseIsComplete() {
        let result = AppSetup.recomputeState(
            identityPresence: .present,
            hasPreexistingDatabaseFile: true,
            protectedDataAvailable: true
        )

        #expect(result.state == .complete)
        #expect(result.shouldPersist)
        #expect(result.unavailable == nil)
    }

    @Test("A present identity without a preexisting database becomes .notSetup (app deleted, ID left in keychain)")
    func presentWithoutDatabaseIsNotSetup() {
        let result = AppSetup.recomputeState(
            identityPresence: .present,
            hasPreexistingDatabaseFile: false,
            protectedDataAvailable: true
        )

        #expect(result.state == .notSetup)
        #expect(result.shouldPersist)
        #expect(result.unavailable == nil)
    }

    @Test("An absent identity becomes .notSetup and is persisted (fresh install / completed erase)")
    func absentIsNotSetup() {
        let result = AppSetup.recomputeState(
            identityPresence: .absent,
            hasPreexistingDatabaseFile: true,
            protectedDataAvailable: true
        )

        #expect(result.state == .notSetup)
        #expect(result.shouldPersist)
        #expect(result.unavailable == nil)
    }

    /// Regression: the permanence behind the "open to fetch" onboarding bug. An undetermined identity presence
    /// (keychain read failure) must return `.notSetup` transiently but MUST NOT be persisted, so the state
    /// self-heals on the next read once the keychain is available again.
    @Test("An undetermined identity is NOT persisted, so a transient keychain failure never sticks")
    func undeterminedIsNotPersisted() {
        let result = AppSetup.recomputeState(
            identityPresence: .undetermined,
            hasPreexistingDatabaseFile: true,
            protectedDataAvailable: true
        )

        #expect(result.state == .notSetup)
        #expect(result.shouldPersist == false)
        #expect(result.unavailable == .keychainUnreadable)
    }

    /// Regression: the UserDefaults-while-locked corruption. While protected data is unavailable the app-group
    /// UserDefaults reads the state key as 0 even for a fully set up app, so the recompute must NOT persist,
    /// even if the identity looks present, otherwise it would clobber the real `.complete` on disk.
    @Test("Nothing is persisted while protected data is unavailable, even if the identity looks present")
    func protectedDataUnavailableNeverPersists() {
        let result = AppSetup.recomputeState(
            identityPresence: .present,
            hasPreexistingDatabaseFile: true,
            protectedDataAvailable: false
        )

        #expect(result.state == .notSetup)
        #expect(result.shouldPersist == false)
        #expect(result.unavailable == .protectedDataUnavailable)
    }

    @Test("A locked device and an unreadable keychain are reported as different reasons")
    func unavailableReasonsAreDistinct() {
        let locked = AppSetup.recomputeState(
            identityPresence: .undetermined,
            hasPreexistingDatabaseFile: true,
            protectedDataAvailable: false
        )
        let unreadable = AppSetup.recomputeState(
            identityPresence: .undetermined,
            hasPreexistingDatabaseFile: true,
            protectedDataAvailable: true
        )

        #expect(locked.unavailable != unreadable.unavailable)
    }
}

Messung
CHZG
859710094

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.