chore: move gofakeit integration testing calls (#10684)

# Which Problems Are Solved

Flakiness and conflicts in value from gofakeit.

# How the Problems Are Solved

Move Gofakeit calls to the integration package, to guarantee proper
usage and values for integration testing.

# Additional Changes

None

# Additional Context

None

(cherry picked from commit 492f1826ee)
This commit is contained in:
Stefan Benz
2025-09-10 08:00:31 +02:00
committed by Livio Spring
parent 78ded99017
commit b892fc9b28
70 changed files with 1404 additions and 1293 deletions

View File

@@ -5,12 +5,12 @@ import (
"net/url"
"testing"
"github.com/brianvoe/gofakeit/v6"
"github.com/muhlemmer/gu"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/integration"
"github.com/zitadel/zitadel/internal/query"
app "github.com/zitadel/zitadel/pkg/grpc/app/v2beta"
)
@@ -38,7 +38,7 @@ func samlMetadataGen(entityID string) []byte {
func TestCreateSAMLAppRequestToDomain(t *testing.T) {
t.Parallel()
genMetaForValidRequest := samlMetadataGen(gofakeit.URL())
genMetaForValidRequest := samlMetadataGen(integration.URL())
tt := []struct {
testName string
@@ -55,7 +55,7 @@ func TestCreateSAMLAppRequestToDomain(t *testing.T) {
projectID: "proj-1",
req: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{
MetadataXml: samlMetadataGen(gofakeit.URL()),
MetadataXml: samlMetadataGen(integration.URL()),
},
LoginVersion: &app.LoginVersion{
Version: &app.LoginVersion_LoginV2{
@@ -122,7 +122,7 @@ func TestCreateSAMLAppRequestToDomain(t *testing.T) {
func TestUpdateSAMLAppConfigRequestToDomain(t *testing.T) {
t.Parallel()
genMetaForValidRequest := samlMetadataGen(gofakeit.URL())
genMetaForValidRequest := samlMetadataGen(integration.URL())
tt := []struct {
testName string
@@ -139,7 +139,7 @@ func TestUpdateSAMLAppConfigRequestToDomain(t *testing.T) {
projectID: "proj-1",
req: &app.UpdateSAMLApplicationConfigurationRequest{
Metadata: &app.UpdateSAMLApplicationConfigurationRequest_MetadataXml{
MetadataXml: samlMetadataGen(gofakeit.URL()),
MetadataXml: samlMetadataGen(integration.URL()),
},
LoginVersion: &app.LoginVersion{
Version: &app.LoginVersion_LoginV2{
@@ -202,7 +202,7 @@ func TestUpdateSAMLAppConfigRequestToDomain(t *testing.T) {
func TestAppSAMLConfigToPb(t *testing.T) {
t.Parallel()
metadata := samlMetadataGen(gofakeit.URL())
metadata := samlMetadataGen(integration.URL())
tt := []struct {
name string

View File

@@ -7,13 +7,13 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/zitadel/zitadel/internal/integration"
app "github.com/zitadel/zitadel/pkg/grpc/app/v2beta"
)
@@ -35,7 +35,7 @@ func TestCreateApplicationKey(t *testing.T) {
inputCtx: IAMOwnerCtx,
creationRequest: &app.CreateApplicationKeyRequest{
ProjectId: p.GetId(),
AppId: gofakeit.UUID(),
AppId: integration.ID(),
ExpirationDate: timestamppb.New(time.Now().AddDate(0, 0, 1).UTC()),
},
expectedErrorType: codes.FailedPrecondition,
@@ -118,7 +118,7 @@ func TestDeleteApplicationKey(t *testing.T) {
inputCtx: IAMOwnerCtx,
deletionRequest: func(ttt *testing.T) *app.DeleteApplicationKeyRequest {
return &app.DeleteApplicationKeyRequest{
Id: gofakeit.UUID(),
Id: integration.ID(),
ProjectId: p.GetId(),
ApplicationId: createdApp.GetAppId(),
}

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"testing"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
@@ -23,7 +22,7 @@ func TestCreateApplication(t *testing.T) {
t.Parallel()
notExistingProjectID := gofakeit.UUID()
notExistingProjectID := integration.ID()
tt := []struct {
testName string
@@ -95,7 +94,7 @@ func TestCreateApplication(t *testing.T) {
inputCtx: IAMOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_OidcRequest{
OidcRequest: &app.CreateOIDCApplicationRequest{
RedirectUris: []string{"http://example.com"},
@@ -125,7 +124,7 @@ func TestCreateApplication(t *testing.T) {
inputCtx: IAMOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: notExistingProjectID,
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataUrl{
@@ -148,11 +147,11 @@ func TestCreateApplication(t *testing.T) {
inputCtx: IAMOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{
MetadataXml: samlMetadataGen(gofakeit.URL()),
MetadataXml: samlMetadataGen(integration.URL()),
},
LoginVersion: &app.LoginVersion{
Version: &app.LoginVersion_LoginV2{
@@ -217,7 +216,7 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
inputCtx: LoginUserCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_OidcRequest{
OidcRequest: &app.CreateOIDCApplicationRequest{
RedirectUris: []string{"http://example.com"},
@@ -247,11 +246,11 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
inputCtx: LoginUserCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{
MetadataXml: samlMetadataGen(gofakeit.URL()),
MetadataXml: samlMetadataGen(integration.URL()),
},
LoginVersion: &app.LoginVersion{
Version: &app.LoginVersion_LoginV2{
@@ -286,7 +285,7 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
inputCtx: OrgOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_OidcRequest{
OidcRequest: &app.CreateOIDCApplicationRequest{
RedirectUris: []string{"http://example.com"},
@@ -316,11 +315,11 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
inputCtx: OrgOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{
MetadataXml: samlMetadataGen(gofakeit.URL()),
MetadataXml: samlMetadataGen(integration.URL()),
},
LoginVersion: &app.LoginVersion{
Version: &app.LoginVersion_LoginV2{
@@ -355,7 +354,7 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
inputCtx: projectOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_OidcRequest{
OidcRequest: &app.CreateOIDCApplicationRequest{
RedirectUris: []string{"http://example.com"},
@@ -385,11 +384,11 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
inputCtx: projectOwnerCtx,
creationRequest: &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{
MetadataXml: samlMetadataGen(gofakeit.URL()),
MetadataXml: samlMetadataGen(integration.URL()),
},
LoginVersion: &app.LoginVersion{
Version: &app.LoginVersion_LoginV2{
@@ -422,8 +421,8 @@ func TestCreateApplication_WithDifferentPermissions(t *testing.T) {
}
func TestUpdateApplication(t *testing.T) {
orgNotInCtx := instance.CreateOrganization(IAMOwnerCtx, integration.OrganizationName(), gofakeit.Email())
pNotInCtx := instance.CreateProject(IAMOwnerCtx, t, orgNotInCtx.GetOrganizationId(), gofakeit.AppName(), false, false)
orgNotInCtx := instance.CreateOrganization(IAMOwnerCtx, integration.OrganizationName(), integration.Email())
pNotInCtx := instance.CreateProject(IAMOwnerCtx, t, orgNotInCtx.GetOrganizationId(), integration.ApplicationName(), false, false)
p := instance.CreateProject(IAMOwnerCtx, t, instance.DefaultOrg.GetId(), integration.ProjectName(), false, false)
@@ -461,7 +460,7 @@ func TestUpdateApplication(t *testing.T) {
},
}
samlMetas := samlMetadataGen(gofakeit.URL())
samlMetas := samlMetadataGen(integration.URL())
reqForSAMLAppCreation := &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{
@@ -479,28 +478,28 @@ func TestUpdateApplication(t *testing.T) {
appForNameChange, appNameChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForAppNameCreation,
})
require.Nil(t, appNameChangeErr)
appForAPIConfigChange, appAPIConfigChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForAPIAppCreation,
})
require.Nil(t, appAPIConfigChangeErr)
appForOIDCConfigChange, appOIDCConfigChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForOIDCAppCreation,
})
require.Nil(t, appOIDCConfigChangeErr)
appForSAMLConfigChange, appSAMLConfigChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForSAMLAppCreation,
})
require.Nil(t, appSAMLConfigChangeErr)
@@ -649,7 +648,7 @@ func TestUpdateApplication_WithDifferentPermissions(t *testing.T) {
appForNameChange, appNameChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForAppNameCreation,
})
require.Nil(t, appNameChangeErr)
@@ -683,7 +682,7 @@ func TestUpdateApplication_WithDifferentPermissions(t *testing.T) {
ProjectId: p.GetId(),
Id: appForNameChange.GetAppId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
},
},
{
@@ -737,7 +736,7 @@ func TestUpdateApplication_WithDifferentPermissions(t *testing.T) {
ProjectId: p.GetId(),
Id: appForNameChange.GetAppId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
},
},
{
@@ -791,7 +790,7 @@ func TestUpdateApplication_WithDifferentPermissions(t *testing.T) {
ProjectId: p.GetId(),
Id: appForNameChange.GetAppId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
},
expectedErrorType: codes.PermissionDenied,
},
@@ -864,7 +863,7 @@ func TestDeleteApplication(t *testing.T) {
appToDelete, appNameChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForAppNameCreation,
})
require.Nil(t, appNameChangeErr)
@@ -882,7 +881,7 @@ func TestDeleteApplication(t *testing.T) {
inputCtx: IAMOwnerCtx,
deleteRequest: &app.DeleteApplicationRequest{
ProjectId: p.GetId(),
Id: gofakeit.Sentence(2),
Id: integration.ID(),
},
expectedErrorType: codes.NotFound,
},
@@ -984,7 +983,7 @@ func TestDeactivateApplication(t *testing.T) {
appToDeactivate, appCreateErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForAppNameCreation,
})
require.NoError(t, appCreateErr)
@@ -1003,7 +1002,7 @@ func TestDeactivateApplication(t *testing.T) {
inputCtx: IAMOwnerCtx,
deleteRequest: &app.DeactivateApplicationRequest{
ProjectId: p.GetId(),
Id: gofakeit.Sentence(2),
Id: integration.ID(),
},
expectedErrorType: codes.NotFound,
},
@@ -1105,7 +1104,7 @@ func TestReactivateApplication(t *testing.T) {
appToReactivate, appCreateErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForAppNameCreation,
})
require.Nil(t, appCreateErr)
@@ -1130,7 +1129,7 @@ func TestReactivateApplication(t *testing.T) {
inputCtx: IAMOwnerCtx,
reactivateRequest: &app.ReactivateApplicationRequest{
ProjectId: p.GetId(),
Id: gofakeit.Sentence(2),
Id: integration.ID(),
},
expectedErrorType: codes.NotFound,
},
@@ -1238,7 +1237,7 @@ func TestRegenerateClientSecret(t *testing.T) {
apiAppToRegen, apiAppCreateErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForApiAppCreation,
})
require.Nil(t, apiAppCreateErr)
@@ -1266,7 +1265,7 @@ func TestRegenerateClientSecret(t *testing.T) {
oidcAppToRegen, oidcAppCreateErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{
ProjectId: p.GetId(),
Name: gofakeit.AppName(),
Name: integration.ApplicationName(),
CreationRequestType: reqForOIDCAppCreation,
})
require.Nil(t, oidcAppCreateErr)
@@ -1286,7 +1285,7 @@ func TestRegenerateClientSecret(t *testing.T) {
inputCtx: IAMOwnerCtx,
regenRequest: &app.RegenerateClientSecretRequest{
ProjectId: p.GetId(),
ApplicationId: gofakeit.Sentence(2),
ApplicationId: integration.ID(),
},
expectedErrorType: codes.InvalidArgument,
},
@@ -1295,7 +1294,7 @@ func TestRegenerateClientSecret(t *testing.T) {
inputCtx: IAMOwnerCtx,
regenRequest: &app.RegenerateClientSecretRequest{
ProjectId: p.GetId(),
ApplicationId: gofakeit.Sentence(2),
ApplicationId: integration.ID(),
AppType: &app.RegenerateClientSecretRequest_IsApi{},
},
expectedErrorType: codes.NotFound,

View File

@@ -9,7 +9,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
@@ -42,7 +41,7 @@ func TestGetApplication(t *testing.T) {
CreationRequestType: &app.CreateApplicationRequest_SamlRequest{
SamlRequest: &app.CreateSAMLApplicationRequest{
LoginVersion: &app.LoginVersion{Version: &app.LoginVersion_LoginV1{LoginV1: &app.LoginV1{}}},
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{MetadataXml: samlMetadataGen(gofakeit.URL())},
Metadata: &app.CreateSAMLApplicationRequest_MetadataXml{MetadataXml: samlMetadataGen(integration.URL())},
},
},
})
@@ -85,7 +84,7 @@ func TestGetApplication(t *testing.T) {
testName: "when unknown app ID should return not found error",
inputCtx: IAMOwnerCtx,
inputRequest: &app.GetApplicationRequest{
Id: gofakeit.Sentence(2),
Id: integration.ID(),
},
expectedErrorType: codes.NotFound,
@@ -170,9 +169,9 @@ func TestListApplications(t *testing.T) {
createdDeactivatedApiApp, deactivatedApiAppName := createAPIAppWithName(t, IAMOwnerCtx, instance, p.GetId())
deactivateApp(t, createdDeactivatedApiApp, p.GetId())
_, createdSAMLApp, samlAppName := createSAMLAppWithName(t, gofakeit.URL(), p.GetId())
_, createdSAMLApp, samlAppName := createSAMLAppWithName(t, integration.URL(), p.GetId())
createdOIDCApp, oidcAppName := createOIDCAppWithName(t, gofakeit.URL(), p.GetId())
createdOIDCApp, oidcAppName := createOIDCAppWithName(t, integration.URL(), p.GetId())
type appWithName struct {
app *app.CreateApplicationResponse
@@ -593,7 +592,7 @@ func TestGetApplicationKey(t *testing.T) {
testName: "when unknown app ID should return not found error",
inputCtx: IAMOwnerCtx,
inputRequest: &app.GetApplicationKeyRequest{
Id: gofakeit.Sentence(2),
Id: integration.ID(),
},
expectedErrorType: codes.NotFound,

View File

@@ -9,7 +9,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/muhlemmer/gu"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -82,7 +81,7 @@ func samlMetadataGen(entityID string) []byte {
}
func createSAMLAppWithName(t *testing.T, baseURI, projectID string) ([]byte, *app.CreateApplicationResponse, string) {
samlMetas := samlMetadataGen(gofakeit.URL())
samlMetas := samlMetadataGen(integration.URL())
appName := integration.ApplicationName()
appForSAMLConfigChange, appSAMLConfigChangeErr := instance.Client.AppV2Beta.CreateApplication(IAMOwnerCtx, &app.CreateApplicationRequest{