Skip to content

refactor(mqrest): ♻️ add auth strategy seam - #140

Merged
konih merged 1 commit into
mainfrom
lane/auth-11-strategy-seam
Jul 22, 2026
Merged

konih merged 1 commit into
mainfrom
lane/auth-11-strategy-seam

Conversation

@konih

@konih konih commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • introduce an authentication strategy seam in the mqrest adapter
  • preserve existing basic-auth behavior behind the new strategy boundary
  • cover strategy application and error handling with focused tests

Verification

  • task verify
  • task lint
  • task test:run
  • task scrub

Copilot AI review requested due to automatic review settings July 22, 2026 22:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 requestAuthenticator interface plus a basicRequestAuthenticator implementation.
  • Update the mqrest Client to 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

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/adapter/mqrest/client.go 71.42% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@konih
konih merged commit dc6063c into main Jul 22, 2026
25 checks passed
@konih
konih deleted the lane/auth-11-strategy-seam branch July 22, 2026 22:35
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.

2 participants