2023-07-10 13:27:00 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-19 10:34:00 +00:00
|
|
|
"net"
|
|
|
|
"net/http"
|
2023-07-10 13:27:00 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/muhlemmer/gu"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
|
|
"github.com/zitadel/zitadel/internal/id/mock"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/authrequest"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/session"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-07-10 13:27:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommands_AddAuthRequest(t *testing.T) {
|
|
|
|
mockCtx := authz.NewMockContext("instanceID", "orgID", "loginClient")
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
request *AuthRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want *CurrentAuthRequest
|
|
|
|
wantErr error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"already exists error",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: mock.NewIDGeneratorExpectIDs(t, "id"),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
request: &AuthRequest{},
|
|
|
|
},
|
|
|
|
nil,
|
2023-12-08 14:30:55 +00:00
|
|
|
zerrors.ThrowPreconditionFailed(nil, "COMMAND-Sf3gt", "Errors.AuthRequest.AlreadyExisting"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"added",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
&domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
[]domain.Prompt{domain.PromptNone},
|
|
|
|
[]string{"en", "de"},
|
|
|
|
gu.Ptr(time.Duration(0)),
|
|
|
|
gu.Ptr("loginHint"),
|
|
|
|
gu.Ptr("hintUserID"),
|
|
|
|
),
|
|
|
|
),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
idGenerator: mock.NewIDGeneratorExpectIDs(t, "id"),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
request: &AuthRequest{
|
|
|
|
LoginClient: "loginClient",
|
|
|
|
ClientID: "clientID",
|
|
|
|
RedirectURI: "redirectURI",
|
|
|
|
State: "state",
|
|
|
|
Nonce: "nonce",
|
|
|
|
Scope: []string{"openid"},
|
|
|
|
Audience: []string{"audience"},
|
|
|
|
ResponseType: domain.OIDCResponseTypeCode,
|
|
|
|
CodeChallenge: &domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
Prompt: []domain.Prompt{domain.PromptNone},
|
|
|
|
UILocales: []string{"en", "de"},
|
|
|
|
MaxAge: gu.Ptr(time.Duration(0)),
|
|
|
|
LoginHint: gu.Ptr("loginHint"),
|
|
|
|
HintUserID: gu.Ptr("hintUserID"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&CurrentAuthRequest{
|
|
|
|
AuthRequest: &AuthRequest{
|
|
|
|
ID: "V2_id",
|
|
|
|
LoginClient: "loginClient",
|
|
|
|
ClientID: "clientID",
|
|
|
|
RedirectURI: "redirectURI",
|
|
|
|
State: "state",
|
|
|
|
Nonce: "nonce",
|
|
|
|
Scope: []string{"openid"},
|
|
|
|
Audience: []string{"audience"},
|
|
|
|
ResponseType: domain.OIDCResponseTypeCode,
|
|
|
|
CodeChallenge: &domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
Prompt: []domain.Prompt{domain.PromptNone},
|
|
|
|
UILocales: []string{"en", "de"},
|
|
|
|
MaxAge: gu.Ptr(time.Duration(0)),
|
|
|
|
LoginHint: gu.Ptr("loginHint"),
|
|
|
|
HintUserID: gu.Ptr("hintUserID"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
}
|
|
|
|
got, err := c.AddAuthRequest(tt.args.ctx, tt.args.request)
|
|
|
|
require.ErrorIs(t, tt.wantErr, err)
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommands_LinkSessionToAuthRequest(t *testing.T) {
|
|
|
|
mockCtx := authz.NewMockContext("instanceID", "orgID", "loginClient")
|
|
|
|
type fields struct {
|
2023-11-16 06:35:50 +00:00
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
tokenVerifier func(ctx context.Context, sessionToken, sessionID, tokenID string) (err error)
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
id string
|
|
|
|
sessionID string
|
|
|
|
sessionToken string
|
|
|
|
checkLoginClient bool
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
details *domain.ObjectDetails
|
|
|
|
authReq *CurrentAuthRequest
|
|
|
|
wantErr error
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"authRequest not found",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierValid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowNotFound(nil, "COMMAND-jae5P", "Errors.AuthRequest.NotExisting"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"authRequest not existing",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewFailedEvent(mockCtx, &authrequest.NewAggregate("id", "instanceID").Aggregate,
|
|
|
|
domain.OIDCErrorReasonUnspecified),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierValid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowPreconditionFailed(nil, "COMMAND-Sx208nt", "Errors.AuthRequest.AlreadyHandled"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"wrong login client",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierValid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: authz.NewMockContext("instanceID", "orgID", "wrongLoginClient"),
|
|
|
|
id: "id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
sessionToken: "token",
|
|
|
|
checkLoginClient: true,
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowPermissionDenied(nil, "COMMAND-rai9Y", "Errors.AuthRequest.WrongLoginClient"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"session not existing",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierValid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowPreconditionFailed(nil, "COMMAND-Flk38", "Errors.Session.NotExisting"),
|
2023-11-06 09:48:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"session expired",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
session.NewAddedEvent(mockCtx,
|
2023-11-16 06:35:50 +00:00
|
|
|
&session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-11-06 09:48:28 +00:00
|
|
|
&domain.UserAgent{
|
|
|
|
FingerprintID: gu.Ptr("fp1"),
|
|
|
|
IP: net.ParseIP("1.2.3.4"),
|
|
|
|
Description: gu.Ptr("firefox"),
|
|
|
|
Header: http.Header{"foo": []string{"bar"}},
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewUserCheckedEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
|
|
|
"userID", "org1", testNow.Add(-5*time.Minute)),
|
2023-11-06 09:48:28 +00:00
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewPasswordCheckedEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-11-06 09:48:28 +00:00
|
|
|
testNow.Add(-5*time.Minute)),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewLifetimeSetEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-11-06 09:48:28 +00:00
|
|
|
2*time.Minute),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
sessionToken: "token",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowPreconditionFailed(nil, "COMMAND-Hkl3d", "Errors.Session.Expired"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid session token",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2023-10-19 10:34:00 +00:00
|
|
|
session.NewAddedEvent(mockCtx,
|
2023-11-16 06:35:50 +00:00
|
|
|
&session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-10-19 10:34:00 +00:00
|
|
|
&domain.UserAgent{
|
|
|
|
FingerprintID: gu.Ptr("fp1"),
|
|
|
|
IP: net.ParseIP("1.2.3.4"),
|
|
|
|
Description: gu.Ptr("firefox"),
|
|
|
|
Header: http.Header{"foo": []string{"bar"}},
|
|
|
|
},
|
|
|
|
)),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierInvalid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
sessionToken: "invalid",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowPermissionDenied(nil, "COMMAND-sGr42", "Errors.Session.Token.Invalid"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"linked",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2023-10-19 10:34:00 +00:00
|
|
|
session.NewAddedEvent(mockCtx,
|
2023-11-16 06:35:50 +00:00
|
|
|
&session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-10-19 10:34:00 +00:00
|
|
|
&domain.UserAgent{
|
|
|
|
FingerprintID: gu.Ptr("fp1"),
|
|
|
|
IP: net.ParseIP("1.2.3.4"),
|
|
|
|
Description: gu.Ptr("firefox"),
|
|
|
|
Header: http.Header{"foo": []string{"bar"}},
|
|
|
|
},
|
|
|
|
)),
|
2023-07-10 13:27:00 +00:00
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewUserCheckedEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
|
|
|
"userID", "org1", testNow),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewPasswordCheckedEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-07-10 13:27:00 +00:00
|
|
|
testNow),
|
|
|
|
),
|
2023-11-06 09:48:28 +00:00
|
|
|
eventFromEventPusherWithCreationDateNow(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewLifetimeSetEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-11-06 09:48:28 +00:00
|
|
|
2*time.Minute),
|
|
|
|
),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"sessionID",
|
|
|
|
"userID",
|
|
|
|
testNow,
|
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
|
|
|
),
|
|
|
|
),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierValid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
sessionToken: "token",
|
|
|
|
},
|
|
|
|
res{
|
|
|
|
details: &domain.ObjectDetails{ResourceOwner: "instanceID"},
|
|
|
|
authReq: &CurrentAuthRequest{
|
|
|
|
AuthRequest: &AuthRequest{
|
|
|
|
ID: "V2_id",
|
|
|
|
LoginClient: "loginClient",
|
|
|
|
ClientID: "clientID",
|
|
|
|
RedirectURI: "redirectURI",
|
|
|
|
State: "state",
|
|
|
|
Nonce: "nonce",
|
|
|
|
Scope: []string{"openid"},
|
|
|
|
Audience: []string{"audience"},
|
|
|
|
ResponseType: domain.OIDCResponseTypeCode,
|
|
|
|
},
|
2023-07-12 12:24:01 +00:00
|
|
|
SessionID: "sessionID",
|
|
|
|
UserID: "userID",
|
|
|
|
AuthMethods: []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"linked with login client check",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2023-10-19 10:34:00 +00:00
|
|
|
session.NewAddedEvent(mockCtx,
|
2023-11-16 06:35:50 +00:00
|
|
|
&session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-10-19 10:34:00 +00:00
|
|
|
&domain.UserAgent{
|
|
|
|
FingerprintID: gu.Ptr("fp1"),
|
|
|
|
IP: net.ParseIP("1.2.3.4"),
|
|
|
|
Description: gu.Ptr("firefox"),
|
|
|
|
Header: http.Header{"foo": []string{"bar"}},
|
|
|
|
},
|
|
|
|
)),
|
2023-07-10 13:27:00 +00:00
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewUserCheckedEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
|
|
|
"userID", "org1", testNow),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewPasswordCheckedEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-07-10 13:27:00 +00:00
|
|
|
testNow),
|
|
|
|
),
|
2023-11-06 09:48:28 +00:00
|
|
|
eventFromEventPusherWithCreationDateNow(
|
2023-11-16 06:35:50 +00:00
|
|
|
session.NewLifetimeSetEvent(mockCtx, &session.NewAggregate("sessionID", "instance1").Aggregate,
|
2023-11-06 09:48:28 +00:00
|
|
|
2*time.Minute),
|
|
|
|
),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"sessionID",
|
|
|
|
"userID",
|
|
|
|
testNow,
|
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
|
|
|
),
|
|
|
|
),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
tokenVerifier: newMockTokenVerifierValid(),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: authz.NewMockContext("instanceID", "orgID", "loginClient"),
|
|
|
|
id: "V2_id",
|
|
|
|
sessionID: "sessionID",
|
|
|
|
sessionToken: "token",
|
|
|
|
checkLoginClient: true,
|
|
|
|
},
|
|
|
|
res{
|
|
|
|
details: &domain.ObjectDetails{ResourceOwner: "instanceID"},
|
|
|
|
authReq: &CurrentAuthRequest{
|
|
|
|
AuthRequest: &AuthRequest{
|
|
|
|
ID: "V2_id",
|
|
|
|
LoginClient: "loginClient",
|
|
|
|
ClientID: "clientID",
|
|
|
|
RedirectURI: "redirectURI",
|
|
|
|
State: "state",
|
|
|
|
Nonce: "nonce",
|
|
|
|
Scope: []string{"openid"},
|
|
|
|
Audience: []string{"audience"},
|
|
|
|
ResponseType: domain.OIDCResponseTypeCode,
|
|
|
|
},
|
2023-07-12 12:24:01 +00:00
|
|
|
SessionID: "sessionID",
|
|
|
|
UserID: "userID",
|
|
|
|
AuthMethods: []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
sessionTokenVerifier: tt.fields.tokenVerifier,
|
|
|
|
}
|
|
|
|
details, got, err := c.LinkSessionToAuthRequest(tt.args.ctx, tt.args.id, tt.args.sessionID, tt.args.sessionToken, tt.args.checkLoginClient)
|
|
|
|
require.ErrorIs(t, err, tt.res.wantErr)
|
|
|
|
assert.Equal(t, tt.res.details, details)
|
|
|
|
if err == nil {
|
|
|
|
assert.WithinRange(t, got.AuthTime, testNow, testNow)
|
|
|
|
got.AuthTime = time.Time{}
|
|
|
|
}
|
|
|
|
assert.Equal(t, tt.res.authReq, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommands_FailAuthRequest(t *testing.T) {
|
|
|
|
mockCtx := authz.NewMockContext("instanceID", "orgID", "loginClient")
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
id string
|
|
|
|
reason domain.OIDCErrorReason
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
details *domain.ObjectDetails
|
|
|
|
authReq *CurrentAuthRequest
|
|
|
|
wantErr error
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"authRequest not existing",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "foo",
|
|
|
|
reason: domain.OIDCErrorReasonLoginRequired,
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
wantErr: zerrors.ThrowPreconditionFailed(nil, "COMMAND-Sx202nt", "Errors.AuthRequest.AlreadyHandled"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"failed",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
authrequest.NewFailedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
|
|
|
|
domain.OIDCErrorReasonLoginRequired),
|
|
|
|
),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_id",
|
|
|
|
reason: domain.OIDCErrorReasonLoginRequired,
|
|
|
|
},
|
|
|
|
res{
|
|
|
|
details: &domain.ObjectDetails{ResourceOwner: "instanceID"},
|
|
|
|
authReq: &CurrentAuthRequest{
|
|
|
|
AuthRequest: &AuthRequest{
|
|
|
|
ID: "V2_id",
|
|
|
|
LoginClient: "loginClient",
|
|
|
|
ClientID: "clientID",
|
|
|
|
RedirectURI: "redirectURI",
|
|
|
|
State: "state",
|
|
|
|
Nonce: "nonce",
|
|
|
|
Scope: []string{"openid"},
|
|
|
|
Audience: []string{"audience"},
|
|
|
|
ResponseType: domain.OIDCResponseTypeCode,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
|
|
|
details, got, err := c.FailAuthRequest(tt.args.ctx, tt.args.id, tt.args.reason)
|
|
|
|
require.ErrorIs(t, err, tt.res.wantErr)
|
|
|
|
assert.Equal(t, tt.res.details, details)
|
|
|
|
assert.Equal(t, tt.res.authReq, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommands_AddAuthRequestCode(t *testing.T) {
|
|
|
|
mockCtx := authz.NewMockContext("instanceID", "orgID", "loginClient")
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
id string
|
|
|
|
code string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
wantErr error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"empty code error",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_authRequestID",
|
|
|
|
code: "",
|
|
|
|
},
|
2023-12-08 14:30:55 +00:00
|
|
|
zerrors.ThrowPreconditionFailed(nil, "COMMAND-Ht52d", "Errors.AuthRequest.InvalidCode"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"no session linked error",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
&domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
[]domain.Prompt{domain.PromptNone},
|
|
|
|
[]string{"en", "de"},
|
|
|
|
gu.Ptr(time.Duration(0)),
|
|
|
|
gu.Ptr("loginHint"),
|
|
|
|
gu.Ptr("hintUserID"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_authRequestID",
|
|
|
|
code: "V2_authRequestID",
|
|
|
|
},
|
2023-12-08 14:30:55 +00:00
|
|
|
zerrors.ThrowPreconditionFailed(nil, "COMMAND-SFwd2", "Errors.AuthRequest.AlreadyHandled"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"success",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
&domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
[]domain.Prompt{domain.PromptNone},
|
|
|
|
[]string{"en", "de"},
|
|
|
|
gu.Ptr(time.Duration(0)),
|
|
|
|
gu.Ptr("loginHint"),
|
|
|
|
gu.Ptr("hintUserID"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate,
|
|
|
|
"sessionID",
|
|
|
|
"userID",
|
|
|
|
testNow,
|
2023-07-12 12:24:01 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
authrequest.NewCodeAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
id: "V2_authRequestID",
|
|
|
|
code: "V2_authRequestID",
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
|
|
|
err := c.AddAuthRequestCode(tt.args.ctx, tt.args.id, tt.args.code)
|
|
|
|
assert.ErrorIs(t, tt.wantErr, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommands_ExchangeAuthCode(t *testing.T) {
|
|
|
|
mockCtx := authz.NewMockContext("instanceID", "orgID", "loginClient")
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
code string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
authRequest *CurrentAuthRequest
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"empty code error",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
code: "",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
err: zerrors.ThrowPreconditionFailed(nil, "COMMAND-Sf3g2", "Errors.AuthRequest.InvalidCode"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"no code added error",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
&domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
[]domain.Prompt{domain.PromptNone},
|
|
|
|
[]string{"en", "de"},
|
|
|
|
gu.Ptr(time.Duration(0)),
|
|
|
|
gu.Ptr("loginHint"),
|
|
|
|
gu.Ptr("hintUserID"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
code: "V2_authRequestID",
|
|
|
|
},
|
|
|
|
res{
|
2023-12-08 14:30:55 +00:00
|
|
|
err: zerrors.ThrowPreconditionFailed(nil, "COMMAND-SFwd2", "Errors.AuthRequest.NoCode"),
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"code exchanged",
|
|
|
|
fields{
|
|
|
|
eventstore: eventstoreExpect(t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate,
|
|
|
|
"loginClient",
|
|
|
|
"clientID",
|
|
|
|
"redirectURI",
|
|
|
|
"state",
|
|
|
|
"nonce",
|
|
|
|
[]string{"openid"},
|
|
|
|
[]string{"audience"},
|
|
|
|
domain.OIDCResponseTypeCode,
|
|
|
|
&domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
[]domain.Prompt{domain.PromptNone},
|
|
|
|
[]string{"en", "de"},
|
|
|
|
gu.Ptr(time.Duration(0)),
|
|
|
|
gu.Ptr("loginHint"),
|
|
|
|
gu.Ptr("hintUserID"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate,
|
|
|
|
"sessionID",
|
|
|
|
"userID",
|
|
|
|
testNow,
|
2023-07-12 12:24:01 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
authrequest.NewCodeAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
authrequest.NewCodeExchangedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
|
2023-07-10 13:27:00 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
ctx: mockCtx,
|
|
|
|
code: "V2_authRequestID",
|
|
|
|
},
|
|
|
|
res{
|
|
|
|
authRequest: &CurrentAuthRequest{
|
|
|
|
AuthRequest: &AuthRequest{
|
|
|
|
ID: "V2_authRequestID",
|
|
|
|
LoginClient: "loginClient",
|
|
|
|
ClientID: "clientID",
|
|
|
|
RedirectURI: "redirectURI",
|
|
|
|
State: "state",
|
|
|
|
Nonce: "nonce",
|
|
|
|
Scope: []string{"openid"},
|
|
|
|
Audience: []string{"audience"},
|
|
|
|
ResponseType: domain.OIDCResponseTypeCode,
|
|
|
|
CodeChallenge: &domain.OIDCCodeChallenge{
|
|
|
|
Challenge: "challenge",
|
|
|
|
Method: domain.CodeChallengeMethodS256,
|
|
|
|
},
|
|
|
|
Prompt: []domain.Prompt{domain.PromptNone},
|
|
|
|
UILocales: []string{"en", "de"},
|
|
|
|
MaxAge: gu.Ptr(time.Duration(0)),
|
|
|
|
LoginHint: gu.Ptr("loginHint"),
|
|
|
|
HintUserID: gu.Ptr("hintUserID"),
|
|
|
|
},
|
2023-07-12 12:24:01 +00:00
|
|
|
SessionID: "sessionID",
|
|
|
|
UserID: "userID",
|
|
|
|
AuthMethods: []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
|
|
|
got, err := c.ExchangeAuthCode(tt.args.ctx, tt.args.code)
|
|
|
|
assert.ErrorIs(t, tt.res.err, err)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
// equal on time won't work -> test separately and clear it before comparing the rest
|
|
|
|
assert.WithinRange(t, got.AuthTime, testNow, testNow)
|
|
|
|
got.AuthTime = time.Time{}
|
|
|
|
}
|
|
|
|
assert.Equal(t, tt.res.authRequest, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|