Skip to content

Commit

Permalink
fix(client): skip resource check in GetAccessToken when resource is…
Browse files Browse the repository at this point in the history
… empty string
  • Loading branch information
xiaoyijun committed Sep 6, 2022
1 parent a9e8985 commit f13011b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func (logtoClient *LogtoClient) GetAccessToken(resource string) (AccessToken, er
return AccessToken{}, ErrNotAuthenticated
}

// TODO: do not check granted resource if resource is empty
if !slices.Contains(logtoClient.logtoConfig.Resources, resource) {
return AccessToken{}, ErrUnacknowledgedResourceFound
if resource != "" {
if !slices.Contains(logtoClient.logtoConfig.Resources, resource) {
return AccessToken{}, ErrUnacknowledgedResourceFound
}
}

accessTokenKey := buildAccessTokenKey([]string{}, resource)
Expand Down
12 changes: 3 additions & 9 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ func TestGetAccessTokenShouldReturnAccessTokenAccessTokenInTokenMap(t *testing.T
}

logtoClient := NewLogtoClient(
&LogtoConfig{
Resources: []string{""},
},
&LogtoConfig{},
&TestStorage{
data: map[string]string{
StorageKeyIdToken: "id token",
Expand All @@ -39,9 +37,7 @@ func TestGetAccessTokenShouldReturnAccessTokenAccessTokenInTokenMap(t *testing.T

func TestGetAccessTokenShouldReturnNotAuthenticatedErrIfNoIdTokenAvailable(t *testing.T) {
logtoClient := NewLogtoClient(
&LogtoConfig{
Resources: []string{""},
},
&LogtoConfig{},
&TestStorage{
data: map[string]string{
StorageKeyIdToken: "",
Expand Down Expand Up @@ -95,9 +91,7 @@ func TestGetAccessTokenShouldReturnFetchedAccessTokenAndUpdateLocalAccessTokenIf
defer patchesForVerifyIdToken.Reset()

logtoClient := NewLogtoClient(
&LogtoConfig{
Resources: []string{""},
},
&LogtoConfig{},
&TestStorage{
data: map[string]string{
StorageKeyIdToken: "id token",
Expand Down
4 changes: 1 addition & 3 deletions client/handle_sign_in_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ func TestHandleSignInCallbackShouldHandleCallbackCorrectly(t *testing.T) {
},
}

logtoClient := NewLogtoClient(&LogtoConfig{
Resources: []string{""},
}, storage)
logtoClient := NewLogtoClient(&LogtoConfig{}, storage)

signInCallbackRequest, createSignInCallbackRequestErr := http.NewRequest("GET", "https://example.com/sign-in-callback", nil)
assert.Nil(t, createSignInCallbackRequestErr)
Expand Down
9 changes: 2 additions & 7 deletions client/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ func TestFetchOidcConfigShouldReturnExpectedOidcConfig(t *testing.T) {
func TestLoadAccessTokenMapShouldLoadAccessTokenMapFromStorage(t *testing.T) {
expiresAt := time.Now().Unix() + 60

logtoConfig := &LogtoConfig{
Resources: []string{"testResource"},
}
logtoConfig := &LogtoConfig{}

testStorage := &TestStorage{
data: map[string]string{
Expand Down Expand Up @@ -152,10 +150,7 @@ func TestVerifyAndSaveTokenResponseShouldSaveToken(t *testing.T) {

defer patchesForVerifyIdToken.Reset()

logtoClient := NewLogtoClient(&LogtoConfig{
// TODO: do not check granted resource if resource is empty
Resources: []string{""},
}, &TestStorage{
logtoClient := NewLogtoClient(&LogtoConfig{}, &TestStorage{
data: map[string]string{},
})

Expand Down

0 comments on commit f13011b

Please sign in to comment.