Skip to content

Conversation

@freeznet
Copy link
Member

(If this PR fixes a github issue, please add Fixes #<xyz>.)

Fixes #

(or if this PR is one task of a github issue, please add Master Issue: #<xyz> to link to the master issue.)

Master Issue: #

Motivation

Explain here the context, and why you're making that change. What is the problem you're trying to solve.

Modifications

Describe the modifications you've done.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Documentation

Check the box below.

Need to update docs?

  • doc-required

    (If you need help on updating docs, create a doc issue)

  • no-need-doc

    (Please explain why)

  • doc

    (If this PR contains doc changes)

@freeznet freeznet self-assigned this Jan 30, 2026
@freeznet freeznet requested review from a team as code owners January 30, 2026 07:59
@github-actions
Copy link
Contributor

@freeznet:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@github-actions github-actions bot added the doc-info-missing This pr needs to mark a document option in description label Jan 30, 2026
@freeznet freeznet requested a review from Copilot January 30, 2026 08:17
Copy link
Contributor

Copilot AI left a comment

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 adds support for the IssuerURL field in the OAuth2 ClientCredentialsFlow configuration for Pulsar Admin clients. The change ensures that the issuer endpoint is properly passed to both the Issuer struct and the ClientCredentialsFlowOptions struct when creating OAuth2 authentication providers.

Changes:

  • Added IssuerURL field to ClientCredentialsFlowOptions initialization, setting it to the same value as IssuerEndpoint
  • Introduced a package-level variable newAuthenticationOAuth2WithFlow for better testability
  • Added comprehensive unit tests to verify the OAuth2 configuration is correctly passed through

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/admin/interface.go Added package variable for testability and set IssuerURL field in OAuth2 flow options
pkg/admin/interface_test.go Added new test file with unit tests verifying OAuth2 IssuerURL configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}, oauth2.ClientCredentialsFlowOptions{
IssuerURL: conf.IssuerEndpoint,
KeyFile: keyFilePath,
AdditionalScopes: strings.Split(conf.Scope, " "),
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

When conf.Scope is an empty string, strings.Split will return a slice containing one empty string instead of an empty slice. This may not be the intended behavior. Consider handling the empty scope case explicitly, for example by checking if conf.Scope is empty and passing nil or an empty slice instead.

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +93
func TestNewPulsarAdminOAuth2IssuerURL(t *testing.T) {
original := newAuthenticationOAuth2WithFlow
t.Cleanup(func() {
newAuthenticationOAuth2WithFlow = original
})

var gotIssuer oauth2.Issuer
var gotFlow oauth2.ClientCredentialsFlowOptions
called := false

newAuthenticationOAuth2WithFlow = func(issuer oauth2.Issuer, flowOptions oauth2.ClientCredentialsFlowOptions) (auth.Provider, error) {
called = true
gotIssuer = issuer
gotFlow = flowOptions
return &fakeAuthProvider{}, nil
}

conf := PulsarAdminConfig{
IssuerEndpoint: "https://issuer.example.com",
ClientID: "client-id",
Audience: "audience",
Scope: "scope-a scope-b",
KeyFilePath: "test-key-file.json",
}

_, err := NewPulsarAdmin(conf)
if err != nil {
t.Fatalf("NewPulsarAdmin() error = %v", err)
}

if !called {
t.Fatalf("expected NewAuthenticationOAuth2WithFlow to be called")
}

if gotIssuer.IssuerEndpoint != conf.IssuerEndpoint {
t.Fatalf("issuer endpoint = %q, want %q", gotIssuer.IssuerEndpoint, conf.IssuerEndpoint)
}

if gotFlow.IssuerURL != conf.IssuerEndpoint {
t.Fatalf("flow issuer url = %q, want %q", gotFlow.IssuerURL, conf.IssuerEndpoint)
}

if gotFlow.KeyFile == "" {
t.Fatalf("expected flow key file to be set")
}

expectedScopes := []string{"scope-a", "scope-b"}
if !reflect.DeepEqual(gotFlow.AdditionalScopes, expectedScopes) {
t.Fatalf("additional scopes = %v, want %v", gotFlow.AdditionalScopes, expectedScopes)
}
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The test only covers the happy path with a non-empty scope. Consider adding test cases for edge cases such as: empty scope string, scope with multiple spaces, and scope with leading/trailing spaces. These edge cases could expose issues with the strings.Split implementation in the production code.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-info-missing This pr needs to mark a document option in description

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants