Skip to content

Conversation

@armcknight
Copy link
Member

We originally did this for a mobile app, but we may now also be adding a mac app, so this should be more generic (the old name was already out of date anyways)

@armcknight armcknight requested a review from a team as a code owner December 16, 2025 19:04
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 16, 2025
@armcknight armcknight changed the title feat: update to more generic schema to support other Apple apps feat(ILOC): update to more generic schema to support other Apple apps Dec 16, 2025
# expires_in should be a positive integer number of seconds until expiry
assert fragment_d["expires_in"]
assert fragment_d["token_type"] == ["bearer"]
assert int(fragment_d["expires_in"][0]) > 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The OAuth token response contains a negative expires_in value and an incorrect token_type case ("bearer" vs "Bearer"), which will cause new test assertions to fail.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The OAuth token response payload contains two errors. First, the expires_in value is calculated as timezone.now() - token.expires_at, which results in a negative integer. This will cause the new test assertion assert int(fragment_d["expires_in"][0]) > 0 to fail and violates the OAuth2 specification, which requires a positive integer. Second, the implementation returns a lowercase token_type of "bearer", while the updated test asserts the capitalized version "Bearer". Both issues stem from the implementation not being updated to match new test expectations.

💡 Suggested Fix

Update the expires_in calculation to be int((token.expires_at - timezone.now()).total_seconds()) to produce a positive value. Additionally, change the token_type value in the response dictionary from "bearer" to "Bearer" to match the test expectation.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: tests/sentry/web/frontend/test_oauth_authorize.py#L348

Potential issue: The OAuth token response payload contains two errors. First, the
`expires_in` value is calculated as `timezone.now() - token.expires_at`, which results
in a negative integer. This will cause the new test assertion `assert
int(fragment_d["expires_in"][0]) > 0` to fail and violates the OAuth2 specification,
which requires a positive integer. Second, the implementation returns a lowercase
`token_type` of `"bearer"`, while the updated test asserts the capitalized version
`"Bearer"`. Both issues stem from the implementation not being updated to match new test
expectations.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7607579

assert fragment_d["expires_in"]
assert fragment_d["token_type"] == ["bearer"]
assert int(fragment_d["expires_in"][0]) > 0
assert fragment_d["token_type"] == ["Bearer"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test expects capitalized token_type but production returns lowercase

The test now expects fragment_d["token_type"] == ["Bearer"] with a capital "B", but the production code in oauth_authorize.py at line 444 returns "token_type": "bearer" with a lowercase "b". This mismatch will cause the test to fail. The assertions appear on both lines 344 and 349 (duplicated).

Fix in Cursor Fix in Web

# expires_in should be a positive integer number of seconds until expiry
assert fragment_d["expires_in"]
assert fragment_d["token_type"] == ["bearer"]
assert int(fragment_d["expires_in"][0]) > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test expects positive expires_in but calculation yields negative

The new assertion int(fragment_d["expires_in"][0]) > 0 expects a positive value, but the production code in oauth_authorize.py calculates expires_in as timezone.now() - token.expires_at, which produces a negative number since expires_at is in the future. Interestingly, oauth_token.py has the correct calculation (token.expires_at - timezone.now()). This test will fail against the current production code.

Fix in Cursor Fix in Web

@armcknight armcknight merged commit f200d16 into master Dec 17, 2025
68 checks passed
@armcknight armcknight deleted the armcknight/feat/udpate-custom-apple-auth-schema branch December 17, 2025 02:07
@github-actions github-actions bot locked and limited conversation to collaborators Jan 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants