2023-04-28 11:39:53 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package user_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-05-24 18:29:58 +00:00
|
|
|
"strings"
|
2023-04-28 11:39:53 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/muhlemmer/gu"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-20 12:39:50 +00:00
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
2023-05-24 18:29:58 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
|
2023-06-20 12:39:50 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc"
|
2023-04-28 11:39:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2023-06-20 16:23:28 +00:00
|
|
|
mgmt "github.com/zitadel/zitadel/pkg/grpc/management"
|
2023-09-13 12:43:01 +00:00
|
|
|
object "github.com/zitadel/zitadel/pkg/grpc/object/v2beta"
|
|
|
|
user "github.com/zitadel/zitadel/pkg/grpc/user/v2beta"
|
2023-04-28 11:39:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
CTX context.Context
|
|
|
|
ErrCTX context.Context
|
|
|
|
Tester *integration.Tester
|
|
|
|
Client user.UserServiceClient
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(func() int {
|
|
|
|
ctx, errCtx, cancel := integration.Contexts(time.Hour)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
Tester = integration.NewTester(ctx)
|
|
|
|
defer Tester.Done()
|
|
|
|
|
2023-07-06 06:38:13 +00:00
|
|
|
CTX, ErrCTX = Tester.WithAuthorization(ctx, integration.OrgOwner), errCtx
|
2023-06-07 15:28:42 +00:00
|
|
|
Client = Tester.Client.UserV2
|
2023-04-28 11:39:53 +00:00
|
|
|
return m.Run()
|
|
|
|
}())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_AddHumanUser(t *testing.T) {
|
2023-06-21 14:06:18 +00:00
|
|
|
idpID := Tester.AddGenericOAuthProvider(t)
|
2023-04-28 11:39:53 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.AddHumanUserRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.AddHumanUserResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "default verification",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
2023-05-02 16:24:24 +00:00
|
|
|
OrgId: Tester.Organisation.ID,
|
2023-04-28 11:39:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-04-28 11:39:53 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{},
|
2023-08-03 04:42:59 +00:00
|
|
|
Phone: &user.SetHumanPhone{},
|
2023-04-28 11:39:53 +00:00
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddHumanUserResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-08-03 04:42:59 +00:00
|
|
|
name: "return email verification code",
|
2023-04-28 11:39:53 +00:00
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
2023-05-02 16:24:24 +00:00
|
|
|
OrgId: Tester.Organisation.ID,
|
2023-04-28 11:39:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-04-28 11:39:53 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Verification: &user.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnEmailVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddHumanUserResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
EmailCode: gu.Ptr("something"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "custom template",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
2023-05-02 16:24:24 +00:00
|
|
|
OrgId: Tester.Organisation.ID,
|
2023-04-28 11:39:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-04-28 11:39:53 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Verification: &user.SetHumanEmail_SendCode{
|
|
|
|
SendCode: &user.SendEmailVerificationCode{
|
|
|
|
UrlTemplate: gu.Ptr("https://example.com/email/verify?userID={{.UserID}}&code={{.Code}}&orgID={{.OrgID}}"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddHumanUserResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-03 04:42:59 +00:00
|
|
|
{
|
|
|
|
name: "return phone verification code",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
|
|
|
OrgId: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-08-03 04:42:59 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{},
|
|
|
|
Phone: &user.SetHumanPhone{
|
|
|
|
Phone: "+41791234567",
|
|
|
|
Verification: &user.SetHumanPhone_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnPhoneVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddHumanUserResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
PhoneCode: gu.Ptr("something"),
|
|
|
|
},
|
|
|
|
},
|
2023-04-28 11:39:53 +00:00
|
|
|
{
|
|
|
|
name: "custom template error",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
2023-05-02 16:24:24 +00:00
|
|
|
OrgId: Tester.Organisation.ID,
|
2023-04-28 11:39:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-04-28 11:39:53 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Verification: &user.SetHumanEmail_SendCode{
|
|
|
|
SendCode: &user.SendEmailVerificationCode{
|
|
|
|
UrlTemplate: gu.Ptr("{{"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing REQUIRED profile",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
2023-05-02 16:24:24 +00:00
|
|
|
OrgId: Tester.Organisation.ID,
|
2023-04-28 11:39:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Verification: &user.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnEmailVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing REQUIRED email",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
2023-05-02 16:24:24 +00:00
|
|
|
OrgId: Tester.Organisation.ID,
|
2023-04-28 11:39:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-04-28 11:39:53 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2023-05-24 18:29:58 +00:00
|
|
|
{
|
|
|
|
name: "missing idp",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
|
|
|
OrgId: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-05-24 18:29:58 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: "livio@zitadel.com",
|
|
|
|
Verification: &user.SetHumanEmail_IsVerified{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IdpLinks: []*user.IDPLink{
|
|
|
|
{
|
2023-06-20 12:39:50 +00:00
|
|
|
IdpId: "idpID",
|
|
|
|
UserId: "userID",
|
|
|
|
UserName: "username",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "with idp",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
|
|
|
OrgId: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-05-24 18:29:58 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: "livio@zitadel.com",
|
|
|
|
Verification: &user.SetHumanEmail_IsVerified{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_Password{
|
|
|
|
Password: &user.Password{
|
|
|
|
Password: "DifficultPW666!",
|
|
|
|
ChangeRequired: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IdpLinks: []*user.IDPLink{
|
|
|
|
{
|
2023-06-20 12:39:50 +00:00
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "userID",
|
|
|
|
UserName: "username",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddHumanUserResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-07-14 06:49:57 +00:00
|
|
|
{
|
|
|
|
name: "hashed password",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
|
|
|
OrgId: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-07-14 06:49:57 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_HashedPassword{
|
|
|
|
HashedPassword: &user.HashedPassword{
|
|
|
|
Hash: "$2y$12$hXUrnqdq1RIIYZ2HPytIIe5lXdIvbhqrTvdPsSF7o.jFh817Z6lwm",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddHumanUserResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unsupported hashed password",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddHumanUserRequest{
|
|
|
|
Organisation: &object.Organisation{
|
|
|
|
Org: &object.Organisation_OrgId{
|
|
|
|
OrgId: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-08-22 10:05:45 +00:00
|
|
|
GivenName: "Donald",
|
|
|
|
FamilyName: "Duck",
|
2023-07-14 06:49:57 +00:00
|
|
|
NickName: gu.Ptr("Dukkie"),
|
|
|
|
DisplayName: gu.Ptr("Donald Duck"),
|
|
|
|
PreferredLanguage: gu.Ptr("en"),
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{},
|
|
|
|
Metadata: []*user.SetMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "somekey",
|
|
|
|
Value: []byte("somevalue"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PasswordType: &user.AddHumanUserRequest_HashedPassword{
|
|
|
|
HashedPassword: &user.HashedPassword{
|
|
|
|
Hash: "$scrypt$ln=16,r=8,p=1$cmFuZG9tc2FsdGlzaGFyZA$Rh+NnJNo1I6nRwaNqbDm6kmADswD1+7FTKZ7Ln9D8nQ",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2023-04-28 11:39:53 +00:00
|
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
userID := fmt.Sprint(time.Now().UnixNano() + int64(i))
|
|
|
|
tt.args.req.UserId = &userID
|
|
|
|
if email := tt.args.req.GetEmail(); email != nil {
|
|
|
|
email.Email = fmt.Sprintf("%s@me.now", userID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tt.want != nil {
|
|
|
|
tt.want.UserId = userID
|
|
|
|
}
|
|
|
|
|
|
|
|
got, err := Client.AddHumanUser(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, tt.want.GetUserId(), got.GetUserId())
|
|
|
|
if tt.want.GetEmailCode() != "" {
|
|
|
|
assert.NotEmpty(t, got.GetEmailCode())
|
|
|
|
}
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-05-24 18:29:58 +00:00
|
|
|
|
|
|
|
func TestServer_AddIDPLink(t *testing.T) {
|
2023-06-21 14:06:18 +00:00
|
|
|
idpID := Tester.AddGenericOAuthProvider(t)
|
2023-05-24 18:29:58 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.AddIDPLinkRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.AddIDPLinkResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "user does not exist",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddIDPLinkRequest{
|
|
|
|
UserId: "userID",
|
|
|
|
IdpLink: &user.IDPLink{
|
2023-06-20 12:39:50 +00:00
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "userID",
|
|
|
|
UserName: "username",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: nil,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "idp does not exist",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddIDPLinkRequest{
|
2023-07-06 06:38:13 +00:00
|
|
|
UserId: Tester.Users[integration.FirstInstanceUsersKey][integration.OrgOwner].ID,
|
2023-05-24 18:29:58 +00:00
|
|
|
IdpLink: &user.IDPLink{
|
2023-06-20 12:39:50 +00:00
|
|
|
IdpId: "idpID",
|
|
|
|
UserId: "userID",
|
|
|
|
UserName: "username",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: nil,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add link",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.AddIDPLinkRequest{
|
2023-07-06 06:38:13 +00:00
|
|
|
UserId: Tester.Users[integration.FirstInstanceUsersKey][integration.OrgOwner].ID,
|
2023-05-24 18:29:58 +00:00
|
|
|
IdpLink: &user.IDPLink{
|
2023-06-20 12:39:50 +00:00
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "userID",
|
|
|
|
UserName: "username",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.AddIDPLinkResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := Client.AddIDPLink(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 10:05:45 +00:00
|
|
|
func TestServer_StartIdentityProviderIntent(t *testing.T) {
|
2023-06-21 14:06:18 +00:00
|
|
|
idpID := Tester.AddGenericOAuthProvider(t)
|
2023-05-24 18:29:58 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
2023-08-22 10:05:45 +00:00
|
|
|
req *user.StartIdentityProviderIntentRequest
|
2023-05-24 18:29:58 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2023-08-22 10:05:45 +00:00
|
|
|
want *user.StartIdentityProviderIntentResponse
|
2023-05-24 18:29:58 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing urls",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
2023-08-22 10:05:45 +00:00
|
|
|
&user.StartIdentityProviderIntentRequest{
|
2023-05-24 18:29:58 +00:00
|
|
|
IdpId: idpID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: nil,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "next step auth url",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
2023-08-22 10:05:45 +00:00
|
|
|
&user.StartIdentityProviderIntentRequest{
|
2023-08-16 11:29:57 +00:00
|
|
|
IdpId: idpID,
|
2023-08-22 10:05:45 +00:00
|
|
|
Content: &user.StartIdentityProviderIntentRequest_Urls{
|
2023-08-16 11:29:57 +00:00
|
|
|
Urls: &user.RedirectURLs{
|
|
|
|
SuccessUrl: "https://example.com/success",
|
|
|
|
FailureUrl: "https://example.com/failure",
|
|
|
|
},
|
|
|
|
},
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
2023-08-22 10:05:45 +00:00
|
|
|
want: &user.StartIdentityProviderIntentResponse{
|
2023-05-24 18:29:58 +00:00
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
},
|
2023-08-22 10:05:45 +00:00
|
|
|
NextStep: &user.StartIdentityProviderIntentResponse_AuthUrl{
|
2023-07-10 13:27:00 +00:00
|
|
|
AuthUrl: "https://example.com/oauth/v2/authorize?client_id=clientID&prompt=select_account&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fidps%2Fcallback&response_type=code&scope=openid+profile+email&state=",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-08-22 10:05:45 +00:00
|
|
|
got, err := Client.StartIdentityProviderIntent(tt.args.ctx, tt.args.req)
|
2023-05-24 18:29:58 +00:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nextStep := tt.want.GetNextStep(); nextStep != nil {
|
|
|
|
if !strings.HasPrefix(got.GetAuthUrl(), tt.want.GetAuthUrl()) {
|
|
|
|
assert.Failf(t, "auth url does not match", "expected: %s, but got: %s", tt.want.GetAuthUrl(), got.GetAuthUrl())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 10:05:45 +00:00
|
|
|
func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
2023-06-21 14:06:18 +00:00
|
|
|
idpID := Tester.AddGenericOAuthProvider(t)
|
|
|
|
intentID := Tester.CreateIntent(t, idpID)
|
2023-08-16 11:29:57 +00:00
|
|
|
successfulID, token, changeDate, sequence := Tester.CreateSuccessfulOAuthIntent(t, idpID, "", "id")
|
2023-09-25 05:21:50 +00:00
|
|
|
successfulWithUserID, WithUsertoken, WithUserchangeDate, WithUsersequence := Tester.CreateSuccessfulOAuthIntent(t, idpID, "user", "id")
|
2023-08-16 11:29:57 +00:00
|
|
|
ldapSuccessfulID, ldapToken, ldapChangeDate, ldapSequence := Tester.CreateSuccessfulLDAPIntent(t, idpID, "", "id")
|
2023-09-25 05:21:50 +00:00
|
|
|
ldapSuccessfulWithUserID, ldapWithUserToken, ldapWithUserChangeDate, ldapWithUserSequence := Tester.CreateSuccessfulLDAPIntent(t, idpID, "user", "id")
|
2023-05-24 18:29:58 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
2023-08-22 10:05:45 +00:00
|
|
|
req *user.RetrieveIdentityProviderIntentRequest
|
2023-05-24 18:29:58 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2023-08-22 10:05:45 +00:00
|
|
|
want *user.RetrieveIdentityProviderIntentResponse
|
2023-05-24 18:29:58 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "failed intent",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
2023-08-22 10:05:45 +00:00
|
|
|
&user.RetrieveIdentityProviderIntentRequest{
|
|
|
|
IdpIntentId: intentID,
|
|
|
|
IdpIntentToken: "",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "wrong token",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
2023-08-22 10:05:45 +00:00
|
|
|
&user.RetrieveIdentityProviderIntentRequest{
|
|
|
|
IdpIntentId: successfulID,
|
|
|
|
IdpIntentToken: "wrong token",
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "retrieve successful intent",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
2023-08-22 10:05:45 +00:00
|
|
|
&user.RetrieveIdentityProviderIntentRequest{
|
|
|
|
IdpIntentId: successfulID,
|
|
|
|
IdpIntentToken: token,
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
2023-08-22 10:05:45 +00:00
|
|
|
want: &user.RetrieveIdentityProviderIntentResponse{
|
2023-05-24 18:29:58 +00:00
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.New(changeDate),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
Sequence: sequence,
|
|
|
|
},
|
|
|
|
IdpInformation: &user.IDPInformation{
|
|
|
|
Access: &user.IDPInformation_Oauth{
|
|
|
|
Oauth: &user.IDPOAuthAccessInformation{
|
|
|
|
AccessToken: "accessToken",
|
|
|
|
IdToken: gu.Ptr("idToken"),
|
|
|
|
},
|
|
|
|
},
|
2023-06-20 12:39:50 +00:00
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "id",
|
|
|
|
UserName: "username",
|
|
|
|
RawInformation: func() *structpb.Struct {
|
|
|
|
s, err := structpb.NewStruct(map[string]interface{}{
|
|
|
|
"sub": "id",
|
|
|
|
"preferred_username": "username",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return s
|
|
|
|
}(),
|
2023-05-24 18:29:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2023-09-25 05:21:50 +00:00
|
|
|
{
|
|
|
|
name: "retrieve successful intent with linked user",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.RetrieveIdentityProviderIntentRequest{
|
|
|
|
IdpIntentId: successfulWithUserID,
|
|
|
|
IdpIntentToken: WithUsertoken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.RetrieveIdentityProviderIntentResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.New(WithUserchangeDate),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
Sequence: WithUsersequence,
|
|
|
|
},
|
|
|
|
UserId: "user",
|
|
|
|
IdpInformation: &user.IDPInformation{
|
|
|
|
Access: &user.IDPInformation_Oauth{
|
|
|
|
Oauth: &user.IDPOAuthAccessInformation{
|
|
|
|
AccessToken: "accessToken",
|
|
|
|
IdToken: gu.Ptr("idToken"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "id",
|
|
|
|
UserName: "username",
|
|
|
|
RawInformation: func() *structpb.Struct {
|
|
|
|
s, err := structpb.NewStruct(map[string]interface{}{
|
|
|
|
"sub": "id",
|
|
|
|
"preferred_username": "username",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return s
|
|
|
|
}(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2023-08-16 11:29:57 +00:00
|
|
|
{
|
|
|
|
name: "retrieve successful ldap intent",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
2023-08-22 10:05:45 +00:00
|
|
|
&user.RetrieveIdentityProviderIntentRequest{
|
|
|
|
IdpIntentId: ldapSuccessfulID,
|
|
|
|
IdpIntentToken: ldapToken,
|
2023-08-16 11:29:57 +00:00
|
|
|
},
|
|
|
|
},
|
2023-08-22 10:05:45 +00:00
|
|
|
want: &user.RetrieveIdentityProviderIntentResponse{
|
2023-08-16 11:29:57 +00:00
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.New(ldapChangeDate),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
Sequence: ldapSequence,
|
|
|
|
},
|
|
|
|
IdpInformation: &user.IDPInformation{
|
2023-09-25 05:21:50 +00:00
|
|
|
Access: &user.IDPInformation_Ldap{
|
|
|
|
Ldap: &user.IDPLDAPAccessInformation{
|
|
|
|
Attributes: func() *structpb.Struct {
|
|
|
|
s, err := structpb.NewStruct(map[string]interface{}{
|
|
|
|
"id": []interface{}{"id"},
|
|
|
|
"username": []interface{}{"username"},
|
|
|
|
"language": []interface{}{"en"},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return s
|
|
|
|
}(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "id",
|
|
|
|
UserName: "username",
|
|
|
|
RawInformation: func() *structpb.Struct {
|
|
|
|
s, err := structpb.NewStruct(map[string]interface{}{
|
|
|
|
"id": "id",
|
|
|
|
"preferredUsername": "username",
|
|
|
|
"preferredLanguage": "en",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return s
|
|
|
|
}(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "retrieve successful ldap intent with linked user",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.RetrieveIdentityProviderIntentRequest{
|
|
|
|
IdpIntentId: ldapSuccessfulWithUserID,
|
|
|
|
IdpIntentToken: ldapWithUserToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.RetrieveIdentityProviderIntentResponse{
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.New(ldapWithUserChangeDate),
|
|
|
|
ResourceOwner: Tester.Organisation.ID,
|
|
|
|
Sequence: ldapWithUserSequence,
|
|
|
|
},
|
|
|
|
UserId: "user",
|
|
|
|
IdpInformation: &user.IDPInformation{
|
2023-08-16 11:29:57 +00:00
|
|
|
Access: &user.IDPInformation_Ldap{
|
|
|
|
Ldap: &user.IDPLDAPAccessInformation{
|
|
|
|
Attributes: func() *structpb.Struct {
|
|
|
|
s, err := structpb.NewStruct(map[string]interface{}{
|
|
|
|
"id": []interface{}{"id"},
|
|
|
|
"username": []interface{}{"username"},
|
|
|
|
"language": []interface{}{"en"},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return s
|
|
|
|
}(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IdpId: idpID,
|
|
|
|
UserId: "id",
|
|
|
|
UserName: "username",
|
|
|
|
RawInformation: func() *structpb.Struct {
|
|
|
|
s, err := structpb.NewStruct(map[string]interface{}{
|
|
|
|
"id": "id",
|
|
|
|
"preferredUsername": "username",
|
|
|
|
"preferredLanguage": "en",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return s
|
|
|
|
}(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2023-05-24 18:29:58 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-08-22 10:05:45 +00:00
|
|
|
got, err := Client.RetrieveIdentityProviderIntent(tt.args.ctx, tt.args.req)
|
2023-05-24 18:29:58 +00:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2023-08-16 11:29:57 +00:00
|
|
|
grpc.AllFieldsEqual(t, tt.want.ProtoReflect(), got.ProtoReflect(), grpc.CustomMappers)
|
2023-05-24 18:29:58 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 16:23:28 +00:00
|
|
|
|
|
|
|
func TestServer_ListAuthenticationMethodTypes(t *testing.T) {
|
|
|
|
userIDWithoutAuth := Tester.CreateHumanUser(CTX).GetUserId()
|
|
|
|
|
|
|
|
userIDWithPasskey := Tester.CreateHumanUser(CTX).GetUserId()
|
|
|
|
Tester.RegisterUserPasskey(CTX, userIDWithPasskey)
|
|
|
|
|
|
|
|
userMultipleAuth := Tester.CreateHumanUser(CTX).GetUserId()
|
|
|
|
Tester.RegisterUserPasskey(CTX, userMultipleAuth)
|
|
|
|
provider, err := Tester.Client.Mgmt.AddGenericOIDCProvider(CTX, &mgmt.AddGenericOIDCProviderRequest{
|
|
|
|
Name: "ListAuthenticationMethodTypes",
|
|
|
|
Issuer: "https://example.com",
|
|
|
|
ClientId: "client_id",
|
|
|
|
ClientSecret: "client_secret",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
idpLink, err := Tester.Client.UserV2.AddIDPLink(CTX, &user.AddIDPLinkRequest{UserId: userMultipleAuth, IdpLink: &user.IDPLink{
|
|
|
|
IdpId: provider.GetId(),
|
|
|
|
UserId: "external-id",
|
|
|
|
UserName: "displayName",
|
|
|
|
}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.ListAuthenticationMethodTypesRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.ListAuthenticationMethodTypesResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no auth",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.ListAuthenticationMethodTypesRequest{
|
|
|
|
UserId: userIDWithoutAuth,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListAuthenticationMethodTypesResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "with auth (passkey)",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.ListAuthenticationMethodTypesRequest{
|
|
|
|
UserId: userIDWithPasskey,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListAuthenticationMethodTypesResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
},
|
|
|
|
AuthMethodTypes: []user.AuthenticationMethodType{
|
|
|
|
user.AuthenticationMethodType_AUTHENTICATION_METHOD_TYPE_PASSKEY,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple auth",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.ListAuthenticationMethodTypesRequest{
|
|
|
|
UserId: userMultipleAuth,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListAuthenticationMethodTypesResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 2,
|
|
|
|
},
|
|
|
|
AuthMethodTypes: []user.AuthenticationMethodType{
|
|
|
|
user.AuthenticationMethodType_AUTHENTICATION_METHOD_TYPE_PASSKEY,
|
|
|
|
user.AuthenticationMethodType_AUTHENTICATION_METHOD_TYPE_IDP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
var got *user.ListAuthenticationMethodTypesResponse
|
|
|
|
var err error
|
|
|
|
|
|
|
|
for {
|
|
|
|
got, err = Client.ListAuthenticationMethodTypes(tt.args.ctx, tt.args.req)
|
|
|
|
if err == nil && got.GetDetails().GetProcessedSequence() >= idpLink.GetDetails().GetSequence() {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-CTX.Done():
|
|
|
|
t.Fatal(CTX.Err(), err)
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
t.Log("retrying ListAuthenticationMethodTypes")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.want.GetDetails().GetTotalResult(), got.GetDetails().GetTotalResult())
|
|
|
|
require.Equal(t, tt.want.GetAuthMethodTypes(), got.GetAuthMethodTypes())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|