mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
fix(org): adding unique constrants to not allow an org to be added twice with same id (#10243)
# Which Problems Are Solved When adding 2 orgs with the same ID, you get a positive response from the API, later when the org is projected, it errors due to the id already in use # How the Problems Are Solved Check org with orgID specified does not already exist before adding events # Additional Changes Added additional test case for adding same org with same name twice # Additional Context - Closes https://github.com/zitadel/zitadel/issues/10127 --------- Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com>
This commit is contained in:
@@ -47,14 +47,17 @@ func TestMain(m *testing.M) {
|
||||
func TestServer_CreateOrganization(t *testing.T) {
|
||||
idpResp := Instance.AddGenericOAuthProvider(CTX, Instance.DefaultOrg.Id)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *v2beta_org.CreateOrganizationRequest
|
||||
id string
|
||||
want *v2beta_org.CreateOrganizationResponse
|
||||
wantErr bool
|
||||
}{
|
||||
type test struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *v2beta_org.CreateOrganizationRequest
|
||||
id string
|
||||
testFunc func(ctx context.Context, t *testing.T)
|
||||
want *v2beta_org.CreateOrganizationResponse
|
||||
wantErr bool
|
||||
}
|
||||
|
||||
tests := []test{
|
||||
{
|
||||
name: "missing permission",
|
||||
ctx: Instance.WithAuthorization(CTX, integration.UserTypeOrgOwner),
|
||||
@@ -73,6 +76,25 @@ func TestServer_CreateOrganization(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
func() test {
|
||||
orgName := gofakeit.Name()
|
||||
return test{
|
||||
name: "adding org with same name twice",
|
||||
ctx: CTX,
|
||||
req: &v2beta_org.CreateOrganizationRequest{
|
||||
Name: orgName,
|
||||
Admins: nil,
|
||||
},
|
||||
testFunc: func(ctx context.Context, t *testing.T) {
|
||||
// create org initially
|
||||
_, err := Client.CreateOrganization(ctx, &v2beta_org.CreateOrganizationRequest{
|
||||
Name: orgName,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
},
|
||||
wantErr: true,
|
||||
}
|
||||
}(),
|
||||
{
|
||||
name: "invalid admin type",
|
||||
ctx: CTX,
|
||||
@@ -212,9 +234,34 @@ func TestServer_CreateOrganization(t *testing.T) {
|
||||
Id: "custom_id",
|
||||
},
|
||||
},
|
||||
func() test {
|
||||
orgID := gofakeit.Name()
|
||||
return test{
|
||||
name: "adding org with same ID twice",
|
||||
ctx: CTX,
|
||||
req: &v2beta_org.CreateOrganizationRequest{
|
||||
Id: &orgID,
|
||||
Name: gofakeit.Name(),
|
||||
Admins: nil,
|
||||
},
|
||||
testFunc: func(ctx context.Context, t *testing.T) {
|
||||
// create org initially
|
||||
_, err := Client.CreateOrganization(ctx, &v2beta_org.CreateOrganizationRequest{
|
||||
Id: &orgID,
|
||||
Name: gofakeit.Name(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
},
|
||||
wantErr: true,
|
||||
}
|
||||
}(),
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.testFunc != nil {
|
||||
tt.testFunc(tt.ctx, t)
|
||||
}
|
||||
|
||||
got, err := Client.CreateOrganization(tt.ctx, tt.req)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
|
Reference in New Issue
Block a user