Skip to content

test(auth): failing integration test for OAuth-profile X-User-Id 403 - #136

Open
Ramon Nogueira (ramon-langchain) wants to merge 2 commits into
mainfrom
ramonn/fix-profile-xuserid
Open

test(auth): failing integration test for OAuth-profile X-User-Id 403#136
Ramon Nogueira (ramon-langchain) wants to merge 2 commits into
mainfrom
ramonn/fix-profile-xuserid

Conversation

@ramon-langchain

@ramon-langchain Ramon Nogueira (ramon-langchain) commented Jun 29, 2026

Copy link
Copy Markdown
Member

Problem

OAuth-profile requests (langsmith auth login) are rejected with 403 by the backend. WithProfile auth sends an X-User-Id header derived from the access-token JWT sub (added in #98). The backend's auth middleware returns 403 when X-User-Id doesn't equal the user it resolves from the same token — and the AS sub does not match the resolved ls_user_id, so the call fails.

Reproduced live with a fresh OAuth login on both dev and prod (it is not environment-specific):

GET https://api.smith.langchain.com/v2/sandboxes/boxes:     403 Forbidden
GET https://dev.api.smith.langchain.com/v2/sandboxes/boxes: 403 Forbidden
  x_user_id (token sub)   != auth_user_id (resolved ls_user_id)

Why nothing caught it

  • The existing integration tests authenticate with WithAPIKey — the API-key path strips Authorization/X-User-Id, so it never exercises this.
  • The unit tests use an httptest mock that records the header but does no identity resolution, so they pass regardless.

This PR adds the missing coverage: an integration test that uses WithProfile (the OAuth-bearer path) and hits GET /v2/sandboxes/boxes, which runs under the auth middleware that enforces the X-User-Id check. It fails (403) against a real backend today, and skips unless an OAuth-logged-in profile is present (so API-key-only CI is unaffected). Defaults to the default (production) profile; override with LANGSMITH_OAUTH_PROFILE.

This PR intentionally contains only the failing test — no fix — to capture the regression.

Test Plan

  • go test -tags integration -run TestOAuthProfile_AuthenticatedRequest ./integration/ fails with 403 against prod and dev using an OAuth profile
  • Skips cleanly when no OAuth profile is configured

Reproduces a regression where OAuth-profile (langsmith auth login) requests
are rejected with 403 by the backend. WithProfile auth sends an X-User-Id
header derived from the access-token JWT sub; the backend rejects the request
when that id does not match the user it resolves from the same token. Only the
OAuth-bearer path is affected — API-key auth (covered by the existing profile
tests) strips the header — and the unit tests use an httptest mock that does no
identity resolution, so neither catches it.

The test uses WithProfile and hits GET /v2/sandboxes/boxes, which runs under
the auth middleware that enforces the X-User-Id check. It fails (403) against a
real backend today and skips unless an OAuth-logged-in profile is present.
Use the 'default' (production) profile by default and confirm the 403
reproduces against prod, not just dev — the X-User-Id mismatch is systematic,
not dev-only. Add a consistent loginHint to every credential-related skip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant