Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trusted Entitlements: add integration tests to verify CustomerInfo cache invalidation #2730

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,76 @@ 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 testChangingToInformationalModeResetsCustomerInfoCache() async throws {
// 1. Fetch CustomerInfo
_ = try await Purchases.shared.customerInfo()

// 2. Enable signature verification
await self.changeMode(to: Signing.verificationMode(with: .informational))

// 3. Verify CustomerInfo is not cached anymore
await self.verifyNoCachedCustomerInfo()
}

func testChangingToEnforcedModeResetsCustomerInfoCache() 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
await self.verifyNoCachedCustomerInfo()
}

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

private func verifyNoCachedCustomerInfo() async {
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)"
)
}
}

}

// MARK: - Private

private extension BaseSignatureVerificationIntegrationTests {
Expand Down