Skip to content

Commit

Permalink
enforce hashing of custom user-if func result
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Sep 2, 2021
1 parent 940f288 commit 5578dee
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion auth_test.go
Expand Up @@ -395,7 +395,7 @@ func TestDirectProvider_WithCustomUserIDFunc(t *testing.T) {
t.Logf("resp %s", string(body))
t.Logf("headers: %+v", resp.Header)

assert.Contains(t, string(body), `"name":"dev_direct","id":"direct_custom_blah"`)
assert.Contains(t, string(body), `"name":"dev_direct","id":"direct_custom_5bf1fd927dfb8679496a2e6cf00cbe50c1c87145"`)

require.Equal(t, 2, len(resp.Cookies()))
assert.Equal(t, "JWT", resp.Cookies()[0].Name)
Expand Down
2 changes: 1 addition & 1 deletion provider/direct.go
Expand Up @@ -98,7 +98,7 @@ func (p DirectHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {

userID := p.ProviderName + "_" + token.HashID(sha1.New(), creds.User)
if p.UserIDFunc != nil {
userID = p.ProviderName + "_" + p.UserIDFunc(creds.User, r)
userID = p.ProviderName + "_" + token.HashID(sha1.New(), p.UserIDFunc(creds.User, r))
}

u := token.User{
Expand Down
2 changes: 1 addition & 1 deletion provider/direct_test.go
Expand Up @@ -121,7 +121,7 @@ func TestDirect_LoginHandlerCustomUserID(t *testing.T) {
require.NoError(t, err)
handler.ServeHTTP(rr, req)
assert.Equal(t, 200, rr.Code)
assert.Equal(t, `{"name":"myuser","id":"test_myuser_custom_id","picture":""}`+"\n", rr.Body.String())
assert.Equal(t, `{"name":"myuser","id":"test_18c4eec1ecbe23902609e999c4d3da997e7ac10f","picture":""}`+"\n", rr.Body.String())
}

func TestDirect_LoginHandlerFailed(t *testing.T) {
Expand Down

0 comments on commit 5578dee

Please sign in to comment.