From afeaa49db3d87404be171da339f96bfdd06b2a30 Mon Sep 17 00:00:00 2001 From: Dobromir Zahariev Date: Tue, 5 Oct 2021 08:32:28 +0300 Subject: [PATCH] Hotfix v1.17.4 2052 (#2053) * Handle same customer and account external tenants ID * Update values.yaml * Adjust test * Formatting --- chart/compass/values.yaml | 4 ++-- .../internal/tenantfetchersvc/handler.go | 4 ++++ .../internal/tenantfetchersvc/handler_test.go | 22 ++++++++++++++++++- tests/tenant-fetcher/tests/handler_test.go | 18 +++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/chart/compass/values.yaml b/chart/compass/values.yaml index 0a65275197..db892977af 100644 --- a/chart/compass/values.yaml +++ b/chart/compass/values.yaml @@ -75,7 +75,7 @@ global: version: "PR-2027" director: dir: - version: "PR-2049" + version: "PR-2053" gateway: dir: version: "PR-2027" @@ -104,7 +104,7 @@ global: version: "PR-44" e2e_tests: dir: - version: "PR-2027" + version: "PR-2053" isLocalEnv: false oauth2: host: oauth2 diff --git a/components/director/internal/tenantfetchersvc/handler.go b/components/director/internal/tenantfetchersvc/handler.go index aa7d02b166..3eb268ce37 100644 --- a/components/director/internal/tenantfetchersvc/handler.go +++ b/components/director/internal/tenantfetchersvc/handler.go @@ -189,6 +189,10 @@ func (h *handler) getSubscriptionRequest(body []byte, region string) (*TenantSub req.SubaccountTenantID = "" } + if req.AccountTenantID == req.CustomerTenantID { + req.CustomerTenantID = "" + } + return req, nil } diff --git a/components/director/internal/tenantfetchersvc/handler_test.go b/components/director/internal/tenantfetchersvc/handler_test.go index 64f512b3f2..11105a0158 100644 --- a/components/director/internal/tenantfetchersvc/handler_test.go +++ b/components/director/internal/tenantfetchersvc/handler_test.go @@ -91,6 +91,14 @@ func TestService_Create(t *testing.T) { }) assert.NoError(t, err) + bodyWithMathcingParent, err := json.Marshal(tenantCreationRequest{ + TenantID: tenantExtID, + CustomerID: tenantExtID, + Subdomain: tenantSubdomain, + SubscriptionProviderID: subscriptionProviderID, + }) + assert.NoError(t, err) + bodyWithMissingTenantSubdomain, err := json.Marshal(tenantCreationRequest{ TenantID: tenantExtID, CustomerID: parentTenantExtID, @@ -151,7 +159,7 @@ func TestService_Create(t *testing.T) { ExpectedStatusCode: http.StatusOK, }, { - Name: "Succeeds when matching child tenant ID is provided", + Name: "Succeeds when matching subaccount and account tenant IDs are provided", TxFn: txGen.ThatSucceeds, TenantSubscriberFn: func() *automock.TenantSubscriber { subscriber := &automock.TenantSubscriber{} @@ -162,6 +170,18 @@ func TestService_Create(t *testing.T) { ExpectedSuccessOutput: compassURL, ExpectedStatusCode: http.StatusOK, }, + { + Name: "Succeeds when matching customer and account tenant IDs are provided", + TxFn: txGen.ThatSucceeds, + TenantSubscriberFn: func() *automock.TenantSubscriber { + subscriber := &automock.TenantSubscriber{} + subscriber.On("Subscribe", txtest.CtxWithDBMatcher(), &accountWithoutParentProvisioningRequest, "").Return(nil).Once() + return subscriber + }, + Request: httptest.NewRequest(http.MethodPut, target, bytes.NewBuffer(bodyWithMathcingParent)), + ExpectedSuccessOutput: compassURL, + ExpectedStatusCode: http.StatusOK, + }, { Name: "Returns error when reading request body fails", TxFn: txGen.ThatDoesntStartTransaction, diff --git a/tests/tenant-fetcher/tests/handler_test.go b/tests/tenant-fetcher/tests/handler_test.go index e963e0c916..fe59149609 100644 --- a/tests/tenant-fetcher/tests/handler_test.go +++ b/tests/tenant-fetcher/tests/handler_test.go @@ -109,6 +109,24 @@ func TestOnboardingHandler(t *testing.T) { assertTenant(t, tnt, tenant.TenantID, tenant.Subdomain) }) + t.Run("Successful account tenant creation with matching customer and account tenant IDs", func(t *testing.T) { + id := uuid.New().String() + tenant := Tenant{ + CustomerID: id, + TenantID: id, + Subdomain: defaultSubdomain, + SubscriptionProviderID: uuid.New().String(), + } + + addTenantExpectStatusCode(t, tenant, http.StatusOK) + + tnt, err := fixtures.GetTenantByExternalID(dexGraphQLClient, tenant.TenantID) + require.NoError(t, err) + + // THEN + assertTenant(t, tnt, tenant.TenantID, tenant.Subdomain) + }) + t.Run("Should not add already existing tenants", func(t *testing.T) { tenantWithCustomer := Tenant{ TenantID: uuid.New().String(),