test(gateway): add unit tests for AuthHandlers#233
Open
eclipse0922 wants to merge 4 commits intoselfpatch:mainfrom
Open
test(gateway): add unit tests for AuthHandlers#233eclipse0922 wants to merge 4 commits intoselfpatch:mainfrom
eclipse0922 wants to merge 4 commits intoselfpatch:mainfrom
Conversation
Adds 15 unit tests covering the three AuthHandlers methods: - handle_auth_authorize, handle_auth_token, handle_auth_revoke all return 404 when authentication is disabled (default state) - handle_auth_authorize input validation: wrong grant_type, missing/empty client_id, missing client_secret each return 400 - handle_auth_token input validation: wrong grant_type, missing/empty refresh_token each return 400 - handle_auth_revoke input validation: invalid JSON, missing token field, non-string token each return 400 - Error responses for auth endpoints follow OAuth2 RFC 6749 format (error/error_description) while the auth-disabled 404 uses SOVD format Tests use a null GatewayNode and null AuthManager. Auth-enabled tests exercise only input-validation paths that return before auth_manager is accessed, so null auth_manager is safe. Closes selfpatch#178 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Align success-path assertions with current handler response behavior and add a missing validation test for empty client_secret.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a dedicated GTest unit suite for the REST AuthHandlers so the gateway’s OAuth2-style auth endpoints have explicit input-validation and error-format coverage (closing #178).
Changes:
- Introduces
test_auth_handlers.cppwith ~15 tests covering auth-disabled behavior, request validation, and basic happy-path flows using a realAuthManager. - Ensures OAuth2 RFC 6749-style error payload shape (
error/error_description) is exercised for validation failures. - Wires the new test target into
CMakeLists.txt(including coverage flags when enabled).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/ros2_medkit_gateway/test/test_auth_handlers.cpp |
New unit tests for /auth/authorize, /auth/token, /auth/revoke handler behavior and response formats. |
src/ros2_medkit_gateway/CMakeLists.txt |
Adds test_auth_handlers target and includes it in coverage instrumentation list. |
mfaferek93
reviewed
Feb 24, 2026
| }; | ||
|
|
||
| // @verifies REQ_INTEROP_086 | ||
| TEST_F(AuthHandlersRevokeTest, ReturnsBadRequestForInvalidJson) { |
Collaborator
There was a problem hiding this comment.
revoke tests tagged @verifies REQ_INTEROP_086, but docs/requirements/specs/auth.rst only defines 086 for /authorize and 087 for /token. No REQ for /revoke exists. We can add a new one in auth.rst (next free ID is 095) and update lines 268, 283, 297, 400 in the test file.
That way docs/requirements/coverage.rst picks it up automatically.
mfaferek93
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AuthHandlers(handle_auth_authorize,handle_auth_token,handle_auth_revoke)AuthConfig)handle_auth_authorizevalidation: wronggrant_type→ 400unsupported_grant_type; missing/emptyclient_idorclient_secret→ 400invalid_requesthandle_auth_tokenvalidation: wronggrant_type→ 400unsupported_grant_type; missing/emptyrefresh_token→ 400invalid_requesthandle_auth_revokevalidation: invalid JSON → 400; missing/non-stringtokenfield → 400error/error_descriptionfields)GatewayNodeand nullAuthManager; auth-enabled tests only exercise input-validation paths that return beforeauth_manageris accessedTest plan
colcon test --ctest-args -R test_auth_handlersros2_medkit_dev:latestCloses #178
🤖 Generated with Claude Code