Skip to content

Commit

Permalink
special case for basic auth added
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Dec 7, 2018
1 parent 4f7a4dc commit c8fd291
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ func handleGetDetail(sessionKey, apiID string, byHash bool) (interface{}, int) {
spec := getApiSpec(apiID)
if spec != nil {
sessionManager = spec.SessionManager
// special case for basic auth with custom hashing algo
if spec.UseBasicAuth && strings.HasPrefix(sessionKey, spec.OrgID) {
sessionKey = generateToken(spec.OrgID, sessionKey)
}
}

var session user.SessionState
Expand Down
26 changes: 26 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ func TestHashKeyHandler(t *testing.T) {
t.Run(fmt.Sprintf("%sHash fn: %s", tc.desc, tc.hashFunction), func(t *testing.T) {
testHashKeyHandlerHelper(t, tc.expectedHashSize)
})
t.Run(fmt.Sprintf("%sHash fn: %s and Basic Auth", tc.desc, tc.hashFunction), func(t *testing.T) {
testHashFuncAndBAHelper(t)
})
}
}

Expand Down Expand Up @@ -419,6 +422,29 @@ func testHashKeyHandlerHelper(t *testing.T, expectedHashSize int) {
})
}

func testHashFuncAndBAHelper(t *testing.T) {
ts := newTykTestServer()
defer ts.Close()

session := testPrepareBasicAuth(false)

ts.Run(t, []test.TestCase{
{
Method: "POST",
Path: "/tyk/keys/defaultuser",
Data: session,
AdminAuth: true,
Code: 200,
},
{
Method: "GET",
Path: "/tyk/keys/defaultuser?api_id=test",
AdminAuth: true,
Code: 200,
},
}...)
}

func TestHashKeyListingDisabled(t *testing.T) {
globalConf := config.Global()
// make it to use hashes for Redis keys
Expand Down

0 comments on commit c8fd291

Please sign in to comment.