OAuth tests often prove that the happy path works while leaving the most important trust decision untested: where is the authorization response allowed to go? The test are green, but the boundary is still unclear.
A login can appear successful even when the test suite never checks exact redirect-URI matching, state validation, PKCE handling, or the boundary between a test identity and a real account. That creates a dangerous kind of confidence. The test is green, but it may not catch an allowlist regression or a leaked code.
The fix is a redirect-URI matrix. Treat each OAuth test as a small security experiment with an explicit client, identity, callback, and expected result. The matrix also make review easier when a client configuration changes.
Why redirect URI tests fail to prove much
Many suites have one test client, one callback URL, and one reusable email fixture. That setup is easy to maintain, but it hides important cases:
- The exact registered URI is accepted.
- A URI with a different path is rejected.
- A URI with a confusingly similar host is rejected.
- An untrusted preview environment cannot receive a production code.
- A callback cannot silently remove or alter the
statevalue.
The common mistake is testing only the identity provider's success response. OAuth security depends on the complete flow, including what the application does with a response that is almost valid.
An idempotent signup email handling pattern is useful here: every test run should own its inputs and be safe to replay. The same principle applies to authorization codes and callback attempts.
Model the trust boundary
Before adding cases, write down the assets and boundaries. The assets might include an authorization code, an access token, a refresh token, and the test user's account. The boundaries include the browser, the application callback, the identity provider, and any temporary inbox used to confirm a signup.
The threat model does not need to be long. Ask four questions:
- Can an attacker redirect a code to a host they control?
- Can a test accidentally use a real account or real mailbox?
- Can a retry associate a response with the wrong test run?
- Will a failure leave enough evidence to tell configuration error from application bug?
Do not use a fake email generator as a substitute for identity isolation. A disposable address can help keep test data separate, but it does not make a client ID, redirect URI, or token safe. Keep credentials and test identities scoped to the environment that owns them.
Build a redirect-URI matrix
Represent the expected behavior as data. For example:
[ {"name": "registered callback", "uri": "https://app.test/oauth/callback", "expect": "allow"}, {"name": "wrong path", "uri": "https://app.test/oauth/other", "expect": "deny"}, {"name": "lookalike host", "uri": "https://app.test.attacker.example/callback", "expect": "deny"}, {"name": "preview callback", "uri": "https://preview.test/oauth/callback", "expect": "environment-policy"} ] The test should assert the provider response and the application's behavior. A denial should not become a generic success page. The application should record a safe error, preserve correlation data, and avoid placing an authorization code in a URL that can be copied into logs or analytics. A denied callback should not became a confusing success screen.
Include both exact-match and policy cases. Wildcard callback rules deserve special attention because a broad pattern can make an otherwise careful client behave like an open redirect. If a wildcard is required for preview environments, constrain it to an owned suffix and test an adjacent unowned suffix too.
Use PKCE and state in every browser-like test, including negative cases. The negative test is where a missing verifier or mismatched state should be visible. Its not enough to assert that the provider returned an error; assert that the application did not create a session.
Keep identities and email fixtures isolated
Give each run a unique identity label and fixture owner. A run identifier can appear in the test subject, database record, and structured log, while the actual email content stays out of ordinary logs. Never print authorization codes, cookies, or tokens while debugging.
If a test includes malformed input such as tamp mail com or temp gamil com, treat it as an input-validation case. Do not turn those strings into links or let them become credentials. A little messy test data is useful, but the test description should still be clear.
Cleanup needs the same ownership rule. Expire test users, revoke issued sessions, and remove callback fixtures by run ID. When the workflow is automated, use a frozen plan for automated runs so a retry does not quietly change the cases it is supposed to prove. Do not let a retry changes the identity owner halfway through a run.
Capture evidence from negative tests
For every matrix row, save the case name, environment, client identifier, sanitized redirect URI, result category, and correlation ID. Redact query values before storing a URL. A useful failure record says “wrong path was accepted by client X in preview” rather than only “OAuth test failed.”
Keep provider configuration snapshots versioned, but exclude client secrets. If a test fails after a configuration change, the team should be able to compare the registered callback set and the application allowlist without recovering sensitive credentials.
A practical checklist
- [ ] Exact registered callback is tested.
- [ ] Wrong path, scheme, host, and port cases are tested.
- [ ] Preview and production callbacks are separated.
- [ ]
stateand PKCE are asserted on success and failure paths. - [ ] Each identity, email fixture, and session has a run owner.
- [ ] Tokens, codes, cookies, and message bodies are redacted from logs.
- [ ] A rejected redirect cannot create an authenticated session.
- [ ] The matrix and its expected results are frozen for retries.
The goal is not to create a huge OAuth test suite. It is to make the trust boundary visible and repeatable. A small matrix with strong evidence can catch more serious mistakes than many happy-path browser tests, and it gives the security team a much clearer answer when a callback configuration changes. These checks is modest, but they produce evidence people can act on.
