Repository navigation
fix(oauth): fail GitHub sign-in when the user payload is missing - #14093
Conversation
A null GitHub user body was assigned to a typed array and 500'd the OAuth redirect. Treat that payload as an OAuth provider failure. Fixes CLOUD-3QWQ Co-authored-by: Chirag Aggarwal <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
🔵 Tier A · Mergeable after minor fixes
The change rejects missing or non-array GitHub user responses with an OAuth2 exception while retaining the typed array cache. It also moves user-ID retrieval into the redirect handler's provider-failure catch and adds a unit regression for a JSON
Fix with agent prompt### Issue 1
tests/unit/Auth/OAuth2/GithubTest.php:116-124
**Decouple the missing-user test from internal request formatting**
The exact `request()` arguments and call count make this regression fail if authentication headers or fetching strategy change, even when a missing user still produces the correct exception. AGENTS.md requires named fakes and observable-behavior assertions rather than internal request details; use a fake that supplies the missing-user response and keep the exception assertions.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 3
Reviewed |
| $github | ||
| ->expects($this->once()) | ||
| ->method('request') | ||
| ->with( | ||
| 'GET', | ||
| 'https://api.github.com/user', | ||
| ['Authorization: token ' . \urlencode('access-token')], | ||
| ) | ||
| ->willReturn('null'); |
There was a problem hiding this comment.
Decouple the missing-user test from internal request formatting
The exact request() arguments and call count make this regression fail if authentication headers or fetching strategy change, even when a missing user still produces the correct exception. AGENTS.md requires named fakes and observable-behavior assertions rather than internal request details; use a fake that supplies the missing-user response and keep the exception assertions.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Auth/OAuth2/GithubTest.php
Line: 116-124
Comment:
**Decouple the missing-user test from internal request formatting**
The exact `request()` arguments and call count make this regression fail if authentication headers or fetching strategy change, even when a missing user still produces the correct exception. AGENTS.md requires named fakes and observable-behavior assertions rather than internal request details; use a fake that supplies the missing-user response and keep the exception assertions.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
cloud#5410 re-pins server-ce to this branch and needs main at or past ee75768: the health tests that stop asserting wall-clock ping budgets (#14069), Content-Length: 0 on empty client bodies for OAuth token requests (#14072) and the SDK task no longer calling setters removed in sdk-generator 5.3.4 (#14073). Also brings the GitHub OAuth missing-user fix (#14093) and appwrite/geo 0.3.2 (#14100). The merge is clean and the lock is untouched; both sides still resolve appwrite/sdk-generator 5.0.1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
GitHub OAuth redirect (
/v1/account/sessions/oauth2/:provider/redirect) returned a 500 on cloud release 1.50.126 when GitHub's user payload was missing.json_decodeyieldednull, and assigning that toAppwrite\Auth\OAuth2\Github::$user(array) threw aTypeError.A missing or non-array user body is now an OAuth provider failure, the same way other adapters reject a user document the provider did not return (
throw new Exception(..., 400)). The redirect handler loads the user id inside the existingOAuth2Exceptioncatch, so that failure uses the existingfailureRedirect(USER_OAUTH2_PROVIDER_FAILURE)path instead of a 500.The
$userproperty stays a typed array.Fixes CLOUD-3QWQ
Test Plan
vendor/bin/phpunit tests/unit/Auth/OAuth2/GithubTest.php(12 tests, includingtestMissingUserfor a JSONnulluser body)vendor/bin/pint --teston the changed PHP filesRelated PRs and Issues
Checklist