Skip to content

Commit

Permalink
config: allow blank identity providers when loading sessions for serv…
Browse files Browse the repository at this point in the history
…ice account support
  • Loading branch information
calebdoxsey committed Oct 26, 2022
1 parent 1b59611 commit 8e55698
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 9 additions & 7 deletions config/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ func (store *SessionStore) LoadSessionState(r *http.Request) (*sessions.State, e
}

// confirm that the identity provider id matches the state
idp, err := store.options.GetIdentityProviderForRequestURL(urlutil.GetAbsoluteURL(r).String())
if err != nil {
return nil, err
}
if state.IdentityProviderID != "" {
idp, err := store.options.GetIdentityProviderForRequestURL(urlutil.GetAbsoluteURL(r).String())
if err != nil {
return nil, err
}

if idp.GetId() != state.IdentityProviderID {
return nil, fmt.Errorf("unexpected session state identity provider id: %s != %s",
idp.GetId(), state.IdentityProviderID)
if idp.GetId() != state.IdentityProviderID {
return nil, fmt.Errorf("unexpected session state identity provider id: %s != %s",
idp.GetId(), state.IdentityProviderID)
}
}

return &state, nil
Expand Down
16 changes: 16 additions & 0 deletions config/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,20 @@ func TestSessionStore_LoadSessionState(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, s)
})
t.Run("blank idp", func(t *testing.T) {
rawJWS := makeJWS(t, &sessions.State{
Issuer: "authenticate.example.com",
ID: "example",
})

r, err := http.NewRequest(http.MethodGet, "https://p2.example.com", nil)
require.NoError(t, err)
r.Header.Set(httputil.HeaderPomeriumAuthorization, rawJWS)
s, err := store.LoadSessionState(r)
assert.NoError(t, err)
assert.Empty(t, cmp.Diff(&sessions.State{
Issuer: "authenticate.example.com",
ID: "example",
}, s))
})
}

0 comments on commit 8e55698

Please sign in to comment.