diff --git a/internal/api/grpc/user/v2/passkey_integration_test.go b/internal/api/grpc/user/v2/passkey_integration_test.go index 139bef3e68..383eeb0c82 100644 --- a/internal/api/grpc/user/v2/passkey_integration_test.go +++ b/internal/api/grpc/user/v2/passkey_integration_test.go @@ -24,6 +24,10 @@ func TestServer_RegisterPasskey(t *testing.T) { }) require.NoError(t, err) + // We also need a user session + Tester.RegisterUserPasskey(CTX, userID) + _, sessionToken, _, _ := Tester.CreateVerifiedWebAuthNSession(t, CTX, userID) + type args struct { ctx context.Context req *user.RegisterPasskeyRequest @@ -95,14 +99,12 @@ func TestServer_RegisterPasskey(t *testing.T) { }, wantErr: true, }, - /* TODO: after we are able to obtain a Bearer token for a human user - https://github.com/zitadel/zitadel/issues/6022 { - name: "human user", + name: "user setting its own passkey", args: args{ - ctx: CTX, + ctx: Tester.WithAuthorizationToken(CTX, sessionToken), req: &user.RegisterPasskeyRequest{ - UserId: humanUserID, + UserId: userID, }, }, want: &user.RegisterPasskeyResponse{ @@ -111,7 +113,6 @@ func TestServer_RegisterPasskey(t *testing.T) { }, }, }, - */ } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/api/grpc/user/v2/totp_integration_test.go b/internal/api/grpc/user/v2/totp_integration_test.go index 18a5e43bd1..4fef7bbf9b 100644 --- a/internal/api/grpc/user/v2/totp_integration_test.go +++ b/internal/api/grpc/user/v2/totp_integration_test.go @@ -5,16 +5,22 @@ package user_test import ( "context" "testing" + "time" + "github.com/pquerna/otp/totp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/zitadel/zitadel/internal/integration" + object "github.com/zitadel/zitadel/pkg/grpc/object/v2beta" user "github.com/zitadel/zitadel/pkg/grpc/user/v2beta" ) func TestServer_RegisterTOTP(t *testing.T) { - // userID := Tester.CreateHumanUser(CTX).GetUserId() + userID := Tester.CreateHumanUser(CTX).GetUserId() + Tester.RegisterUserPasskey(CTX, userID) + _, sessionToken, _, _ := Tester.CreateVerifiedWebAuthNSession(t, CTX, userID) + ctx := Tester.WithAuthorizationToken(CTX, sessionToken) type args struct { ctx context.Context @@ -29,7 +35,7 @@ func TestServer_RegisterTOTP(t *testing.T) { { name: "missing user id", args: args{ - ctx: CTX, + ctx: ctx, req: &user.RegisterTOTPRequest{}, }, wantErr: true, @@ -37,19 +43,17 @@ func TestServer_RegisterTOTP(t *testing.T) { { name: "user mismatch", args: args{ - ctx: CTX, + ctx: ctx, req: &user.RegisterTOTPRequest{ UserId: "wrong", }, }, wantErr: true, }, - /* TODO: after we are able to obtain a Bearer token for a human user - https://github.com/zitadel/zitadel/issues/6022 { - name: "human user", + name: "success", args: args{ - ctx: CTX, + ctx: ctx, req: &user.RegisterTOTPRequest{ UserId: userID, }, @@ -60,7 +64,6 @@ func TestServer_RegisterTOTP(t *testing.T) { }, }, }, - */ } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -80,15 +83,16 @@ func TestServer_RegisterTOTP(t *testing.T) { func TestServer_VerifyTOTPRegistration(t *testing.T) { userID := Tester.CreateHumanUser(CTX).GetUserId() + Tester.RegisterUserPasskey(CTX, userID) + _, sessionToken, _, _ := Tester.CreateVerifiedWebAuthNSession(t, CTX, userID) + ctx := Tester.WithAuthorizationToken(CTX, sessionToken) - /* TODO: after we are able to obtain a Bearer token for a human user - reg, err := Client.RegisterTOTP(CTX, &user.RegisterTOTPRequest{ + reg, err := Client.RegisterTOTP(ctx, &user.RegisterTOTPRequest{ UserId: userID, }) require.NoError(t, err) code, err := totp.GenerateCode(reg.Secret, time.Now()) require.NoError(t, err) - */ type args struct { ctx context.Context @@ -103,7 +107,7 @@ func TestServer_VerifyTOTPRegistration(t *testing.T) { { name: "user mismatch", args: args{ - ctx: CTX, + ctx: ctx, req: &user.VerifyTOTPRegistrationRequest{ UserId: "wrong", }, @@ -113,7 +117,7 @@ func TestServer_VerifyTOTPRegistration(t *testing.T) { { name: "wrong code", args: args{ - ctx: CTX, + ctx: ctx, req: &user.VerifyTOTPRegistrationRequest{ UserId: userID, Code: "123", @@ -121,12 +125,10 @@ func TestServer_VerifyTOTPRegistration(t *testing.T) { }, wantErr: true, }, - /* TODO: after we are able to obtain a Bearer token for a human user - https://github.com/zitadel/zitadel/issues/6022 { name: "success", args: args{ - ctx: CTX, + ctx: ctx, req: &user.VerifyTOTPRegistrationRequest{ UserId: userID, Code: code, @@ -138,7 +140,6 @@ func TestServer_VerifyTOTPRegistration(t *testing.T) { }, }, }, - */ } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/api/grpc/user/v2/u2f_integration_test.go b/internal/api/grpc/user/v2/u2f_integration_test.go index febe0ddfb1..77653f8789 100644 --- a/internal/api/grpc/user/v2/u2f_integration_test.go +++ b/internal/api/grpc/user/v2/u2f_integration_test.go @@ -11,12 +11,17 @@ import ( "google.golang.org/protobuf/types/known/structpb" "github.com/zitadel/zitadel/internal/integration" + object "github.com/zitadel/zitadel/pkg/grpc/object/v2beta" user "github.com/zitadel/zitadel/pkg/grpc/user/v2beta" ) func TestServer_RegisterU2F(t *testing.T) { userID := Tester.CreateHumanUser(CTX).GetUserId() + // We also need a user session + Tester.RegisterUserPasskey(CTX, userID) + _, sessionToken, _, _ := Tester.CreateVerifiedWebAuthNSession(t, CTX, userID) + type args struct { ctx context.Context req *user.RegisterU2FRequest @@ -45,12 +50,10 @@ func TestServer_RegisterU2F(t *testing.T) { }, wantErr: true, }, - /* TODO: after we are able to obtain a Bearer token for a human user - https://github.com/zitadel/zitadel/issues/6022 { - name: "human user", + name: "user setting its own passkey", args: args{ - ctx: CTX, + ctx: Tester.WithAuthorizationToken(CTX, sessionToken), req: &user.RegisterU2FRequest{ UserId: userID, }, @@ -61,7 +64,6 @@ func TestServer_RegisterU2F(t *testing.T) { }, }, }, - */ } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -85,8 +87,11 @@ func TestServer_RegisterU2F(t *testing.T) { func TestServer_VerifyU2FRegistration(t *testing.T) { userID := Tester.CreateHumanUser(CTX).GetUserId() - /* TODO after we are able to obtain a Bearer token for a human user - pkr, err := Client.RegisterU2F(CTX, &user.RegisterU2FRequest{ + Tester.RegisterUserPasskey(CTX, userID) + _, sessionToken, _, _ := Tester.CreateVerifiedWebAuthNSession(t, CTX, userID) + ctx := Tester.WithAuthorizationToken(CTX, sessionToken) + + pkr, err := Client.RegisterU2F(ctx, &user.RegisterU2FRequest{ UserId: userID, }) require.NoError(t, err) @@ -94,7 +99,6 @@ func TestServer_VerifyU2FRegistration(t *testing.T) { attestationResponse, err := Tester.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions()) require.NoError(t, err) - */ type args struct { ctx context.Context @@ -109,7 +113,7 @@ func TestServer_VerifyU2FRegistration(t *testing.T) { { name: "missing user id", args: args{ - ctx: CTX, + ctx: ctx, req: &user.VerifyU2FRegistrationRequest{ U2FId: "123", TokenName: "nice name", @@ -117,11 +121,10 @@ func TestServer_VerifyU2FRegistration(t *testing.T) { }, wantErr: true, }, - /* TODO after we are able to obtain a Bearer token for a human user { name: "success", args: args{ - ctx: CTX, + ctx: ctx, req: &user.VerifyU2FRegistrationRequest{ UserId: userID, U2FId: pkr.GetU2FId(), @@ -135,11 +138,10 @@ func TestServer_VerifyU2FRegistration(t *testing.T) { }, }, }, - */ { name: "wrong credential", args: args{ - ctx: CTX, + ctx: ctx, req: &user.VerifyU2FRegistrationRequest{ UserId: userID, U2FId: "123",