From 3159e388429c1836ab99b22668872a0f21ee5019 Mon Sep 17 00:00:00 2001 From: Stefan Benz <46600784+stebenz@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:05:55 +0100 Subject: [PATCH] fix: case changes on org domain (#9196) # Which Problems Are Solved Organization name change results in domain events even if the domain itself doesn't change. # How the Problems Are Solved Check if the domain itself really changes, and if not, don't create the events. # Additional Changes Unittest for this specific case. # Additional Context None (cherry picked from commit 69372e52091634d6654130fd99fabdd9d8f0b61d) --- internal/command/org_domain.go | 4 +++ internal/command/org_test.go | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/internal/command/org_domain.go b/internal/command/org_domain.go index 929e0ab75b..2e132f6c47 100644 --- a/internal/command/org_domain.go +++ b/internal/command/org_domain.go @@ -334,6 +334,10 @@ func (c *Commands) changeDefaultDomain(ctx context.Context, orgID, newName strin if err != nil { return nil, err } + // rename of organization resulting in no change in the domain + if newDefaultDomain == defaultDomain { + return nil, nil + } events := []eventstore.Command{ org.NewDomainAddedEvent(ctx, orgAgg, newDefaultDomain), org.NewDomainVerifiedEvent(ctx, orgAgg, newDefaultDomain), diff --git a/internal/command/org_test.go b/internal/command/org_test.go index cc6a384f21..bf88b55a86 100644 --- a/internal/command/org_test.go +++ b/internal/command/org_test.go @@ -702,6 +702,54 @@ func TestCommandSide_ChangeOrg(t *testing.T) { }, res: res{}, }, + { + name: "change org name case verified, with primary", + fields: fields{ + eventstore: eventstoreExpect( + t, + expectFilter( + eventFromEventPusher( + org.NewOrgAddedEvent(context.Background(), + &org.NewAggregate("org1").Aggregate, + "org"), + ), + ), + expectFilter( + eventFromEventPusher( + org.NewOrgAddedEvent(context.Background(), + &org.NewAggregate("org1").Aggregate, + "org"), + ), + eventFromEventPusher( + org.NewDomainAddedEvent(context.Background(), + &org.NewAggregate("org1").Aggregate, + "org.zitadel.ch"), + ), + eventFromEventPusher( + org.NewDomainVerifiedEvent(context.Background(), + &org.NewAggregate("org1").Aggregate, + "org.zitadel.ch"), + ), + eventFromEventPusher( + org.NewDomainPrimarySetEvent(context.Background(), + &org.NewAggregate("org1").Aggregate, + "org.zitadel.ch"), + ), + ), + expectPush( + org.NewOrgChangedEvent(context.Background(), + &org.NewAggregate("org1").Aggregate, "org", "ORG", + ), + ), + ), + }, + args: args{ + ctx: http_util.WithRequestedHost(context.Background(), "zitadel.ch"), + orgID: "org1", + name: "ORG", + }, + res: res{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {