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

@@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/muhlemmer/gu"
"github.com/stretchr/testify/require"
"github.com/zitadel/logging"
@@ -939,8 +938,9 @@ func (i *Instance) ActivateProjectGrant(ctx context.Context, t *testing.T, proje
return resp
}
func (i *Instance) CreateProjectUserGrant(t *testing.T, ctx context.Context, projectID, userID string) *mgmt.AddUserGrantResponse {
resp, err := i.Client.Mgmt.AddUserGrant(ctx, &mgmt.AddUserGrantRequest{
func (i *Instance) CreateProjectUserGrant(t *testing.T, ctx context.Context, orgID, projectID, userID string) *mgmt.AddUserGrantResponse {
//nolint:staticcheck
resp, err := i.Client.Mgmt.AddUserGrant(SetOrgID(ctx, orgID), &mgmt.AddUserGrantRequest{
UserId: userID,
ProjectId: projectID,
})
@@ -949,6 +949,7 @@ func (i *Instance) CreateProjectUserGrant(t *testing.T, ctx context.Context, pro
}
func (i *Instance) CreateProjectGrantUserGrant(ctx context.Context, orgID, projectID, projectGrantID, userID string) *mgmt.AddUserGrantResponse {
//nolint:staticcheck
resp, err := i.Client.Mgmt.AddUserGrant(SetOrgID(ctx, orgID), &mgmt.AddUserGrantRequest{
UserId: userID,
ProjectId: projectID,
@@ -1046,7 +1047,7 @@ func (i *Instance) DeleteProjectGrantMembership(t *testing.T, ctx context.Contex
func (i *Instance) CreateTarget(ctx context.Context, t *testing.T, name, endpoint string, ty target_domain.TargetType, interrupt bool) *action.CreateTargetResponse {
if name == "" {
name = gofakeit.Name()
name = TargetName()
}
req := &action.CreateTargetRequest{
Name: name,

View File

@@ -11,7 +11,6 @@ import (
"path/filepath"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/zitadel/logging"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
@@ -263,7 +262,7 @@ func (i *Instance) setOrganization(ctx context.Context) {
func (i *Instance) createMachineUser(ctx context.Context, userType UserType) (userID string) {
mustAwait(func() error {
username := gofakeit.Username()
username := Username()
userResp, err := i.Client.Mgmt.AddMachineUser(ctx, &management.AddMachineUserRequest{
UserName: username,
Name: username,

View File

@@ -11,6 +11,34 @@ func OrganizationName() string {
return company()
}
func Email() string {
return RandString(5) + gofakeit.Email()
}
func Phone() string {
return "+41" + gofakeit.Phone()
}
func FirstName() string {
return gofakeit.FirstName()
}
func LastName() string {
return gofakeit.LastName()
}
func Username() string {
return gofakeit.Username() + RandString(5)
}
func Language() string {
return gofakeit.LanguageBCP()
}
func UserSchemaName() string {
return gofakeit.Name() + RandString(5)
}
// appName private function to add a random string to the gofakeit.AppName function
func appName() string {
return gofakeit.AppName() + "-" + RandString(5)
@@ -39,3 +67,27 @@ func RoleKey() string {
func RoleDisplayName() string {
return appName()
}
func DomainName() string {
return RandString(5) + gofakeit.DomainName()
}
func URL() string {
return gofakeit.URL()
}
func RelayState() string {
return ID()
}
func ID() string {
return RandString(20)
}
func Slogan() string {
return gofakeit.Slogan()
}
func Number() int {
return gofakeit.Number(0, 1_000_000)
}

View File

@@ -10,7 +10,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/zitadel/oidc/v3/pkg/client"
"github.com/zitadel/oidc/v3/pkg/client/rp"
"github.com/zitadel/oidc/v3/pkg/client/rs"
@@ -135,7 +134,7 @@ func (i *Instance) CreateOIDCInactivateProjectClient(ctx context.Context, redire
}
func (i *Instance) CreateOIDCImplicitFlowClient(ctx context.Context, t *testing.T, redirectURI string, loginVersion *app.LoginVersion) (*management.AddOIDCAppResponse, error) {
project := i.CreateProject(ctx, t, "", gofakeit.AppName(), false, false)
project := i.CreateProject(ctx, t, "", ProjectName(), false, false)
resp, err := i.Client.Mgmt.AddOIDCApp(ctx, &management.AddOIDCAppRequest{
ProjectId: project.GetId(),
@@ -176,7 +175,7 @@ func (i *Instance) CreateOIDCImplicitFlowClient(ctx context.Context, t *testing.
}
func (i *Instance) CreateOIDCTokenExchangeClient(ctx context.Context, t *testing.T) (client *management.AddOIDCAppResponse, keyData []byte, err error) {
project := i.CreateProject(ctx, t, "", gofakeit.AppName(), false, false)
project := i.CreateProject(ctx, t, "", ProjectName(), false, false)
return i.CreateOIDCWebClientJWT(ctx, "", "", project.GetId(), app.OIDCGrantType_OIDC_GRANT_TYPE_TOKEN_EXCHANGE, app.OIDCGrantType_OIDC_GRANT_TYPE_AUTHORIZATION_CODE, app.OIDCGrantType_OIDC_GRANT_TYPE_REFRESH_TOKEN)
}
@@ -373,7 +372,7 @@ func CheckRedirect(req *http.Request) (*url.URL, error) {
}
func (i *Instance) CreateOIDCCredentialsClient(ctx context.Context) (machine *management.AddMachineUserResponse, name, clientID, clientSecret string, err error) {
name = gofakeit.Username()
name = Username()
machine, err = i.Client.Mgmt.AddMachineUser(ctx, &management.AddMachineUserRequest{
Name: name,
UserName: name,
@@ -392,7 +391,7 @@ func (i *Instance) CreateOIDCCredentialsClient(ctx context.Context) (machine *ma
}
func (i *Instance) CreateOIDCCredentialsClientInactive(ctx context.Context) (machine *management.AddMachineUserResponse, name, clientID, clientSecret string, err error) {
name = gofakeit.Username()
name = Username()
machine, err = i.Client.Mgmt.AddMachineUser(ctx, &management.AddMachineUserRequest{
Name: name,
UserName: name,
@@ -417,7 +416,7 @@ func (i *Instance) CreateOIDCCredentialsClientInactive(ctx context.Context) (mac
}
func (i *Instance) CreateOIDCJWTProfileClient(ctx context.Context, keyLifetime time.Duration) (machine *management.AddMachineUserResponse, name string, keyData []byte, err error) {
name = gofakeit.Username()
name = Username()
machine, err = i.Client.Mgmt.AddMachineUser(ctx, &management.AddMachineUserRequest{
Name: name,
UserName: name,

View File

@@ -13,7 +13,6 @@ import (
"strings"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/crewjam/saml"
"github.com/crewjam/saml/samlsp"
"github.com/zitadel/logging"
@@ -117,7 +116,7 @@ func (i *Instance) CreateSAMLClientLoginVersion(ctx context.Context, projectID s
resp, err := i.Client.Mgmt.AddSAMLApp(ctx, &management.AddSAMLAppRequest{
ProjectId: projectID,
Name: fmt.Sprintf("app-%s", gofakeit.AppName()),
Name: ApplicationName(),
Metadata: &management.AddSAMLAppRequest_MetadataXml{MetadataXml: spMetadata},
LoginVersion: loginVersion,
})