Skip to content

Commit

Permalink
Merge f946157 into 0edfb00
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Mar 12, 2019
2 parents 0edfb00 + f946157 commit 0e70488
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func (r *RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) erro
log.Debug("Adding ACCESS key to sorted list: ", sortedListKey)
r.store.AddToSortedSet(
sortedListKey,
accessData.AccessToken,
storage.HashKey(accessData.AccessToken),
float64(accessData.CreatedAt.Unix()+int64(accessData.ExpiresIn)), // set score as token expire timestamp
)

Expand Down
21 changes: 19 additions & 2 deletions oauth_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/storage"
"github.com/TykTechnologies/tyk/test"
"github.com/TykTechnologies/tyk/user"
)
Expand Down Expand Up @@ -467,11 +468,23 @@ func getAuthCode(t *testing.T, ts *tykTestServer) map[string]string {
}

func TestGetClientTokens(t *testing.T) {
t.Run("Without hashing", func(t *testing.T) {
testGetClientTokens(t, false)
})
t.Run("With hashing", func(t *testing.T) {
testGetClientTokens(t, true)
})
}

func testGetClientTokens(t *testing.T, hashed bool) {
globalConf := config.Global()
// set tokens to be expired after 1 second
globalConf.OauthTokenExpire = 1
// cleanup tokens older than 3 seconds
globalConf.OauthTokenExpiredRetainPeriod = 3

globalConf.HashKeys = hashed

config.SetGlobal(globalConf)

defer resetTestConfig()
Expand Down Expand Up @@ -516,8 +529,12 @@ func TestGetClientTokens(t *testing.T) {
t.Fatal(err)
}

// save tokens for future check
tokensID[response["access_token"].(string)] = true
if hashed {
// save tokens for future check
tokensID[storage.HashKey(response["access_token"].(string))] = true
} else {
tokensID[response["access_token"].(string)] = true
}
}
})

Expand Down

0 comments on commit 0e70488

Please sign in to comment.