Skip to content

Commit

Permalink
Trusted Entitlements: add integration tests to verify `CustomerInfo…
Browse files Browse the repository at this point in the history
…` cache invalidation

I remembered this behavior while going through the code, so I thought it would be useful to encode as integration tests.
  • Loading branch information
NachoSoto committed Jun 28, 2023
1 parent 3b34874 commit 7704b12
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,61 @@ class EnforcedSignatureVerificationIntegrationTests: BaseSignatureVerificationIn

}

class DynamicModeSignatureVerificationIntegrationTests: BaseSignatureVerificationIntegrationTests {

private static var currentMode: Signing.ResponseVerificationMode = .disabled

override class var responseVerificationMode: Signing.ResponseVerificationMode {
return self.currentMode
}

override func setUp() async throws {
Self.currentMode = .disabled

try await super.setUp()
}

func testDisablingSignatureVerificationDoesNotResetCustomerInfoCache() async throws {
// 1. Start with enforced mode
await self.changeMode(to: Signing.enforcedVerificationMode())

// 2. Fetch CustomerInfo
_ = try await Purchases.shared.customerInfo()

// 3. Disable verification again
await self.changeMode(to: .disabled)

// 4. Verify CustomerInfo is still cached
_ = try await Purchases.shared.customerInfo(fetchPolicy: .fromCacheOnly)
}

func testEnablingSignatureVerificationResetsCustomerInfoCache() async throws {
// 1. Fetch CustomerInfo
_ = try await Purchases.shared.customerInfo()

// 2. Enable signature verification
await self.changeMode(to: Signing.enforcedVerificationMode())

// 3. Verify CustomerInfo is not cached anymore
do {
_ = try await Purchases.shared.customerInfo(fetchPolicy: .fromCacheOnly)
} catch {
expect(error).to(matchError(ErrorCode.customerInfoError))
expect(error.localizedDescription)
.to(
contain(Strings.purchase.missing_cached_customer_info.description),
description: "Unexpected error: \(error)"
)
}
}

private func changeMode(to newMode: Signing.ResponseVerificationMode) async {
Self.currentMode = newMode
await self.resetSingleton()
}

}

// MARK: - Private

private extension BaseSignatureVerificationIntegrationTests {
Expand Down

0 comments on commit 7704b12

Please sign in to comment.