Engineering Authentication Test Generation

Authentication Test Prompt

Login, token refresh, and everything that must fail: expired tokens, wrong permissions, malicious credentials — auth tested as behavior.

Overview

Auth code is tested backwards everywhere: the login-works test exists, the seventeen ways auth must FAIL don't. This setup generates the auth test suite with security as a first-class coverage area: authentication failures (missing, expired, malformed credentials — each its own test), permission boundaries returning the right 403s, malicious input through every credential field, and access to other users' resources by ID rejected — alongside the API failure scenarios: 401 vs 403 distinguished, idempotent refresh behavior, and error shapes that don't leak what exists.

How to use this resource

  1. Count the failure tests

    A healthy auth suite has more failure tests than success tests — the contract is built to produce that ratio.

  2. Test expiry as a moment

    The token that expires BETWEEN two requests is the scenario that separates tested auth from lucky auth.

  3. Verify the cross-user wall

    Authenticated-but-wrong-user requests against every resource type — the test that catches IDOR before users do.

Why This Works

  • Failure-first framing matches auth reality: success is one path, failure is the surface
  • The 401/403 separation tests the distinction attackers probe first
  • Cross-user scenarios catch the authorization bugs authentication tests can't see

Best for

  • Auth endpoints, middleware, and guards
  • Systems where a 403 returned as 404 (or worse, 200) is an incident
  • Token lifecycles with refresh, expiry, and revocation

Not for

  • Reviewing auth code for vulnerabilities — that's the Code Review Prompt Generator's security focus; review finds, tests verify
  • Pen-testing — these tests verify specified behavior, not undiscovered attack surface

Use cases

  • Testing login and token-refresh endpoints before release
  • Covering expired-token behavior on every protected route
  • Verifying users can't reach each other's resources by ID

FAQ

How do I generate tests for everything that should fail in auth

The Security and Failure Scenarios areas make failures first-class: missing, expired, and malformed credentials each get their own test, permission boundaries return 403 for the wrong roles, and access to other users' resources by ID is rejected. Test Case Prompt Generator produces the prompt; you run it in your own assistant, and it generates tests only, never modifying the implementation.

Does this prompt test the difference between 401 and 403

Yes, as separate tests. The TEST STRATEGY treats auth as behavior: 401 for missing or expired credentials, 403 for valid-but-forbidden, and they are different tests. The Failure Scenarios also require nonexistent resources to return 404, not 500 or an empty 200, and every response asserts status code, body shape, and the headers that matter.

Is this a substitute for a security review or pen test of my auth code

No. The notFor is explicit: reviewing auth code for vulnerabilities is the Code Review Prompt Generator's job, and pen-testing probes undiscovered attack surface. These tests verify specified behavior, so they close the ASSUMPTIONS and GAPS the prompt lists but don't guarantee your auth is secure; review finds, tests verify, and both stay under human review.

More resources from Test Case Prompt Generator

Resources that pair well

Related tools

Workflows that use this resource

Guides for this resource

Tip: Save time by exploring related resources and tools that integrate with this resource.