test: drop tautological assertions, cover real OAuth + expiry invariants#4
Merged
Conversation
- PKCE: replace "verifier != challenge" / "two generations differ" (universe-luck passes) with the RFC 7636 4.2 invariant: challenge == base64url(SHA256(verifier)) - Credentials: drop the synthesized-Codable round-trip; add coverage for the 60s leeway window (existing -120s/+300s tests skipped it) and a Keychain key-stability check - LocalCallbackServer: drop parseCallbackExtractsCodeAndState — it only echoed the init parameter back
10704cf to
d81334e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removed three tests that pass by luck of the universe (not by checking anything) and one that lied about what it tests, then added coverage for invariants that would actually break sign-in or sign users out if they regressed.
Removed
PKCETests.verifierAndChallengeAreDifferent/eachGenerationIsUnique— SHA-256 doesn't collide with its input, and two random 64-byte buffers don't repeat. Neither could ever fail.PKCETests.generatedPKCEHasVerifierAndChallenge— empty-string smoke check, subsumed by the length+charset test.CredentialsTests.equalityAndCodingRoundTrip— encoded then decoded with the sameJSONEncoder/JSONDecoder, asserting equality. Tests the Swift compiler's synthesizedCodable, not our contract.LocalCallbackServerTests.parseCallbackExtractsCodeAndState— the body only assertedserver.callbackPath == "/auth/callback"after constructing the server with that string. Init-parameter echo masquerading as a parser test.Added
PKCETests.challengeIsBase64URLEncodedSHA256OfVerifier— RFC 7636 §4.2:challenge == BASE64URL(SHA256(verifier)). If this drifts, the OpenAI token endpoint rejects the auth-code exchange withinvalid_grant.CredentialsTests.credentialsAreExpiredWithinDefaultLeewayWindow— a token expiring in 30s must already count as expired soAuthService.credentials(for:)triggers a refresh before clock skew causes a 401 mid-request.CredentialsTests.customLeewayChangesTheExpiryThreshold— same token, different leeway → flips the result either way.CredentialsTests.persistedJSONKeysAreStable— protects the on-disk Keychain shape: any key rename silently signs every existing user out on the next launch.Test plan
swift test— 45/45 pass