chore: use integration package for name generation (#10591)

# Which Problems Are Solved

Integration test failed sometimes with `organization already
exists`-errors.

# How the Problems Are Solved

Use a consistent function to generate name used for organization
creation.

# Additional Changes

Correct a eventual consistent test for username around organization
domain changes with eventual consistent loop.

# Additional Context

None

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>

(cherry picked from commit 5721b63bcb)
This commit is contained in:
Stefan Benz
2025-08-29 14:56:16 +02:00
committed by Livio Spring
parent 678f9ad448
commit d0d8e904c4
19 changed files with 97 additions and 98 deletions

View File

@@ -4,7 +4,6 @@ package user_test
import (
"context"
"fmt"
"slices"
"testing"
"time"
@@ -377,7 +376,7 @@ func TestServer_ListKeys(t *testing.T) {
want *user.ListKeysResponse
}
OrgCTX := CTX
otherOrg := Instance.CreateOrganization(SystemCTX, fmt.Sprintf("ListKeys-%s", gofakeit.AppName()), gofakeit.Email())
otherOrg := Instance.CreateOrganization(SystemCTX, integration.OrganizationName(), gofakeit.Email())
otherOrgUser, err := Client.CreateUser(SystemCTX, &user.CreateUserRequest{
OrganizationId: otherOrg.OrganizationId,
UserType: &user.CreateUserRequest_Machine_{

View File

@@ -19,7 +19,7 @@ import (
)
func TestServer_SetUserMetadata(t *testing.T) {
iamOwnerCTX := Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
iamOwnerCTX := Instance.WithAuthorizationToken(CTX, integration.UserTypeIAMOwner)
tests := []struct {
name string
@@ -31,7 +31,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
}{
{
name: "missing permission",
ctx: Instance.WithAuthorization(context.Background(), integration.UserTypeNoPermission),
ctx: Instance.WithAuthorizationToken(context.Background(), integration.UserTypeNoPermission),
dep: func(req *user.SetUserMetadataRequest) {
req.UserId = Instance.CreateUserTypeHuman(CTX, gofakeit.Email()).GetId()
},
@@ -77,7 +77,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
},
{
name: "update user metadata",
ctx: Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner),
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeIAMOwner),
dep: func(req *user.SetUserMetadataRequest) {
req.UserId = Instance.CreateUserTypeHuman(iamOwnerCTX, gofakeit.Email()).GetId()
Instance.SetUserMetadata(iamOwnerCTX, req.UserId, "key1", "value1")
@@ -89,7 +89,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
},
{
name: "update user metadata with same value",
ctx: Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner),
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeIAMOwner),
dep: func(req *user.SetUserMetadataRequest) {
req.UserId = Instance.CreateUserTypeHuman(iamOwnerCTX, gofakeit.Email()).GetId()
Instance.SetUserMetadata(iamOwnerCTX, req.UserId, "key1", "value1")
@@ -132,7 +132,7 @@ func assertSetUserMetadataResponse(t *testing.T, creationDate, changeDate time.T
}
func TestServer_ListUserMetadata(t *testing.T) {
iamOwnerCTX := Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
iamOwnerCTX := Instance.WithAuthorizationToken(CTX, integration.UserTypeIAMOwner)
type args struct {
ctx context.Context
@@ -149,7 +149,7 @@ func TestServer_ListUserMetadata(t *testing.T) {
{
name: "missing permission",
args: args{
ctx: Instance.WithAuthorization(context.Background(), integration.UserTypeNoPermission),
ctx: Instance.WithAuthorizationToken(context.Background(), integration.UserTypeNoPermission),
dep: func(ctx context.Context, request *user.ListUserMetadataRequest, response *user.ListUserMetadataResponse) {
userID := Instance.CreateUserTypeHuman(iamOwnerCTX, gofakeit.Email()).GetId()
request.UserId = userID
@@ -281,7 +281,7 @@ func assertPaginationResponse(t *assert.CollectT, expected *filter.PaginationRes
}
func TestServer_DeleteUserMetadata(t *testing.T) {
iamOwnerCTX := Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
iamOwnerCTX := Instance.WithAuthorizationToken(CTX, integration.UserTypeIAMOwner)
tests := []struct {
name string

View File

@@ -1884,7 +1884,7 @@ func TestServer_DeleteUser(t *testing.T) {
func TestServer_StartIdentityProviderIntent(t *testing.T) {
idpResp := Instance.AddGenericOAuthProvider(IamCTX, Instance.DefaultOrg.Id)
orgIdpResp := Instance.AddOrgGenericOAuthProvider(CTX, Instance.DefaultOrg.Id)
orgResp := Instance.CreateOrganization(IamCTX, fmt.Sprintf("NotDefaultOrg-%s", gofakeit.AppName()), gofakeit.Email())
orgResp := Instance.CreateOrganization(IamCTX, integration.OrganizationName(), gofakeit.Email())
notDefaultOrgIdpResp := Instance.AddOrgGenericOAuthProvider(IamCTX, orgResp.OrganizationId)
samlIdpID := Instance.AddSAMLProvider(IamCTX)
samlRedirectIdpID := Instance.AddSAMLRedirectProvider(IamCTX, "")
@@ -4631,7 +4631,7 @@ func TestServer_CreateUser_And_Compare(t *testing.T) {
func TestServer_CreateUser_Permission(t *testing.T) {
newOrgOwnerEmail := gofakeit.Email()
newOrg := Instance.CreateOrganization(IamCTX, fmt.Sprintf("AddHuman-%s", gofakeit.AppName()), newOrgOwnerEmail)
newOrg := Instance.CreateOrganization(IamCTX, integration.OrganizationName(), newOrgOwnerEmail)
type args struct {
ctx context.Context
req *user.CreateUserRequest
@@ -5302,7 +5302,7 @@ func TestServer_UpdateUser_And_Compare(t *testing.T) {
func TestServer_UpdateUser_Permission(t *testing.T) {
newOrgOwnerEmail := gofakeit.Email()
newOrg := Instance.CreateOrganization(IamCTX, fmt.Sprintf("AddHuman-%s", gofakeit.AppName()), newOrgOwnerEmail)
newOrg := Instance.CreateOrganization(IamCTX, integration.OrganizationName(), newOrgOwnerEmail)
newHumanUserID := newOrg.CreatedAdmins[0].GetUserId()
machineUserResp, err := Instance.Client.UserV2.CreateUser(IamCTX, &user.CreateUserRequest{
OrganizationId: newOrg.OrganizationId,