|
|
|
@@ -5,6 +5,7 @@ package user_test
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"slices"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
@@ -24,7 +25,7 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
type args struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
req *user.GetUserByIDRequest
|
|
|
|
|
dep func(ctx context.Context, username string, request *user.GetUserByIDRequest) (*userAttr, error)
|
|
|
|
|
dep func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
@@ -39,8 +40,8 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
|
UserId: "",
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, username string, request *user.GetUserByIDRequest) (*userAttr, error) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
@@ -52,8 +53,8 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
&user.GetUserByIDRequest{
|
|
|
|
|
UserId: "unknown",
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, username string, request *user.GetUserByIDRequest) (*userAttr, error) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
@@ -63,10 +64,10 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
&user.GetUserByIDRequest{},
|
|
|
|
|
func(ctx context.Context, username string, request *user.GetUserByIDRequest) (*userAttr, error) {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
request.UserId = resp.GetUserId()
|
|
|
|
|
return &userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}, nil
|
|
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
|
|
|
|
request.UserId = info.UserID
|
|
|
|
|
return &info
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.GetUserByIDResponse{
|
|
|
|
@@ -90,7 +91,6 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -107,11 +107,10 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
&user.GetUserByIDRequest{},
|
|
|
|
|
func(ctx context.Context, username string, request *user.GetUserByIDRequest) (*userAttr, error) {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
request.UserId = resp.GetUserId()
|
|
|
|
|
details := Instance.SetUserPassword(ctx, resp.GetUserId(), integration.UserPassword, true)
|
|
|
|
|
return &userAttr{resp.GetUserId(), username, details.GetChangeDate(), resp.GetDetails()}, nil
|
|
|
|
|
func(ctx context.Context, request *user.GetUserByIDRequest) *userAttr {
|
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, true)
|
|
|
|
|
request.UserId = info.UserID
|
|
|
|
|
return &info
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.GetUserByIDResponse{
|
|
|
|
@@ -135,7 +134,6 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
@@ -152,9 +150,7 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
username := gofakeit.Email()
|
|
|
|
|
userAttr, err := tt.args.dep(tt.args.ctx, username, tt.args.req)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
userAttr := tt.args.dep(IamCTX, tt.args.req)
|
|
|
|
|
|
|
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.args.ctx, time.Minute)
|
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
@@ -174,11 +170,12 @@ func TestServer_GetUserByID(t *testing.T) {
|
|
|
|
|
tt.want.User.LoginNames = []string{userAttr.Username}
|
|
|
|
|
if human := tt.want.User.GetHuman(); human != nil {
|
|
|
|
|
human.Email.Email = userAttr.Username
|
|
|
|
|
human.Phone.Phone = userAttr.Phone
|
|
|
|
|
if tt.want.User.GetHuman().GetPasswordChanged() != nil {
|
|
|
|
|
human.PasswordChanged = userAttr.Changed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert.Equal(ttt, tt.want.User, got.User)
|
|
|
|
|
assert.EqualExportedValues(ttt, tt.want.User, got.User)
|
|
|
|
|
integration.AssertDetails(ttt, tt.want, got)
|
|
|
|
|
}, retryDuration, tick)
|
|
|
|
|
})
|
|
|
|
@@ -325,21 +322,60 @@ func TestServer_GetUserByID_Permission(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type userAttr struct {
|
|
|
|
|
UserID string
|
|
|
|
|
Username string
|
|
|
|
|
Phone string
|
|
|
|
|
Changed *timestamppb.Timestamp
|
|
|
|
|
Details *object.Details
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()}
|
|
|
|
|
if passwordChangeRequired {
|
|
|
|
|
details := Instance.SetUserPassword(ctx, resp.GetUserId(), integration.UserPassword, true)
|
|
|
|
|
info.Changed = details.GetChangeDate()
|
|
|
|
|
}
|
|
|
|
|
return info
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
orgResp := Instance.CreateOrganization(IamCTX, fmt.Sprintf("ListUsersOrg-%s", gofakeit.AppName()), gofakeit.Email())
|
|
|
|
|
userResp := Instance.CreateHumanUserVerified(IamCTX, orgResp.OrganizationId, gofakeit.Email())
|
|
|
|
|
type args struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
count int
|
|
|
|
|
req *user.ListUsersRequest
|
|
|
|
|
dep func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error)
|
|
|
|
|
ctx context.Context
|
|
|
|
|
req *user.ListUsersRequest
|
|
|
|
|
dep func(ctx context.Context, request *user.ListUsersRequest) userAttrs
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
@@ -351,11 +387,11 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user by id, no permission",
|
|
|
|
|
args: args{
|
|
|
|
|
UserCTX,
|
|
|
|
|
0,
|
|
|
|
|
&user.ListUsersRequest{},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery([]string{userResp.UserId}))
|
|
|
|
|
return []userAttr{}, nil
|
|
|
|
|
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{}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -371,22 +407,15 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user by id, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
1,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
userIDs := make([]string, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
userIDs[i] = resp.GetUserId()
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}
|
|
|
|
|
}
|
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery(userIDs))
|
|
|
|
|
return infos, nil
|
|
|
|
|
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{info}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -412,7 +441,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -425,23 +453,15 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user by id, passwordChangeRequired, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
1,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
userIDs := make([]string, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
userIDs[i] = resp.GetUserId()
|
|
|
|
|
details := Instance.SetUserPassword(ctx, resp.GetUserId(), integration.UserPassword, true)
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, details.GetChangeDate(), resp.GetDetails()}
|
|
|
|
|
}
|
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery(userIDs))
|
|
|
|
|
return infos, nil
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, true)
|
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery([]string{info.UserID}))
|
|
|
|
|
return []userAttr{info}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -467,7 +487,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
@@ -482,22 +501,15 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user by id multiple, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
3,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
userIDs := make([]string, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
userIDs[i] = resp.GetUserId()
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}
|
|
|
|
|
}
|
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery(userIDs))
|
|
|
|
|
return infos, nil
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
infos := createUsers(ctx, orgResp.OrganizationId, 3, false)
|
|
|
|
|
request.Queries = append(request.Queries, InUserIDsQuery(infos.userIDs()))
|
|
|
|
|
return infos
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -523,7 +535,27 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -544,28 +576,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
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{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -578,22 +588,15 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user by username, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
1,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
userIDs := make([]string, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
userIDs[i] = resp.GetUserId()
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}
|
|
|
|
|
request.Queries = append(request.Queries, UsernameQuery(username))
|
|
|
|
|
}
|
|
|
|
|
return infos, nil
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
|
|
|
|
request.Queries = append(request.Queries, UsernameQuery(info.Username))
|
|
|
|
|
return []userAttr{info}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -619,7 +622,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -632,20 +634,15 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user in emails, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
1,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}
|
|
|
|
|
}
|
|
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(usernames))
|
|
|
|
|
return infos, nil
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
|
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery([]string{info.Username}))
|
|
|
|
|
return []userAttr{info}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -671,7 +668,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -684,20 +680,15 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user in emails multiple, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
3,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}
|
|
|
|
|
}
|
|
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(usernames))
|
|
|
|
|
return infos, nil
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
infos := createUsers(ctx, orgResp.OrganizationId, 3, false)
|
|
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(infos.emails()))
|
|
|
|
|
return infos
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -723,7 +714,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -744,7 +734,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -765,7 +754,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -778,14 +766,81 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user in emails no found, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
3,
|
|
|
|
|
&user.ListUsersRequest{Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
InUserEmailsQuery([]string{"notfound"}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
return []userAttr{}, nil
|
|
|
|
|
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,
|
|
|
|
|
&user.ListUsersRequest{
|
|
|
|
|
Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
info := createUser(ctx, orgResp.OrganizationId, false)
|
|
|
|
|
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,
|
|
|
|
|
&user.ListUsersRequest{Queries: []*user.SearchQuery{
|
|
|
|
|
OrganizationIdQuery(orgResp.OrganizationId),
|
|
|
|
|
InUserEmailsQuery([]string{"notfound"}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
return []userAttr{}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -801,19 +856,14 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
name: "list user resourceowner multiple, ok",
|
|
|
|
|
args: args{
|
|
|
|
|
IamCTX,
|
|
|
|
|
3,
|
|
|
|
|
&user.ListUsersRequest{},
|
|
|
|
|
func(ctx context.Context, usernames []string, request *user.ListUsersRequest) ([]userAttr, error) {
|
|
|
|
|
func(ctx context.Context, request *user.ListUsersRequest) userAttrs {
|
|
|
|
|
orgResp := Instance.CreateOrganization(ctx, fmt.Sprintf("ListUsersResourceowner-%s", gofakeit.AppName()), gofakeit.Email())
|
|
|
|
|
|
|
|
|
|
infos := make([]userAttr, len(usernames))
|
|
|
|
|
for i, username := range usernames {
|
|
|
|
|
resp := Instance.CreateHumanUserVerified(ctx, orgResp.OrganizationId, username)
|
|
|
|
|
infos[i] = userAttr{resp.GetUserId(), username, nil, resp.GetDetails()}
|
|
|
|
|
}
|
|
|
|
|
infos := createUsers(ctx, orgResp.OrganizationId, 3, false)
|
|
|
|
|
request.Queries = append(request.Queries, OrganizationIdQuery(orgResp.OrganizationId))
|
|
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(usernames))
|
|
|
|
|
return infos, nil
|
|
|
|
|
request.Queries = append(request.Queries, InUserEmailsQuery(infos.emails()))
|
|
|
|
|
return infos
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &user.ListUsersResponse{
|
|
|
|
@@ -839,7 +889,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -860,7 +909,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -881,7 +929,6 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
Phone: &user.HumanPhone{
|
|
|
|
|
Phone: "+41791234567",
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -893,12 +940,7 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
usernames := make([]string, tt.args.count)
|
|
|
|
|
for i := 0; i < tt.args.count; i++ {
|
|
|
|
|
usernames[i] = gofakeit.Email()
|
|
|
|
|
}
|
|
|
|
|
infos, err := tt.args.dep(tt.args.ctx, usernames, tt.args.req)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
infos := tt.args.dep(IamCTX, tt.args.req)
|
|
|
|
|
|
|
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.args.ctx, time.Minute)
|
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
@@ -924,6 +966,7 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@@ -931,7 +974,7 @@ func TestServer_ListUsers(t *testing.T) {
|
|
|
|
|
tt.want.Result[i].Details = infos[i].Details
|
|
|
|
|
}
|
|
|
|
|
for i := range tt.want.Result {
|
|
|
|
|
assert.Contains(ttt, got.Result, tt.want.Result[i])
|
|
|
|
|
assert.EqualExportedValues(ttt, got.Result[i], tt.want.Result[i])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
integration.AssertListDetails(ttt, tt.want, got)
|
|
|
|
@@ -958,6 +1001,15 @@ func InUserEmailsQuery(emails []string) *user.SearchQuery {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PhoneQuery(number string) *user.SearchQuery {
|
|
|
|
|
return &user.SearchQuery{Query: &user.SearchQuery_PhoneQuery{
|
|
|
|
|
PhoneQuery: &user.PhoneQuery{
|
|
|
|
|
Number: number,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UsernameQuery(username string) *user.SearchQuery {
|
|
|
|
|
return &user.SearchQuery{Query: &user.SearchQuery_UserNameQuery{
|
|
|
|
|
UserNameQuery: &user.UserNameQuery{
|
|
|
|
|