Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nannany committed Feb 15, 2025
1 parent 32ff570 commit ddbbcdb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions example/server/storage/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ func authRequestToInternal(authReq *oidc.AuthRequest, userID string) *AuthReques
}
}

type AuthRequestWithSessionState struct {
*AuthRequest
SessionState string
}

func (a *AuthRequestWithSessionState) GetSessionState() string {
return a.SessionState
}

type OIDCCodeChallenge struct {
Challenge string
Method string
Expand Down
28 changes: 28 additions & 0 deletions pkg/op/auth_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,34 @@ func TestAuthResponseCode(t *testing.T) {
wantBody: "",
},
},
{
name: "success with state and session_state",
args: args{
authReq: &storage.AuthRequestWithSessionState{
AuthRequest: &storage.AuthRequest{
ID: "id1",
TransferState: "state1",
},
SessionState: "state2",
},
authorizer: func(t *testing.T) op.Authorizer {
ctrl := gomock.NewController(t)
storage := mock.NewMockStorage(ctrl)
storage.EXPECT().SaveAuthCode(gomock.Any(), "id1", "id1")

authorizer := mock.NewMockAuthorizer(ctrl)
authorizer.EXPECT().Storage().Return(storage)
authorizer.EXPECT().Crypto().Return(&mockCrypto{})
authorizer.EXPECT().Encoder().Return(schema.NewEncoder())
return authorizer
},
},
res: res{
wantCode: http.StatusFound,
wantLocationHeader: "/auth/callback/?code=id1&session_state=state2&state=state1",
wantBody: "",
},
},
{
name: "success without state", // reproduce issue #415
args: args{
Expand Down

0 comments on commit ddbbcdb

Please sign in to comment.