2023-05-24 10:22:00 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package user_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2024-07-26 20:39:55 +00:00
|
|
|
"time"
|
2023-05-24 10:22:00 +00:00
|
|
|
|
|
|
|
"github.com/muhlemmer/gu"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-07 15:28:42 +00:00
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
2024-02-28 10:21:11 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
2023-09-13 12:43:01 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2024-07-26 20:39:55 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
2023-05-24 10:22:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_RegisterPasskey(t *testing.T) {
|
2024-10-10 16:50:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
userID := Instance.CreateHumanUser(CTX).GetUserId()
|
2023-05-24 10:22:00 +00:00
|
|
|
reg, err := Client.CreatePasskeyRegistrationLink(CTX, &user.CreatePasskeyRegistrationLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Medium: &user.CreatePasskeyRegistrationLinkRequest_ReturnCode{},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-05 15:28:17 +00:00
|
|
|
// We also need a user session
|
2024-09-06 12:47:57 +00:00
|
|
|
Instance.RegisterUserPasskey(CTX, userID)
|
|
|
|
_, sessionToken, _, _ := Instance.CreateVerifiedWebAuthNSession(t, CTX, userID)
|
2023-12-05 15:28:17 +00:00
|
|
|
|
2023-05-24 10:22:00 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.RegisterPasskeyRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.RegisterPasskeyResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing user id",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.RegisterPasskeyRequest{},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "register code",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.RegisterPasskeyRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Code: reg.GetCode(),
|
|
|
|
Authenticator: user.PasskeyAuthenticator_PASSKEY_AUTHENTICATOR_PLATFORM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.RegisterPasskeyResponse{
|
|
|
|
Details: &object.Details{
|
2024-02-28 10:21:11 +00:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reuse code (not allowed)",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.RegisterPasskeyRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Code: reg.GetCode(),
|
|
|
|
Authenticator: user.PasskeyAuthenticator_PASSKEY_AUTHENTICATOR_PLATFORM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "wrong code",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.RegisterPasskeyRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Code: &user.PasskeyRegistrationCode{
|
|
|
|
Id: reg.GetCode().GetId(),
|
|
|
|
Code: "foobar",
|
|
|
|
},
|
|
|
|
Authenticator: user.PasskeyAuthenticator_PASSKEY_AUTHENTICATOR_CROSS_PLATFORM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user mismatch",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.RegisterPasskeyRequest{
|
|
|
|
UserId: userID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
2023-12-05 15:28:17 +00:00
|
|
|
name: "user setting its own passkey",
|
2023-05-24 10:22:00 +00:00
|
|
|
args: args{
|
2024-09-06 12:47:57 +00:00
|
|
|
ctx: integration.WithAuthorizationToken(CTX, sessionToken),
|
2023-05-24 10:22:00 +00:00
|
|
|
req: &user.RegisterPasskeyRequest{
|
2023-12-05 15:28:17 +00:00
|
|
|
UserId: userID,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.RegisterPasskeyResponse{
|
|
|
|
Details: &object.Details{
|
2024-02-28 10:21:11 +00:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := Client.RegisterPasskey(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, got)
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
if tt.want != nil {
|
|
|
|
assert.NotEmpty(t, got.GetPasskeyId())
|
|
|
|
assert.NotEmpty(t, got.GetPublicKeyCredentialCreationOptions())
|
2024-09-06 12:47:57 +00:00
|
|
|
_, err = Instance.WebAuthN.CreateAttestationResponse(got.GetPublicKeyCredentialCreationOptions())
|
2023-05-24 10:22:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_VerifyPasskeyRegistration(t *testing.T) {
|
2024-10-10 16:50:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-07-26 20:39:55 +00:00
|
|
|
userID, pkr := userWithPasskeyRegistered(t)
|
2023-05-24 10:22:00 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
attestationResponse, err := Instance.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions())
|
2023-05-24 10:22:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.VerifyPasskeyRegistrationRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.VerifyPasskeyRegistrationResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing user id",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.VerifyPasskeyRegistrationRequest{
|
|
|
|
PasskeyId: pkr.GetPasskeyId(),
|
2023-06-07 15:28:42 +00:00
|
|
|
PublicKeyCredential: attestationResponse,
|
2023-05-24 10:22:00 +00:00
|
|
|
PasskeyName: "nice name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.VerifyPasskeyRegistrationRequest{
|
|
|
|
UserId: userID,
|
|
|
|
PasskeyId: pkr.GetPasskeyId(),
|
|
|
|
PublicKeyCredential: attestationResponse,
|
|
|
|
PasskeyName: "nice name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.VerifyPasskeyRegistrationResponse{
|
|
|
|
Details: &object.Details{
|
2024-02-28 10:21:11 +00:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "wrong credential",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.VerifyPasskeyRegistrationRequest{
|
2023-06-07 15:28:42 +00:00
|
|
|
UserId: userID,
|
|
|
|
PasskeyId: pkr.GetPasskeyId(),
|
|
|
|
PublicKeyCredential: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{"foo": {Kind: &structpb.Value_StringValue{StringValue: "bar"}}},
|
|
|
|
},
|
|
|
|
PasskeyName: "nice name",
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := Client.VerifyPasskeyRegistration(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, got)
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_CreatePasskeyRegistrationLink(t *testing.T) {
|
2024-10-10 16:50:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
userID := Instance.CreateHumanUser(CTX).GetUserId()
|
2023-05-24 10:22:00 +00:00
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.CreatePasskeyRegistrationLinkRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.CreatePasskeyRegistrationLinkResponse
|
|
|
|
wantCode bool
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing user id",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.CreatePasskeyRegistrationLinkRequest{},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "send default mail",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.CreatePasskeyRegistrationLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.CreatePasskeyRegistrationLinkResponse{
|
|
|
|
Details: &object.Details{
|
2024-02-28 10:21:11 +00:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "send custom url",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.CreatePasskeyRegistrationLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Medium: &user.CreatePasskeyRegistrationLinkRequest_SendLink{
|
|
|
|
SendLink: &user.SendPasskeyRegistrationLink{
|
|
|
|
UrlTemplate: gu.Ptr("https://example.com/passkey/register?userID={{.UserID}}&orgID={{.OrgID}}&codeID={{.CodeID}}&code={{.Code}}"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.CreatePasskeyRegistrationLinkResponse{
|
|
|
|
Details: &object.Details{
|
2024-02-28 10:21:11 +00:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "return code",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
req: &user.CreatePasskeyRegistrationLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Medium: &user.CreatePasskeyRegistrationLinkRequest_ReturnCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.CreatePasskeyRegistrationLinkResponse{
|
|
|
|
Details: &object.Details{
|
2024-02-28 10:21:11 +00:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2023-05-24 10:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantCode: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := Client.CreatePasskeyRegistrationLink(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, got)
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
if tt.wantCode {
|
|
|
|
assert.NotEmpty(t, got.GetCode().GetId())
|
|
|
|
assert.NotEmpty(t, got.GetCode().GetId())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 20:39:55 +00:00
|
|
|
|
|
|
|
func userWithPasskeyRegistered(t *testing.T) (string, *user.RegisterPasskeyResponse) {
|
2024-09-06 12:47:57 +00:00
|
|
|
userID := Instance.CreateHumanUser(CTX).GetUserId()
|
2024-07-26 20:39:55 +00:00
|
|
|
return userID, passkeyRegister(t, userID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func userWithPasskeyVerified(t *testing.T) (string, string) {
|
|
|
|
userID, pkr := userWithPasskeyRegistered(t)
|
|
|
|
return userID, passkeyVerify(t, userID, pkr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func passkeyRegister(t *testing.T, userID string) *user.RegisterPasskeyResponse {
|
|
|
|
reg, err := Client.CreatePasskeyRegistrationLink(CTX, &user.CreatePasskeyRegistrationLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Medium: &user.CreatePasskeyRegistrationLinkRequest_ReturnCode{},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
pkr, err := Client.RegisterPasskey(CTX, &user.RegisterPasskeyRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Code: reg.GetCode(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, pkr.GetPasskeyId())
|
|
|
|
require.NotEmpty(t, pkr.GetPublicKeyCredentialCreationOptions())
|
|
|
|
return pkr
|
|
|
|
}
|
|
|
|
|
|
|
|
func passkeyVerify(t *testing.T, userID string, pkr *user.RegisterPasskeyResponse) string {
|
2024-09-06 12:47:57 +00:00
|
|
|
attestationResponse, err := Instance.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions())
|
2024-07-26 20:39:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = Client.VerifyPasskeyRegistration(CTX, &user.VerifyPasskeyRegistrationRequest{
|
|
|
|
UserId: userID,
|
|
|
|
PasskeyId: pkr.GetPasskeyId(),
|
|
|
|
PublicKeyCredential: attestationResponse,
|
|
|
|
PasskeyName: "nice name",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return pkr.GetPasskeyId()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_RemovePasskey(t *testing.T) {
|
2024-10-10 16:50:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
userIDWithout := Instance.CreateHumanUser(CTX).GetUserId()
|
2024-07-26 20:39:55 +00:00
|
|
|
userIDRegistered, pkrRegistered := userWithPasskeyRegistered(t)
|
|
|
|
userIDVerified, passkeyIDVerified := userWithPasskeyVerified(t)
|
|
|
|
userIDVerifiedPermission, passkeyIDVerifiedPermission := userWithPasskeyVerified(t)
|
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.RemovePasskeyRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.RemovePasskeyResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing user id",
|
|
|
|
args: args{
|
|
|
|
ctx: IamCTX,
|
|
|
|
req: &user.RemovePasskeyRequest{
|
|
|
|
PasskeyId: "123",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing passkey id",
|
|
|
|
args: args{
|
|
|
|
ctx: IamCTX,
|
|
|
|
req: &user.RemovePasskeyRequest{
|
|
|
|
UserId: "123",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success, registered",
|
|
|
|
args: args{
|
|
|
|
ctx: IamCTX,
|
|
|
|
req: &user.RemovePasskeyRequest{
|
|
|
|
UserId: userIDRegistered,
|
|
|
|
PasskeyId: pkrRegistered.GetPasskeyId(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.RemovePasskeyResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2024-07-26 20:39:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no passkey, error",
|
|
|
|
args: args{
|
|
|
|
ctx: IamCTX,
|
|
|
|
req: &user.RemovePasskeyRequest{
|
|
|
|
UserId: userIDWithout,
|
|
|
|
PasskeyId: pkrRegistered.GetPasskeyId(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success, verified",
|
|
|
|
args: args{
|
|
|
|
ctx: IamCTX,
|
|
|
|
req: &user.RemovePasskeyRequest{
|
|
|
|
UserId: userIDVerified,
|
|
|
|
PasskeyId: passkeyIDVerified,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.RemovePasskeyResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.DefaultOrg.Id,
|
2024-07-26 20:39:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "verified, permission error",
|
|
|
|
args: args{
|
|
|
|
ctx: UserCTX,
|
|
|
|
req: &user.RemovePasskeyRequest{
|
|
|
|
UserId: userIDVerifiedPermission,
|
|
|
|
PasskeyId: passkeyIDVerifiedPermission,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := Client.RemovePasskey(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, got)
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_ListPasskeys(t *testing.T) {
|
2024-10-10 16:50:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
userIDWithout := Instance.CreateHumanUser(CTX).GetUserId()
|
2024-07-26 20:39:55 +00:00
|
|
|
userIDRegistered, _ := userWithPasskeyRegistered(t)
|
|
|
|
userIDVerified, passkeyIDVerified := userWithPasskeyVerified(t)
|
|
|
|
|
|
|
|
userIDMulti, passkeyIDMulti1 := userWithPasskeyVerified(t)
|
|
|
|
passkeyIDMulti2 := passkeyVerify(t, userIDMulti, passkeyRegister(t, userIDMulti))
|
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.ListPasskeysRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.ListPasskeysResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
2024-08-23 06:44:18 +00:00
|
|
|
{
|
|
|
|
name: "list passkeys, no userID",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.ListPasskeysRequest{
|
|
|
|
UserId: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2024-07-26 20:39:55 +00:00
|
|
|
{
|
|
|
|
name: "list passkeys, no permission",
|
|
|
|
args: args{
|
|
|
|
UserCTX,
|
|
|
|
&user.ListPasskeysRequest{
|
|
|
|
UserId: userIDVerified,
|
|
|
|
},
|
|
|
|
},
|
2024-08-23 06:44:18 +00:00
|
|
|
wantErr: true,
|
2024-07-26 20:39:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list passkeys, none",
|
|
|
|
args: args{
|
2024-08-23 06:44:18 +00:00
|
|
|
IamCTX,
|
2024-07-26 20:39:55 +00:00
|
|
|
&user.ListPasskeysRequest{
|
|
|
|
UserId: userIDWithout,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListPasskeysResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
Result: []*user.Passkey{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list passkeys, registered",
|
|
|
|
args: args{
|
2024-08-23 06:44:18 +00:00
|
|
|
IamCTX,
|
2024-07-26 20:39:55 +00:00
|
|
|
&user.ListPasskeysRequest{
|
|
|
|
UserId: userIDRegistered,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListPasskeysResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
Result: []*user.Passkey{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list passkeys, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.ListPasskeysRequest{
|
|
|
|
UserId: userIDVerified,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListPasskeysResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
Result: []*user.Passkey{
|
|
|
|
{
|
|
|
|
Id: passkeyIDVerified,
|
|
|
|
State: user.AuthFactorState_AUTH_FACTOR_STATE_READY,
|
|
|
|
Name: "nice name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list idp links, multi, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.ListPasskeysRequest{
|
|
|
|
UserId: userIDMulti,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListPasskeysResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 2,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
Result: []*user.Passkey{
|
|
|
|
{
|
|
|
|
Id: passkeyIDMulti1,
|
|
|
|
State: user.AuthFactorState_AUTH_FACTOR_STATE_READY,
|
|
|
|
Name: "nice name",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: passkeyIDMulti2,
|
|
|
|
State: user.AuthFactorState_AUTH_FACTOR_STATE_READY,
|
|
|
|
Name: "nice name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-10-17 21:20:57 +00:00
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.args.ctx, time.Minute)
|
2024-07-26 20:39:55 +00:00
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
2024-10-17 21:20:57 +00:00
|
|
|
got, err := Client.ListPasskeys(tt.args.ctx, tt.args.req)
|
2024-07-26 20:39:55 +00:00
|
|
|
if tt.wantErr {
|
2024-10-17 21:20:57 +00:00
|
|
|
require.Error(ttt, err)
|
2024-07-26 20:39:55 +00:00
|
|
|
return
|
|
|
|
}
|
2024-10-17 21:20:57 +00:00
|
|
|
require.NoError(ttt, err)
|
2024-07-26 20:39:55 +00:00
|
|
|
// always first check length, otherwise its failed anyway
|
2024-10-21 19:15:02 +00:00
|
|
|
if assert.Len(ttt, got.Result, len(tt.want.Result)) {
|
|
|
|
for i := range tt.want.Result {
|
|
|
|
assert.Contains(ttt, got.Result, tt.want.Result[i])
|
|
|
|
}
|
2024-07-26 20:39:55 +00:00
|
|
|
}
|
2024-10-17 21:20:57 +00:00
|
|
|
integration.AssertListDetails(ttt, tt.want, got)
|
|
|
|
}, retryDuration, tick, "timeout waiting for expected idplinks result")
|
2024-07-26 20:39:55 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|