From ed5d968d7cec34ad900eb279fc5d427dd2d51592 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Tue, 4 Jul 2023 18:14:26 +0200 Subject: [PATCH] cleanup --- e2e/config/host.docker.internal/zitadel.yaml | 25 ++++-------- e2e/config/localhost/zitadel.yaml | 26 ++++-------- internal/integration/client.go | 24 +++++++++++ internal/integration/integration.go | 40 ------------------- internal/integration/rand.go | 20 ++++++++++ .../handlers/handlers_integration_test.go | 8 +--- 6 files changed, 60 insertions(+), 83 deletions(-) create mode 100644 internal/integration/rand.go diff --git a/e2e/config/host.docker.internal/zitadel.yaml b/e2e/config/host.docker.internal/zitadel.yaml index 6808269531..ff3ecc76e4 100644 --- a/e2e/config/host.docker.internal/zitadel.yaml +++ b/e2e/config/host.docker.internal/zitadel.yaml @@ -1,35 +1,22 @@ Log: Level: info -Telemetry: - Enabled: true - Endpoints: - - https://httpbin.org/post - ExternalDomain: host.docker.internal ExternalSecure: false -TLS: - Enabled: false - Database: cockroach: # This makes the e2e config reusable with an out-of-docker zitadel process and an /etc/hosts entry Host: host.docker.internal +TLS: + Enabled: false + FirstInstance: Org: Human: PasswordChangeRequired: false -DefaultInstance: - Org: - Human: - PasswordChangeRequired: false - Password: "Password1!" - LoginPolicy: - MfaInitSkipLifetime: "0" - LogStore: Access: Database: @@ -55,8 +42,10 @@ Projections: Customizations: NotificationsQuotas: RequeueEvery: 1s - Telemetry: - RequeueEvery: 1s + +DefaultInstance: + LoginPolicy: + MfaInitSkipLifetime: "0" SystemAPIUsers: - cypress: diff --git a/e2e/config/localhost/zitadel.yaml b/e2e/config/localhost/zitadel.yaml index ad9d0692d3..e53061218d 100644 --- a/e2e/config/localhost/zitadel.yaml +++ b/e2e/config/localhost/zitadel.yaml @@ -1,36 +1,22 @@ Log: Level: info -Telemetry: - Enabled: true - Endpoints: -# - https://httpbin.org/post - - https://example.com - ExternalDomain: localhost ExternalSecure: false -TLS: - Enabled: false - Database: cockroach: # This makes the e2e config reusable with an out-of-docker zitadel process and an /etc/hosts entry Host: host.docker.internal +TLS: + Enabled: false + FirstInstance: Org: Human: PasswordChangeRequired: false -DefaultInstance: - Org: - Human: - PasswordChangeRequired: false - Password: "Password1!" - LoginPolicy: - MfaInitSkipLifetime: "0" - LogStore: Access: Database: @@ -56,8 +42,10 @@ Projections: Customizations: NotificationsQuotas: RequeueEvery: 1s - Telemetry: - RequeueEvery: 30s + +DefaultInstance: + LoginPolicy: + MfaInitSkipLifetime: "0" SystemAPIUsers: - cypress: diff --git a/internal/integration/client.go b/internal/integration/client.go index 019fc2a4e5..3f86c035f6 100644 --- a/internal/integration/client.go +++ b/internal/integration/client.go @@ -44,6 +44,30 @@ func newClient(cc *grpc.ClientConn) Client { } } +func (t *Tester) UseIsolatedInstance(ctx context.Context) (primaryDomain, instanceID string, systemCtx, iamOwnerCtx context.Context) { + systemCtx = t.WithAuthorization(ctx, SystemUser) + primaryDomain = randString(5) + ".integration" + instance, err := t.Client.System.CreateInstance(systemCtx, &system.CreateInstanceRequest{ + InstanceName: "testinstance", + CustomDomain: primaryDomain, + Owner: &system.CreateInstanceRequest_Machine_{ + Machine: &system.CreateInstanceRequest_Machine{ + UserName: "owner", + Name: "owner", + PersonalAccessToken: &system.CreateInstanceRequest_PersonalAccessToken{}, + }, + }, + }) + if err != nil { + panic(err) + } + t.createClientConn(ctx, grpc.WithAuthority(primaryDomain)) + t.Users[IAMOwner] = User{ + Token: instance.GetPat(), + } + return primaryDomain, instance.GetInstanceId(), systemCtx, t.WithAuthorization(ctx, IAMOwner) +} + func (s *Tester) CreateHumanUser(ctx context.Context) *user.AddHumanUserResponse { resp, err := s.Client.UserV2.AddHumanUser(ctx, &user.AddHumanUserRequest{ Organisation: &object.Organisation{ diff --git a/internal/integration/integration.go b/internal/integration/integration.go index ac9931bbd8..92a003d0e8 100644 --- a/internal/integration/integration.go +++ b/internal/integration/integration.go @@ -8,7 +8,6 @@ import ( _ "embed" "errors" "fmt" - "math/rand" "os" "strings" "sync" @@ -33,13 +32,8 @@ import ( "github.com/zitadel/zitadel/internal/query" "github.com/zitadel/zitadel/internal/webauthn" "github.com/zitadel/zitadel/pkg/grpc/admin" - "github.com/zitadel/zitadel/pkg/grpc/system" ) -func init() { - rand.Seed(time.Now().UnixNano()) -} - var ( //go:embed config/zitadel.yaml zitadelYAML []byte @@ -288,37 +282,3 @@ func Contexts(timeout time.Duration) (ctx, errCtx context.Context, cancel contex ctx, cancel = context.WithTimeout(context.Background(), timeout) return ctx, errCtx, cancel } - -var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz") - -func randStringRunes(n int) string { - b := make([]rune, n) - for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] - } - return string(b) -} - -func (t *Tester) UseIsolatedInstance(ctx context.Context) (primaryDomain, instanceID string, systemCtx, iamOwnerCtx context.Context) { - systemCtx = t.WithAuthorization(ctx, SystemUser) - primaryDomain = randStringRunes(5) + ".integration" - instance, err := t.Client.System.CreateInstance(systemCtx, &system.CreateInstanceRequest{ - InstanceName: "testinstance", - CustomDomain: primaryDomain, - Owner: &system.CreateInstanceRequest_Machine_{ - Machine: &system.CreateInstanceRequest_Machine{ - UserName: "owner", - Name: "owner", - PersonalAccessToken: &system.CreateInstanceRequest_PersonalAccessToken{}, - }, - }, - }) - if err != nil { - panic(err) - } - t.createClientConn(ctx, grpc.WithAuthority(primaryDomain)) - t.Users[IAMOwner] = User{ - Token: instance.GetPat(), - } - return primaryDomain, instance.GetInstanceId(), systemCtx, t.WithAuthorization(ctx, IAMOwner) -} diff --git a/internal/integration/rand.go b/internal/integration/rand.go new file mode 100644 index 0000000000..4425c97c8c --- /dev/null +++ b/internal/integration/rand.go @@ -0,0 +1,20 @@ +package integration + +import ( + "math/rand" + "time" +) + +func init() { + rand.Seed(time.Now().UnixNano()) +} + +var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz") + +func randString(n int) string { + b := make([]rune, n) + for i := range b { + b[i] = letterRunes[rand.Intn(len(letterRunes))] + } + return string(b) +} diff --git a/internal/notification/handlers/handlers_integration_test.go b/internal/notification/handlers/handlers_integration_test.go index 8a7a0b085d..1b3d5f6df4 100644 --- a/internal/notification/handlers/handlers_integration_test.go +++ b/internal/notification/handlers/handlers_integration_test.go @@ -8,11 +8,9 @@ import ( "testing" "time" - "github.com/zitadel/zitadel/pkg/grpc/management" - - "github.com/zitadel/zitadel/pkg/grpc/system" - "github.com/zitadel/zitadel/internal/integration" + "github.com/zitadel/zitadel/pkg/grpc/management" + "github.com/zitadel/zitadel/pkg/grpc/system" ) var ( @@ -27,8 +25,6 @@ func TestMain(m *testing.M) { ctx, _, cancel := integration.Contexts(5 * time.Minute) CTX = ctx defer cancel() - os.Setenv("INTEGRATION_DB_FLAVOR", "postgres") - os.Setenv("ZITADEL_MASTERKEY", "MasterkeyNeedsToHave32Characters") Tester = integration.NewTester(ctx) MgmtClient = Tester.Client.Mgmt SystemClient = Tester.Client.System