Repository navigation
refactor(mqrest): ♻️ add auth strategy seam - #140
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an authentication strategy seam inside the internal/adapter/mqrest adapter so request authentication can be varied without hard-coding Basic Auth logic throughout the client, while preserving the existing Basic Auth behavior by default.
Changes:
- Add a
requestAuthenticatorinterface plus abasicRequestAuthenticatorimplementation. - Update the mqrest
Clientto authenticate requests via the strategy seam (with a nil-strategy fallback to legacy Basic Auth behavior). - Add tests to assert the authenticator is invoked for both Ping and MQSC requests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/adapter/mqrest/factory.go | Wires the default Basic authenticator into the mqrest config produced by the factory. |
| internal/adapter/mqrest/client.go | Replaces per-request SetBasicAuth usage with the new authenticator seam and adds contextual error wrapping. |
| internal/adapter/mqrest/auth_strategy.go | Introduces the authenticator interface and the Basic Auth implementation. |
| internal/adapter/mqrest/auth_strategy_test.go | Adds tests verifying the authenticator is applied per request (and should cover error paths as well). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+67
to
+80
| func TestBasicRequestAuthenticatorPreservesHeaders(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| req := httptest.NewRequest(http.MethodPost, "https://mq.example/mqsc", nil) | ||
| auth := basicRequestAuthenticator{username: "[email protected]", password: "p:a:ss"} | ||
| if err := auth.authenticate(context.Background(), req); err != nil { | ||
| t.Fatalf("authenticate: %v", err) | ||
| } | ||
|
|
||
| username, password, ok := req.BasicAuth() | ||
| if !ok || username != "[email protected]" || password != "p:a:ss" { | ||
| t.Fatalf("BasicAuth = (%q, %q, %t)", username, password, ok) | ||
| } | ||
| } |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Verification