Fix: Enforce bot-type check on generateToken endpoint#27078
Fix: Enforce bot-type check on generateToken endpoint#27078mohityadav766 merged 2 commits into1.12.5from
Conversation
The generateToken endpoint was intended for bot users only but the guard was accidentally removed in #8617 (Nov 2022). This restores the original check, rejecting non-bot users with a 400 error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsAdds bot-type validation to the generateToken endpoint to prevent unauthorized token generation. The implementation is sound, but the test expects BAD_REQUEST while passing OK status to TestUtils—consider aligning the expected status code with the actual validation behavior. 💡 Quality: Test passes OK to put() but expects BAD_REQUEST from responseThe test passes Suggested fix🤖 Prompt for agentsOptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
| TestUtils.put( | ||
| getResource(String.format("users/generateToken/%s", user.getId())), | ||
| new GenerateTokenRequest().withJWTTokenExpiry(JWTTokenExpiry.Seven), | ||
| OK, |
There was a problem hiding this comment.
💡 Quality: Test passes OK to put() but expects BAD_REQUEST from response
The test passes OK (200) as the expected status to TestUtils.put(), but the endpoint actually returns 400. This works by accident: put() sees a non-success status, throws HttpResponseException, and assertResponseContains() catches it and checks for BAD_REQUEST. However, the OK parameter is misleading and doesn't match the actual expectation. Other error-path tests in this codebase typically pass the correct expected error status to avoid confusion.
Suggested fix:
Replace `OK` with `BAD_REQUEST`:
TestUtils.put(
getResource(String.format("users/generateToken/%s", user.getId())),
new GenerateTokenRequest().withJWTTokenExpiry(JWTTokenExpiry.Seven),
BAD_REQUEST,
ADMIN_AUTH_HEADERS),
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
Summary
PUT /v1/users/generateToken/{id}that was accidentally removed in Fix#8577: Refactor part of the secrets manager implementation #8617 (Nov 2022)400 Bad Requestinstead of a valid JWT tokenContext
mainvia Add POST /api/v1/users/generateToken endpoint for simplified token generation #25052, but that PR includes a new endpoint, schema changes, and UI refactoring — not suitable for cherry-pickTest plan
put_generateToken_bot_user_200_ok— existing test, still passesput_generateToken_non_bot_user_400— new test, verifies non-bot users are rejected🤖 Generated with Claude Code