Skip to content

Commit

Permalink
Fix allowed tenants for InteractiveBrowserCredential (#22257)
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell authored Jan 17, 2024
1 parent f17d3c3 commit 18bb6a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sdk/azidentity/azidentity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,26 @@ func TestAdditionallyAllowedTenants(t *testing.T) {
}
})
}

t.Run(credNameBrowser, func(t *testing.T) {
c, err := NewInteractiveBrowserCredential(&InteractiveBrowserCredentialOptions{
AdditionallyAllowedTenants: test.allowed,
// this enables testing the credential's tenant resolution without having to authenticate
DisableAutomaticAuthentication: true,
})
require.NoError(t, err)
_, err = c.GetToken(context.Background(), tro)
if test.err {
// the specified tenant isn't allowed, so the error should be about that
require.ErrorContains(t, err, "AdditionallyAllowedTenants")
} else {
// tenant resolution should have succeeded because the specified tenant is allowed,
// however the credential should have returned a different error because automatic
// authentication is disabled
require.ErrorIs(t, ErrAuthenticationRequired, err)
}
})

for _, credName := range []string{credNameAzureCLI, credNameAzureDeveloperCLI} {
t.Run(fmt.Sprintf("DefaultAzureCredential/%s/%s", credName, test.desc), func(t *testing.T) {
typeName := fmt.Sprintf("%T", &AzureCLICredential{})
Expand Down
1 change: 1 addition & 0 deletions sdk/azidentity/interactive_browser_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func NewInteractiveBrowserCredential(options *InteractiveBrowserCredentialOption
}
cp.init()
msalOpts := publicClientOptions{
AdditionallyAllowedTenants: cp.AdditionallyAllowedTenants,
ClientOptions: cp.ClientOptions,
DisableAutomaticAuthentication: cp.DisableAutomaticAuthentication,
DisableInstanceDiscovery: cp.DisableInstanceDiscovery,
Expand Down

0 comments on commit 18bb6a3

Please sign in to comment.