Skip to content

chore(repo): Add machine auth tests for Express and Fastify#8210

Open
wobsoriano wants to merge 4 commits intomainfrom
rob/machine-auth-e2e-backend
Open

chore(repo): Add machine auth tests for Express and Fastify#8210
wobsoriano wants to merge 4 commits intomainfrom
rob/machine-auth-e2e-backend

Conversation

@wobsoriano
Copy link
Copy Markdown
Member

@wobsoriano wobsoriano commented Mar 31, 2026

Description

Continuation of #8124

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Tests
    • Added integration tests for API key, machine-to-machine, and OAuth authentication across Express and Fastify frameworks
    • Tests verify token validation, authorization enforcement, and token type matching behavior

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 31, 2026 0:12am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

⚠️ No Changeset found

Latest commit: 33c8906

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 31, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8210

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8210

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8210

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8210

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8210

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8210

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8210

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8210

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8210

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8210

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8210

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8210

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8210

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8210

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8210

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8210

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8210

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8210

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8210

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8210

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8210

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8210

commit: 33c8906

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

This pull request adds two new Playwright integration test suites: one for Express middleware authentication (integration/tests/express/machine.test.ts) and one for Fastify machine authentication (integration/tests/fastify/machine.test.ts). Both suites validate getAuth behavior with token-type scoping by testing three authentication scenarios: API key authentication, machine-to-machine (M2M) tokens, and OAuth tokens. Each test group spins up a server variant, sends requests with various token types, and asserts status codes and authentication payload structures. Test data is provisioned in beforeAll hooks and cleaned up in afterAll hooks.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding machine auth tests for Express and Fastify frameworks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@integration/tests/express/machine.test.ts`:
- Around line 99-110: The tests iterate over token types but use hard-coded
placeholder strings (e.g., 'mt_test_mismatch', 'oat_test_mismatch'), so they
only exercise invalid-token behavior instead of verifying that acceptsToken
rejects a valid token of the wrong kind; update the table loop in the tests
named `rejects ${tokenType} token on API key route (token type mismatch)` to
supply real, valid tokens of the other types (generate a real M2M token, OAuth
token, and API key token using your existing test helpers such as
createM2MToken/createOAuthToken/createApiKeyToken or the project’s token fixture
functions) and assert 401 for /api/me; apply the same fix to the other two
mismatch tables referenced in the comment (lines ~230-240 and ~339-350) so each
mismatch case uses a valid token of the wrong type rather than a placeholder
string.

In `@integration/tests/fastify/machine.test.ts`:
- Around line 129-140: The tests currently send hard-coded invalid strings
instead of real valid tokens of other kinds; update the token table so each
entry supplies an actual, valid token of the mismatched kind (e.g., for
tokenType 'M2M' and 'OAuth' create real M2M and OAuth tokens) using your
existing test fixtures/factories (e.g., the helper that issues API key/M2M/OAuth
tokens) and keep the test body that calls GET '/api/me' with Authorization:
`Bearer ${token}`; ensure you generate/obtain these tokens via the project
helpers (the token factory used elsewhere in tests) so the assertions exercise
token-type rejection (the test title, tokenType variable, Authorization header
and the GET '/api/me' request remain unchanged).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0f968315-4d6e-45e6-8649-95ac6ca0e755

📥 Commits

Reviewing files that changed from the base of the PR and between 596fcd1 and 2aea6c6.

📒 Files selected for processing (2)
  • integration/tests/express/machine.test.ts
  • integration/tests/fastify/machine.test.ts

Comment on lines +99 to +110
for (const [tokenType, token] of [
['M2M', 'mt_test_mismatch'],
['OAuth', 'oat_test_mismatch'],
] as const) {
test(`rejects ${tokenType} token on API key route (token type mismatch)`, async ({ request }) => {
const url = new URL('/api/me', app.serverUrl);
const res = await request.get(url.toString(), {
headers: { Authorization: `Bearer ${token}` },
});
expect(res.status()).toBe(401);
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use real cross-type tokens in these mismatch assertions.

These cases only send hard-coded placeholder strings, so they re-test the existing invalid-token path instead of proving that acceptsToken rejects a valid token of the wrong kind. If type enforcement regressed but verification still rejected unknown strings, this suite would stay green. Please use real API key, M2M, and OAuth tokens across these tables.

Also applies to: 230-240, 339-350

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integration/tests/express/machine.test.ts` around lines 99 - 110, The tests
iterate over token types but use hard-coded placeholder strings (e.g.,
'mt_test_mismatch', 'oat_test_mismatch'), so they only exercise invalid-token
behavior instead of verifying that acceptsToken rejects a valid token of the
wrong kind; update the table loop in the tests named `rejects ${tokenType} token
on API key route (token type mismatch)` to supply real, valid tokens of the
other types (generate a real M2M token, OAuth token, and API key token using
your existing test helpers such as
createM2MToken/createOAuthToken/createApiKeyToken or the project’s token fixture
functions) and assert 401 for /api/me; apply the same fix to the other two
mismatch tables referenced in the comment (lines ~230-240 and ~339-350) so each
mismatch case uses a valid token of the wrong type rather than a placeholder
string.

Comment on lines +129 to +140
for (const [tokenType, token] of [
['M2M', 'mt_test_mismatch'],
['OAuth', 'oat_test_mismatch'],
] as const) {
test(`rejects ${tokenType} token on API key route (token type mismatch)`, async ({ request }) => {
const url = new URL('/api/me', app.serverUrl);
const res = await request.get(url.toString(), {
headers: { Authorization: `Bearer ${token}` },
});
expect(res.status()).toBe(401);
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use real cross-type tokens in these mismatch assertions.

These cases only send hard-coded placeholder strings, so they re-test the existing invalid-token path instead of proving that acceptsToken rejects a valid token of the wrong kind. If type enforcement regressed but verification still rejected unknown strings, this suite would stay green. Please use real API key, M2M, and OAuth tokens across these tables.

Also applies to: 290-300, 429-440

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integration/tests/fastify/machine.test.ts` around lines 129 - 140, The tests
currently send hard-coded invalid strings instead of real valid tokens of other
kinds; update the token table so each entry supplies an actual, valid token of
the mismatched kind (e.g., for tokenType 'M2M' and 'OAuth' create real M2M and
OAuth tokens) using your existing test fixtures/factories (e.g., the helper that
issues API key/M2M/OAuth tokens) and keep the test body that calls GET '/api/me'
with Authorization: `Bearer ${token}`; ensure you generate/obtain these tokens
via the project helpers (the token factory used elsewhere in tests) so the
assertions exercise token-type rejection (the test title, tokenType variable,
Authorization header and the GET '/api/me' request remain unchanged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant