Copilot commented on code in PR #1441:
URL: https://github.com/apache/pulsar-client-go/pull/1441#discussion_r2564388730


##########
oauth2/auth_suite_test.go:
##########
@@ -58,6 +58,20 @@ func (te *MockTokenExchanger) ExchangeDeviceCode(_ 
context.Context,
        return te.ReturnsTokens, te.ReturnsError
 }
 
+type MockGrantProvider struct {
+       keyFile *KeyFile
+}
+
+func (mgp *MockGrantProvider) GetGrant(audience string, _ 
*ClientCredentialsFlowOptions) (*AuthorizationGrant, error) {
+       return &AuthorizationGrant{
+               Type:              GrantTypeClientCredentials,
+               Audience:          audience,
+               ClientCredentials: mgp.keyFile,
+               TokenEndpoint:     oidcEndpoints.TokenEndpoint,
+               Scopes:            []string{mgp.keyFile.Scope},
+       }, nil

Review Comment:
   The ClientID field in AuthorizationGrant is not being set in 
MockGrantProvider.GetGrant(), but it should be set to mgp.keyFile.ClientID to 
match the behavior of DefaultGrantProvider and maintain consistency.



##########
oauth2/auth_suite_test.go:
##########
@@ -58,6 +58,20 @@ func (te *MockTokenExchanger) ExchangeDeviceCode(_ 
context.Context,
        return te.ReturnsTokens, te.ReturnsError
 }
 
+type MockGrantProvider struct {
+       keyFile *KeyFile
+}
+
+func (mgp *MockGrantProvider) GetGrant(audience string, _ 
*ClientCredentialsFlowOptions) (*AuthorizationGrant, error) {
+       return &AuthorizationGrant{
+               Type:              GrantTypeClientCredentials,
+               Audience:          audience,
+               ClientCredentials: mgp.keyFile,
+               TokenEndpoint:     oidcEndpoints.TokenEndpoint,
+               Scopes:            []string{mgp.keyFile.Scope},

Review Comment:
   The MockGrantProvider ignores the 
ClientCredentialsFlowOptions.AdditionalScopes parameter, which could lead to 
incorrect test behavior. The real DefaultGrantProvider merges AdditionalScopes 
with scopes from the key file. This mock should do the same to properly test 
scope handling.
   ```suggestion
   func (mgp *MockGrantProvider) GetGrant(audience string, opts 
*ClientCredentialsFlowOptions) (*AuthorizationGrant, error) {
        scopes := []string{mgp.keyFile.Scope}
        if opts != nil && len(opts.AdditionalScopes) > 0 {
                scopes = append(scopes, opts.AdditionalScopes...)
        }
        return &AuthorizationGrant{
                Type:              GrantTypeClientCredentials,
                Audience:          audience,
                ClientCredentials: mgp.keyFile,
                TokenEndpoint:     oidcEndpoints.TokenEndpoint,
                Scopes:            scopes,
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to