2024-01-17 10:00:10 +01:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package user_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-02-24 16:29:51 +00:00
|
|
|
"errors"
|
2024-01-17 10:00:10 +01:00
|
|
|
"fmt"
|
2025-01-02 15:44:15 +05:30
|
|
|
"slices"
|
2024-01-17 10:00:10 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-10-17 23:20:57 +02:00
|
|
|
"github.com/brianvoe/gofakeit/v6"
|
2024-01-17 10:00:10 +01:00
|
|
|
"github.com/muhlemmer/gu"
|
2024-03-28 07:21:21 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-01-17 10:00:10 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
|
2024-09-06 15:47:57 +03:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2025-02-24 16:29:51 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/feature/v2"
|
2024-08-15 06:37:06 +02:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
2025-02-20 15:39:48 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/session/v2"
|
2024-08-15 06:37:06 +02:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
2024-01-17 10:00:10 +01:00
|
|
|
)
|
|
|
|
|
2025-02-24 16:29:51 +00:00
|
|
|
var (
|
|
|
|
permissionCheckV2SetFlagInital bool
|
|
|
|
permissionCheckV2SetFlag bool
|
|
|
|
)
|
|
|
|
|
|
|
|
type permissionCheckV2SettingsStruct struct {
|
|
|
|
TestNamePrependString string
|
|
|
|
SetFlag bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var permissionCheckV2Settings []permissionCheckV2SettingsStruct = []permissionCheckV2SettingsStruct{
|
|
|
|
{
|
|
|
|
SetFlag: false,
|
|
|
|
TestNamePrependString: "permission_check_v2 IS NOT SET" + " ",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SetFlag: true,
|
|
|
|
TestNamePrependString: "permission_check_v2 IS SET" + " ",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func setPermissionCheckV2Flag(t *testing.T, setFlag bool) {
|
|
|
|
if permissionCheckV2SetFlagInital && permissionCheckV2SetFlag == setFlag {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := Instance.Client.FeatureV2.SetInstanceFeatures(IamCTX, &feature.SetInstanceFeaturesRequest{
|
|
|
|
PermissionCheckV2: &setFlag,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var flagSet bool
|
|
|
|
for i := 0; !flagSet || i < 6; i++ {
|
|
|
|
res, err := Instance.Client.FeatureV2.GetInstanceFeatures(IamCTX, &feature.GetInstanceFeaturesRequest{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
if res.PermissionCheckV2.Enabled == setFlag {
|
|
|
|
flagSet = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !flagSet {
|
|
|
|
require.NoError(t, errors.New("unable to set permission_check_v2 flag"))
|
|
|
|
}
|
|
|
|
permissionCheckV2SetFlagInital = true
|
|
|
|
permissionCheckV2SetFlag = setFlag
|
|
|
|
}
|
|
|
|
|
2024-01-17 10:00:10 +01:00
|
|
|
func TestServer_GetUserByID(t *testing.T) {
|
2024-10-17 23:20:57 +02:00
|
|
|
orgResp := Instance.CreateOrganization(IamCTX, fmt.Sprintf("GetUserByIDOrg-%s", gofakeit.AppName()), gofakeit.Email())
|
2024-01-17 10:00:10 +01:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.GetUserByIDRequest
|
2025-01-02 15:44:15 +05:30
|
|
|
dep func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.GetUserByIDResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "user by ID, no id provided",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
UserId: "",
|
|
|
|
},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
return nil
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user by ID, not found",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
UserId: "unknown",
|
|
|
|
},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
return nil
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user by ID, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2024-03-21 09:07:00 +01:00
|
|
|
&user.GetUserByIDRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
|
|
|
request.UserId = info.UserID
|
|
|
|
return &info
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.GetUserByIDResponse{
|
|
|
|
User: &user.User{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Username: "",
|
|
|
|
LoginNames: nil,
|
|
|
|
PreferredLoginName: "",
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
AvatarUrl: "",
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2025-02-26 14:00:04 +01:00
|
|
|
CreationDate: timestamppb.Now(),
|
2024-01-17 10:00:10 +01:00
|
|
|
ResourceOwner: orgResp.OrganizationId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-28 07:21:21 +01:00
|
|
|
{
|
|
|
|
name: "user by ID, passwordChangeRequired, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.GetUserByIDRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, true)
|
|
|
|
request.UserId = info.UserID
|
|
|
|
return &info
|
2024-03-28 07:21:21 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.GetUserByIDResponse{
|
|
|
|
User: &user.User{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Username: "",
|
|
|
|
LoginNames: nil,
|
|
|
|
PreferredLoginName: "",
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
AvatarUrl: "",
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
PasswordChangeRequired: true,
|
2024-06-18 13:27:44 +02:00
|
|
|
PasswordChanged: timestamppb.Now(),
|
2024-03-28 07:21:21 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Details: &object.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2025-02-26 14:00:04 +01:00
|
|
|
CreationDate: timestamppb.Now(),
|
2024-03-28 07:21:21 +01:00
|
|
|
ResourceOwner: orgResp.OrganizationId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2025-01-02 15:44:15 +05:30
|
|
|
userAttr := tt.args.dep(IamCTX, tt.args.req)
|
2024-10-17 23:20:57 +02:00
|
|
|
|
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.args.ctx, time.Minute)
|
2024-01-17 16:24:11 +01:00
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
2024-10-17 23:20:57 +02:00
|
|
|
got, err := Client.GetUserByID(tt.args.ctx, tt.args.req)
|
2024-01-17 16:24:11 +01:00
|
|
|
if tt.wantErr {
|
2024-10-21 21:15:02 +02:00
|
|
|
assert.Error(ttt, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !assert.NoError(ttt, err) {
|
2024-01-17 16:24:11 +01:00
|
|
|
return
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
2024-10-17 23:20:57 +02:00
|
|
|
|
2024-07-10 17:49:35 +02:00
|
|
|
tt.want.User.Details = userAttr.Details
|
|
|
|
tt.want.User.UserId = userAttr.UserID
|
|
|
|
tt.want.User.Username = userAttr.Username
|
|
|
|
tt.want.User.PreferredLoginName = userAttr.Username
|
|
|
|
tt.want.User.LoginNames = []string{userAttr.Username}
|
2024-01-17 10:00:10 +01:00
|
|
|
if human := tt.want.User.GetHuman(); human != nil {
|
2024-07-10 17:49:35 +02:00
|
|
|
human.Email.Email = userAttr.Username
|
2025-01-02 15:44:15 +05:30
|
|
|
human.Phone.Phone = userAttr.Phone
|
2024-06-18 13:27:44 +02:00
|
|
|
if tt.want.User.GetHuman().GetPasswordChanged() != nil {
|
2024-07-10 17:49:35 +02:00
|
|
|
human.PasswordChanged = userAttr.Changed
|
2024-06-18 13:27:44 +02:00
|
|
|
}
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
2025-01-02 15:44:15 +05:30
|
|
|
assert.EqualExportedValues(ttt, tt.want.User, got.User)
|
2024-09-06 15:47:57 +03:00
|
|
|
integration.AssertDetails(ttt, tt.want, got)
|
2024-10-17 23:20:57 +02:00
|
|
|
}, retryDuration, tick)
|
2024-01-17 10:00:10 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-08 09:37:23 +01:00
|
|
|
func TestServer_GetUserByID_Permission(t *testing.T) {
|
2024-10-17 23:20:57 +02:00
|
|
|
newOrgOwnerEmail := gofakeit.Email()
|
|
|
|
newOrg := Instance.CreateOrganization(IamCTX, fmt.Sprintf("GetHuman-%s", gofakeit.AppName()), newOrgOwnerEmail)
|
2024-03-08 09:37:23 +01:00
|
|
|
newUserID := newOrg.CreatedAdmins[0].GetUserId()
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *user.GetUserByIDRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.GetUserByIDResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "System, ok",
|
|
|
|
args: args{
|
|
|
|
SystemCTX,
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
UserId: newUserID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.GetUserByIDResponse{
|
|
|
|
User: &user.User{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Username: "",
|
|
|
|
LoginNames: nil,
|
|
|
|
PreferredLoginName: "",
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "firstname",
|
|
|
|
FamilyName: "lastname",
|
|
|
|
NickName: gu.Ptr(""),
|
|
|
|
DisplayName: gu.Ptr("firstname lastname"),
|
|
|
|
PreferredLanguage: gu.Ptr("und"),
|
|
|
|
Gender: user.Gender_GENDER_UNSPECIFIED.Enum(),
|
|
|
|
AvatarUrl: "",
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
Email: newOrgOwnerEmail,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Details: &object.Details{
|
2024-10-23 09:36:50 +02:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2025-02-26 14:00:04 +01:00
|
|
|
CreationDate: timestamppb.Now(),
|
2024-03-08 09:37:23 +01:00
|
|
|
ResourceOwner: newOrg.GetOrganizationId(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Instance, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
UserId: newUserID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.GetUserByIDResponse{
|
|
|
|
User: &user.User{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Username: "",
|
|
|
|
LoginNames: nil,
|
|
|
|
PreferredLoginName: "",
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "firstname",
|
|
|
|
FamilyName: "lastname",
|
|
|
|
NickName: gu.Ptr(""),
|
|
|
|
DisplayName: gu.Ptr("firstname lastname"),
|
|
|
|
PreferredLanguage: gu.Ptr("und"),
|
|
|
|
Gender: user.Gender_GENDER_UNSPECIFIED.Enum(),
|
|
|
|
AvatarUrl: "",
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
Email: newOrgOwnerEmail,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Details: &object.Details{
|
2024-10-23 09:36:50 +02:00
|
|
|
ChangeDate: timestamppb.Now(),
|
2025-02-26 14:00:04 +01:00
|
|
|
CreationDate: timestamppb.Now(),
|
2024-03-08 09:37:23 +01:00
|
|
|
ResourceOwner: newOrg.GetOrganizationId(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Org, error",
|
|
|
|
args: args{
|
|
|
|
CTX,
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
UserId: newUserID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "User, error",
|
|
|
|
args: args{
|
|
|
|
UserCTX,
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
UserId: newUserID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-10-23 09:36:50 +02:00
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.args.ctx, time.Minute)
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
got, err := Client.GetUserByID(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
assert.Error(ttt, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !assert.NoError(ttt, err) {
|
|
|
|
return
|
|
|
|
}
|
2024-07-10 17:49:35 +02:00
|
|
|
|
2024-10-23 09:36:50 +02:00
|
|
|
tt.want.User.UserId = tt.args.req.GetUserId()
|
|
|
|
tt.want.User.Username = newOrgOwnerEmail
|
|
|
|
tt.want.User.PreferredLoginName = newOrgOwnerEmail
|
|
|
|
tt.want.User.LoginNames = []string{newOrgOwnerEmail}
|
|
|
|
if human := tt.want.User.GetHuman(); human != nil {
|
|
|
|
human.Email.Email = newOrgOwnerEmail
|
|
|
|
}
|
|
|
|
// details tested in GetUserByID
|
|
|
|
tt.want.User.Details = got.User.GetDetails()
|
2024-10-17 23:20:57 +02:00
|
|
|
|
2024-10-23 09:36:50 +02:00
|
|
|
assert.Equal(ttt, tt.want.User, got.User)
|
|
|
|
}, retryDuration, tick, "timeout waiting for expected user result")
|
2024-03-08 09:37:23 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-02 15:44:15 +05:30
|
|
|
type userAttrs []userAttr
|
|
|
|
|
|
|
|
func (u userAttrs) userIDs() []string {
|
|
|
|
ids := make([]string, len(u))
|
|
|
|
for i := range u {
|
|
|
|
ids[i] = u[i].UserID
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u userAttrs) emails() []string {
|
|
|
|
emails := make([]string, len(u))
|
|
|
|
for i := range u {
|
|
|
|
emails[i] = u[i].Username
|
|
|
|
}
|
|
|
|
return emails
|
|
|
|
}
|
|
|
|
|
2024-01-17 10:00:10 +01:00
|
|
|
type userAttr struct {
|
|
|
|
UserID string
|
|
|
|
Username string
|
2025-01-02 15:44:15 +05:30
|
|
|
Phone string
|
2024-06-18 13:27:44 +02:00
|
|
|
Changed *timestamppb.Timestamp
|
2024-07-10 17:49:35 +02:00
|
|
|
Details *object.Details
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
|
|
|
|
2025-01-02 15:44:15 +05:30
|
|
|
func createUsers(ctx context.Context, orgID string, count int, passwordChangeRequired bool) userAttrs {
|
|
|
|
infos := make([]userAttr, count)
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
infos[i] = createUser(ctx, orgID, passwordChangeRequired)
|
|
|
|
}
|
|
|
|
slices.Reverse(infos)
|
|
|
|
return infos
|
|
|
|
}
|
|
|
|
|
|
|
|
func createUser(ctx context.Context, orgID string, passwordChangeRequired bool) userAttr {
|
|
|
|
username := gofakeit.Email()
|
|
|
|
// used as default country prefix
|
|
|
|
phone := "+41" + gofakeit.Phone()
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgID, username, phone)
|
|
|
|
info := userAttr{resp.GetUserId(), username, phone, nil, resp.GetDetails()}
|
2025-02-26 14:00:04 +01:00
|
|
|
// as the change date of the creation is the creation date
|
|
|
|
resp.Details.CreationDate = resp.GetDetails().GetChangeDate()
|
2025-01-02 15:44:15 +05:30
|
|
|
if passwordChangeRequired {
|
|
|
|
details := Instance.SetUserPassword(ctx, resp.GetUserId(), integration.UserPassword, true)
|
|
|
|
info.Changed = details.GetChangeDate()
|
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
2024-01-17 10:00:10 +01:00
|
|
|
func TestServer_ListUsers(t *testing.T) {
|
2025-02-24 16:29:51 +00:00
|
|
|
defer func() {
|
|
|
|
_, err := Instance.Client.FeatureV2.ResetInstanceFeatures(IamCTX, &feature.ResetInstanceFeaturesRequest{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}()
|
|
|
|
|
2024-10-17 23:20:57 +02:00
|
|
|
orgResp := Instance.CreateOrganization(IamCTX, fmt.Sprintf("ListUsersOrg-%s", gofakeit.AppName()), gofakeit.Email())
|
2024-01-17 10:00:10 +01:00
|
|
|
type args struct {
|
2025-01-02 15:44:15 +05:30
|
|
|
ctx context.Context
|
|
|
|
req *user.ListUsersRequest
|
|
|
|
dep func(ctx context.Context, request *user.ListUsersRequest) userAttrs
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *user.ListUsersResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
2025-02-20 15:39:48 +00:00
|
|
|
name: "list user by id, no permission machine user",
|
2024-01-17 10:00:10 +01:00
|
|
|
args: args{
|
|
|
|
UserCTX,
|
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery([]string{info.UserID}))
|
|
|
|
return []userAttr{}
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{},
|
|
|
|
},
|
|
|
|
},
|
2025-02-20 15:39:48 +00:00
|
|
|
{
|
|
|
|
name: "list user by id, no permission human user",
|
|
|
|
args: func() args {
|
|
|
|
info := createUser(IamCTX, orgResp.OrganizationId, true)
|
|
|
|
// create session to get token
|
|
|
|
userID := info.UserID
|
|
|
|
createResp, err := Instance.Client.SessionV2.CreateSession(IamCTX, &session.CreateSessionRequest{
|
|
|
|
Checks: &session.Checks{
|
|
|
|
User: &session.CheckUser{
|
|
|
|
Search: &session.CheckUser_UserId{UserId: userID},
|
|
|
|
},
|
|
|
|
Password: &session.CheckPassword{
|
|
|
|
Password: integration.UserPassword,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
// use token to get ctx
|
|
|
|
HumanCTX := integration.WithAuthorizationToken(IamCTX, createResp.GetSessionToken())
|
|
|
|
return args{
|
|
|
|
HumanCTX,
|
|
|
|
&user.ListUsersRequest{},
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
return []userAttr{info}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}(),
|
|
|
|
want: &user.ListUsersResponse{ // human user should return itself when calling ListUsers() even if it has no permissions
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
PasswordChanged: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
{
|
|
|
|
name: "list user by id, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery([]string{info.UserID}))
|
|
|
|
return []userAttr{info}
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-28 07:21:21 +01:00
|
|
|
{
|
|
|
|
name: "list user by id, passwordChangeRequired, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, true)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery([]string{info.UserID}))
|
|
|
|
return []userAttr{info}
|
2024-03-28 07:21:21 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
PasswordChangeRequired: true,
|
2024-06-18 13:27:44 +02:00
|
|
|
PasswordChanged: timestamppb.Now(),
|
2024-03-28 07:21:21 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
{
|
|
|
|
name: "list user by id multiple, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
infos := createUsers(ctx, orgResp.OrganizationId, 3, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery(infos.userIDs()))
|
|
|
|
return infos
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 3,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-01-02 15:44:15 +05:30
|
|
|
},
|
|
|
|
{
|
2024-01-17 10:00:10 +01:00
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-02-24 16:29:51 +00:00
|
|
|
},
|
|
|
|
{
|
2024-01-17 10:00:10 +01:00
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user by username, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, UsernameQuery(info.Username))
|
|
|
|
return []userAttr{info}
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user in emails, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery([]string{info.Username}))
|
|
|
|
return []userAttr{info}
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user in emails multiple, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
infos := createUsers(ctx, orgResp.OrganizationId, 3, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(infos.emails()))
|
|
|
|
return infos
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 3,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user in emails no found, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
InUserEmailsQuery([]string{"notfound"}),
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
return []userAttr{}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user phone, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, PhoneQuery(info.Phone))
|
|
|
|
return []userAttr{info}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user in emails no found, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
2025-02-24 16:29:51 +00:00
|
|
|
&user.ListUsersRequest{
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
InUserEmailsQuery([]string{"notfound"}),
|
|
|
|
},
|
2025-01-02 15:44:15 +05:30
|
|
|
},
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
return []userAttr{}
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{},
|
|
|
|
},
|
|
|
|
},
|
2024-03-21 09:07:00 +01:00
|
|
|
{
|
|
|
|
name: "list user resourceowner multiple, ok",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.ListUsersRequest{},
|
2025-01-02 15:44:15 +05:30
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
2024-10-17 23:20:57 +02:00
|
|
|
orgResp := Instance.CreateOrganization(ctx, fmt.Sprintf("ListUsersResourceowner-%s", gofakeit.AppName()), gofakeit.Email())
|
2024-03-21 09:07:00 +01:00
|
|
|
|
2025-01-02 15:44:15 +05:30
|
|
|
infos := createUsers(ctx, orgResp.OrganizationId, 3, false)
|
2025-02-24 16:29:51 +00:00
|
|
|
request.Queries = []*user.SearchQuery{}
|
2024-03-21 09:07:00 +01:00
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
2025-01-02 15:44:15 +05:30
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(infos.emails()))
|
|
|
|
return infos
|
2024-03-21 09:07:00 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 3,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-02-24 16:29:51 +00:00
|
|
|
{
|
|
|
|
name: "list user with org query",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.ListUsersRequest{},
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
orgRespForOrgTests := Instance.CreateOrganization(IamCTX, fmt.Sprintf("GetUserByIDOrg-%s", gofakeit.AppName()), gofakeit.Email())
|
|
|
|
info := createUser(ctx, orgRespForOrgTests.OrganizationId, false)
|
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgRespForOrgTests.OrganizationId))
|
|
|
|
return []userAttr{info, {}}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 2,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
{
|
|
|
|
State: user.UserState_USER_STATE_ACTIVE,
|
|
|
|
Type: &user.User_Human{
|
|
|
|
Human: &user.HumanUser{
|
|
|
|
Profile: &user.HumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
DisplayName: gu.Ptr("Mickey Mouse"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: user.Gender_GENDER_MALE.Enum(),
|
|
|
|
},
|
|
|
|
Email: &user.HumanEmail{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// this is the admin of the org craated in Instance.CreateOrganization()
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list user with wrong org query",
|
|
|
|
args: args{
|
|
|
|
IamCTX,
|
|
|
|
&user.ListUsersRequest{},
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
orgRespForOrgTests := Instance.CreateOrganization(IamCTX, fmt.Sprintf("GetUserByIDOrg-%s", gofakeit.AppName()), gofakeit.Email())
|
|
|
|
orgRespForOrgTests2 := Instance.CreateOrganization(IamCTX, fmt.Sprintf("GetUserByIDOrg-%s", gofakeit.AppName()), gofakeit.Email())
|
|
|
|
// info := createUser(ctx, orgRespForOrgTests.OrganizationId, false)
|
|
|
|
createUser(ctx, orgRespForOrgTests.OrganizationId, false)
|
|
|
|
request.Queries = []*user.SearchQuery{}
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgRespForOrgTests2.OrganizationId))
|
|
|
|
return []userAttr{{}}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
Timestamp: timestamppb.Now(),
|
|
|
|
},
|
|
|
|
SortingColumn: 0,
|
|
|
|
Result: []*user.User{
|
|
|
|
// this is the admin of the org craated in Instance.CreateOrganization()
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
2025-02-24 16:29:51 +00:00
|
|
|
for _, f := range permissionCheckV2Settings {
|
|
|
|
f := f
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(f.TestNamePrependString+tt.name, func(t *testing.T) {
|
|
|
|
setPermissionCheckV2Flag(t, f.SetFlag)
|
|
|
|
infos := tt.args.dep(IamCTX, tt.args.req)
|
2024-10-17 23:20:57 +02:00
|
|
|
|
2025-02-24 16:29:51 +00:00
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.args.ctx, 10*time.Minute)
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
got, err := Client.ListUsers(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(ttt, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(ttt, err)
|
2024-10-17 23:20:57 +02:00
|
|
|
|
2025-02-24 16:29:51 +00:00
|
|
|
// always only give back dependency infos which are required for the response
|
|
|
|
require.Len(ttt, tt.want.Result, len(infos))
|
|
|
|
if assert.Len(ttt, got.Result, len(tt.want.Result)) {
|
|
|
|
tt.want.Details.TotalResult = got.Details.TotalResult
|
2024-08-15 06:37:06 +02:00
|
|
|
|
2025-02-24 16:29:51 +00:00
|
|
|
// fill in userid and username as it is generated
|
|
|
|
for i := range infos {
|
|
|
|
if tt.want.Result[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
tt.want.Result[i].UserId = infos[i].UserID
|
|
|
|
tt.want.Result[i].Username = infos[i].Username
|
|
|
|
tt.want.Result[i].PreferredLoginName = infos[i].Username
|
|
|
|
tt.want.Result[i].LoginNames = []string{infos[i].Username}
|
|
|
|
if human := tt.want.Result[i].GetHuman(); human != nil {
|
|
|
|
human.Email.Email = infos[i].Username
|
|
|
|
human.Phone.Phone = infos[i].Phone
|
|
|
|
if tt.want.Result[i].GetHuman().GetPasswordChanged() != nil {
|
|
|
|
human.PasswordChanged = infos[i].Changed
|
|
|
|
}
|
2024-10-21 21:15:02 +02:00
|
|
|
}
|
2025-02-24 16:29:51 +00:00
|
|
|
tt.want.Result[i].Details = infos[i].Details
|
|
|
|
}
|
|
|
|
for i := range tt.want.Result {
|
|
|
|
if tt.want.Result[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
assert.EqualExportedValues(ttt, got.Result[i], tt.want.Result[i])
|
2024-06-18 13:27:44 +02:00
|
|
|
}
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
2025-02-24 16:29:51 +00:00
|
|
|
integration.AssertListDetails(ttt, tt.want, got)
|
|
|
|
}, retryDuration, tick, "timeout waiting for expected user result")
|
|
|
|
})
|
|
|
|
}
|
2024-01-17 10:00:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InUserIDsQuery(ids []string) *user.SearchQuery {
|
2025-02-24 16:29:51 +00:00
|
|
|
return &user.SearchQuery{
|
|
|
|
Query: &user.SearchQuery_InUserIdsQuery{
|
|
|
|
InUserIdsQuery: &user.InUserIDQuery{
|
|
|
|
UserIds: ids,
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InUserEmailsQuery(emails []string) *user.SearchQuery {
|
2025-02-24 16:29:51 +00:00
|
|
|
return &user.SearchQuery{
|
|
|
|
Query: &user.SearchQuery_InUserEmailsQuery{
|
|
|
|
InUserEmailsQuery: &user.InUserEmailsQuery{
|
|
|
|
UserEmails: emails,
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-02 15:44:15 +05:30
|
|
|
func PhoneQuery(number string) *user.SearchQuery {
|
2025-02-24 16:29:51 +00:00
|
|
|
return &user.SearchQuery{
|
|
|
|
Query: &user.SearchQuery_PhoneQuery{
|
|
|
|
PhoneQuery: &user.PhoneQuery{
|
|
|
|
Number: number,
|
|
|
|
},
|
2025-01-02 15:44:15 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-17 10:00:10 +01:00
|
|
|
func UsernameQuery(username string) *user.SearchQuery {
|
2025-02-24 16:29:51 +00:00
|
|
|
return &user.SearchQuery{
|
|
|
|
Query: &user.SearchQuery_UserNameQuery{
|
|
|
|
UserNameQuery: &user.UserNameQuery{
|
|
|
|
UserName: username,
|
|
|
|
},
|
2024-01-17 10:00:10 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-03-21 09:07:00 +01:00
|
|
|
|
|
|
|
func OrganizationIdQuery(resourceowner string) *user.SearchQuery {
|
2025-02-24 16:29:51 +00:00
|
|
|
return &user.SearchQuery{
|
|
|
|
Query: &user.SearchQuery_OrganizationIdQuery{
|
|
|
|
OrganizationIdQuery: &user.OrganizationIdQuery{
|
|
|
|
OrganizationId: resourceowner,
|
|
|
|
},
|
2024-03-21 09:07:00 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|