Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
norshtein committed Feb 12, 2020
1 parent 2694bbb commit ee4ddcb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions provider/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package provider

import (
"context"
"strings"
"testing"

"github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns"
Expand Down Expand Up @@ -455,4 +456,32 @@ func TestAzureGetAccessToken(t *testing.T) {
if err == nil {
t.Fatalf("expected to fail, but got no error")
}

// Expect to use managed identity in this case
cfg = config{
ClientID: "msi",
ClientSecret: "msi",
TenantID: "cefe8aef-5127-4d65-a299-012053f81f60",
UserAssignedIdentityID: "userAssignedIdentityClientID",
UseManagedIdentityExtension: true,
}
_, err = getAccessToken(cfg, env)
if err == nil ||
!strings.Contains(err.Error(), "failed to create the managed service identity token") {
t.Fatalf("expected to fail to get the token using user assigned identity, but got %v", err)
}

// Expect to use SPN in this case
cfg = config{
ClientID: "SPNClientID",
ClientSecret: "SPNSecret",
TenantID: "cefe8aef-5127-4d65-a299-012053f81f60",
UserAssignedIdentityID: "userAssignedIdentityClientID",
UseManagedIdentityExtension: true,
}
_, err = getAccessToken(cfg, env)
if err == nil ||
!strings.Contains(err.Error(), "failed to create service principal token") {
t.Fatalf("expected to fail to get the token using service principal, but got %v", err)
}
}

0 comments on commit ee4ddcb

Please sign in to comment.