-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for ensureAccessTokenClaims (#3337)
- Loading branch information
Showing
67 changed files
with
1,987 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package validate | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
// | ||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" | ||
|
||
utilerror "github.com/Azure/ARO-RP/test/util/error" | ||
) | ||
|
||
type token struct { | ||
accesstoken string | ||
} | ||
|
||
func (t token) GetToken(context.Context, policy.TokenRequestOptions) (azcore.AccessToken, error) { | ||
return azcore.AccessToken{Token: t.accesstoken, ExpiresOn: time.Now().Add(24 * time.Hour)}, nil | ||
} | ||
|
||
func TestEnsureAccessTokenClaims(t *testing.T) { | ||
// generated, not real tokens | ||
hasOid := "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJia0Biay5jb20iLCJuYW1lIjoiQmlsbHkgS2VpbGxvciIsICJvaWQiOiAiMTExMTEiLCAiaWF0IjoxNTQ2MzAwODAwLCJleHAiOjE4OTM0NTYwMDB9." | ||
hasAltsecid := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwgImFsdHNlY2lkIjoiYmlsbHkga2VpbGxvciIsICJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9." | ||
hasPuid := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwgInB1aWQiOiJiaWxseSBrZWlsbG9yIiwgIm5hbWUiOiJKb2huIERvZSIsImlhdCI6MTUxNjIzOTAyMn0." | ||
for _, tt := range []struct { | ||
name string | ||
tokenFactory func() azcore.TokenCredential | ||
wantErr string | ||
}{ | ||
{ | ||
name: "server error", | ||
tokenFactory: func() azcore.TokenCredential { | ||
cred := fake.TokenCredential{} | ||
cred.SetError(errors.New("Unable to establish a connection to ARM")) | ||
return &cred | ||
}, | ||
wantErr: "Unable to establish a connection to ARM", | ||
}, | ||
{ | ||
name: "invalid Token, no required claims at all", | ||
tokenFactory: func() azcore.TokenCredential { | ||
return &fake.TokenCredential{} | ||
}, | ||
wantErr: "400: InvalidServicePrincipalToken: properties.servicePrincipalProfile: The provided service principal generated an invalid token.", | ||
}, | ||
{ | ||
name: "valid token: has oid", | ||
tokenFactory: func() azcore.TokenCredential { | ||
return token{hasOid} | ||
}, | ||
}, { | ||
name: "valid token: has altsecid", | ||
tokenFactory: func() azcore.TokenCredential { | ||
return token{hasAltsecid} | ||
}, | ||
}, { | ||
name: "valid token: has puid", | ||
tokenFactory: func() azcore.TokenCredential { | ||
return token{hasPuid} | ||
}, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx := context.Background() | ||
scopes := []string{} | ||
tok := tt.tokenFactory() | ||
|
||
err := ensureAccessTokenClaims(ctx, tok, scopes) | ||
utilerror.AssertErrorMessage(t, err, tt.wantErr) | ||
}) | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/CHANGELOG.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 5 additions & 11 deletions
16
vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/client.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime/pipeline.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.