Skip to content

Commit

Permalink
Update existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julienstroheker committed Aug 2, 2023
1 parent 8423a14 commit 104541b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion apps/confidential/confidential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func fakeClient(tk accesstokens.TokenResponse, credential Credential, options ..
fakeTokenEndpoint, "https://fake_authority/fake/jwt", "fake_authority"),
}
client.base.Token.WSTrust = &fake.WSTrust{}
client.base.AuthParams.AuthnScheme = &authority.BearerAuthenticationScheme{}
return client, nil
}

Expand Down Expand Up @@ -136,6 +137,7 @@ func TestAcquireTokenByCredential(t *testing.T) {
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
TokenType: "Bearer",
}, cred)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1238,6 +1240,7 @@ func TestWithAuthenticationScheme(t *testing.T) {
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
TokenType: "TokenType",
}, cred)
if err != nil {
t.Fatal(err)
Expand All @@ -1250,7 +1253,7 @@ func TestWithAuthenticationScheme(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if result.AccessToken != "FormatedAccessToken" {
if result.AccessToken != token+"-formated" {
t.Fatalf(`unexpected access token "%s"`, result.AccessToken)
}
}
7 changes: 5 additions & 2 deletions apps/internal/base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func TestAcquireTokenSilentGrantedScopes(t *testing.T) {
AccessToken: expectedToken,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: grantedScopes},
TokenType: "Bearer",
},
)
if err != nil {
Expand Down Expand Up @@ -273,6 +274,7 @@ func TestCacheIOErrors(t *testing.T) {
ClientID: fakeClientID,
HomeAccountID: hid,
Scopes: testScopes,
AuthnScheme: &authority.BearerAuthenticationScheme{},
},
accesstokens.TokenResponse{
AccessToken: "at",
Expand Down Expand Up @@ -457,8 +459,9 @@ func TestApplyAuthnScheme(t *testing.T) {
},
},
{
desc: "Should returns passed AuthResult if no AuthnScheme is set",
at: "noAutnScheme",
desc: "Should returns passed AuthResult if no AuthnScheme is set. (defaulted to Bearer)",
at: "noAutnScheme",
scheme: &authority.BearerAuthenticationScheme{},
want: AuthResult{
AccessToken: "noAutnScheme",
},
Expand Down
3 changes: 2 additions & 1 deletion apps/internal/base/internal/storage/items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
ExpiresOn: internalTime.Unix{T: expiresOn},
ExtendedExpiresOn: internalTime.Unix{T: extExpiresOn},
CachedAt: internalTime.Unix{T: cachedAt},
TokenType: "Bearer",
}
)

Expand All @@ -63,7 +64,7 @@ func TestCreateAccessToken(t *testing.T) {
}

func TestKeyForAccessToken(t *testing.T) {
const want = "testhid-env-accesstoken-clientid-realm-user.read"
const want = "testhid-env-accesstoken-clientid-realm-user.read-bearer"
got := atCacheEntity.Key()
if got != want {
t.Errorf("TestKeyForAccessToken: got %s, want %s", got, want)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestOBOAccessTokenScopes(t *testing.T) {
Scopes: scope,
UserAssertion: upn + "-assertion",
Username: idt.PreferredUsername,
AuthnScheme: &authority.BearerAuthenticationScheme{},
}
_, err := mgr.Write(
ap,
Expand All @@ -62,6 +63,7 @@ func TestOBOAccessTokenScopes(t *testing.T) {
GrantedScopes: accesstokens.Scopes{Slice: scope},
IDToken: idt,
RefreshToken: upn + "-rt",
TokenType: "Bearer",
},
)
if err != nil {
Expand Down Expand Up @@ -112,6 +114,7 @@ func TestOBOPartitioning(t *testing.T) {
Scopes: scopes,
UserAssertion: upn + "-assertion",
Username: idt.PreferredUsername,
AuthnScheme: &authority.BearerAuthenticationScheme{},
}
account, err := mgr.Write(
authParams[i],
Expand All @@ -122,6 +125,7 @@ func TestOBOPartitioning(t *testing.T) {
GrantedScopes: accesstokens.Scopes{Slice: scopes},
IDToken: idt,
RefreshToken: upn + "-rt",
TokenType: "Bearer",
},
)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions apps/internal/base/internal/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func TestRead(t *testing.T) {
time.Now(),
"openid profile",
"secret",
"tokenType",
"Bearer",
"",
)
testIDToken := NewIDToken("hid", "env", "realm", "cid", "secret")
Expand Down Expand Up @@ -761,6 +761,7 @@ func TestRead(t *testing.T) {
AuthorityInfo: authInfo,
ClientID: "cid",
Scopes: []string{"openid", "profile"},
AuthnScheme: &authority.BearerAuthenticationScheme{},
}

tests := []struct {
Expand Down Expand Up @@ -848,6 +849,7 @@ func TestWrite(t *testing.T) {
GrantedScopes: accesstokens.Scopes{Slice: []string{"openid", "profile"}},
ExpiresOn: expiresOn,
ExtExpiresOn: internalTime.DurationTime{T: now},
TokenType: "Bearer",
}
authInfo := authority.Info{Host: "env", Tenant: "realm", AuthorityType: accAuth}
authParams := authority.AuthParams{
Expand All @@ -872,7 +874,7 @@ func TestWrite(t *testing.T) {
now,
"openid profile",
"accessToken",
"tokenType",
"Bearer",
"",
)

Expand Down
2 changes: 1 addition & 1 deletion apps/internal/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (*Client) CloseIdleConnections() {}

func GetAccessTokenBody(accessToken, idToken, refreshToken, clientInfo string, expiresIn int) []byte {
body := fmt.Sprintf(
`{"access_token": "%s","expires_in": %d,"expires_on": %d`,
`{"access_token": "%s","expires_in": %d,"expires_on": %d,"token_type": "Bearer"`,
accessToken, expiresIn, time.Now().Add(time.Duration(expiresIn)*time.Second).Unix(),
)
if clientInfo != "" {
Expand Down

0 comments on commit 104541b

Please sign in to comment.