diff --git a/Makefile b/Makefile index 438e7c0941..3b23bc1248 100644 --- a/Makefile +++ b/Makefile @@ -152,7 +152,7 @@ core_integration_server_stop: .PHONY: core_integration_reports core_integration_reports: - go tool covdata textfmt -i=tmp/coverage -pkg=github.com/zitadel/zitadel/internal/...,github.com/zitadel/zitadel/cmd/...,,github.com/zitadel/zitadel/backend/... -o profile.cov + go tool covdata textfmt -i=tmp/coverage -pkg=github.com/zitadel/zitadel/internal/...,github.com/zitadel/zitadel/cmd/...,github.com/zitadel/zitadel/backend/... -o profile.cov .PHONY: core_integration_test core_integration_test: core_integration_server_start core_integration_test_packages core_integration_server_stop core_integration_reports diff --git a/backend/v3/domain/instance.go b/backend/v3/domain/instance.go index 60a5f98f8d..b1f9c180c3 100644 --- a/backend/v3/domain/instance.go +++ b/backend/v3/domain/instance.go @@ -19,7 +19,7 @@ type Instance struct { CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - Domains []*InstanceDomain `json:"domains,omitempty" db:"-"` + Domains []*InstanceDomain `json:"domains,omitempty" db:"domains"` } type instanceCacheIndex uint8 diff --git a/backend/v3/domain/organization.go b/backend/v3/domain/organization.go index 6e51fe19da..d5d8de480f 100644 --- a/backend/v3/domain/organization.go +++ b/backend/v3/domain/organization.go @@ -22,7 +22,7 @@ type Organization struct { CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"` UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"` - Domains []*OrganizationDomain `json:"domains,omitempty" db:"-"` + Domains []*OrganizationDomain `json:"domains,omitempty" db:"domains"` } // OrgIdentifierCondition is used to help specify a single Organization, diff --git a/backend/v3/storage/database/repository/instance_test.go b/backend/v3/storage/database/repository/instance_test.go index e40f416099..badea3d081 100644 --- a/backend/v3/storage/database/repository/instance_test.go +++ b/backend/v3/storage/database/repository/instance_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/brianvoe/gofakeit/v6" + "github.com/muhlemmer/gu" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -337,6 +338,51 @@ func TestGetInstance(t *testing.T) { }, } }(), + { + name: "happy path including domains", + testFunc: func(ctx context.Context, t *testing.T) *domain.Instance { + instanceRepo := repository.InstanceRepository(pool) + instanceId := gofakeit.Name() + instanceName := gofakeit.Name() + + inst := domain.Instance{ + ID: instanceId, + Name: instanceName, + DefaultOrgID: "defaultOrgId", + IAMProjectID: "iamProject", + ConsoleClientID: "consoleCLient", + ConsoleAppID: "consoleApp", + DefaultLanguage: "defaultLanguage", + } + + // create instance + err := instanceRepo.Create(ctx, &inst) + require.NoError(t, err) + + domainRepo := instanceRepo.Domains(false) + d := &domain.AddInstanceDomain{ + InstanceID: inst.ID, + Domain: gofakeit.DomainName(), + IsPrimary: gu.Ptr(true), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, + } + err = domainRepo.Add(ctx, d) + require.NoError(t, err) + + inst.Domains = append(inst.Domains, &domain.InstanceDomain{ + InstanceID: d.InstanceID, + Domain: d.Domain, + IsPrimary: d.IsPrimary, + IsGenerated: d.IsGenerated, + Type: d.Type, + CreatedAt: d.CreatedAt, + UpdatedAt: d.UpdatedAt, + }) + + return &inst + }, + }, { name: "get non existent instance", testFunc: func(ctx context.Context, t *testing.T) *domain.Instance { diff --git a/backend/v3/storage/database/repository/org_test.go b/backend/v3/storage/database/repository/org_test.go index 26b7add8d9..ac3c59d2b7 100644 --- a/backend/v3/storage/database/repository/org_test.go +++ b/backend/v3/storage/database/repository/org_test.go @@ -471,6 +471,52 @@ func TestGetOrganization(t *testing.T) { orgIdentifierCondition: orgRepo.IDCondition(organizationId), } }(), + func() test { + organizationId := gofakeit.Name() + return test{ + name: "happy path get using id including domain", + testFunc: func(ctx context.Context, t *testing.T) *domain.Organization { + organizationName := gofakeit.Name() + + org := domain.Organization{ + ID: organizationId, + Name: organizationName, + InstanceID: instanceId, + State: domain.OrgStateActive, + } + + // create organization + err := orgRepo.Create(ctx, &org) + require.NoError(t, err) + + d := &domain.AddOrganizationDomain{ + InstanceID: org.InstanceID, + OrgID: org.ID, + Domain: gofakeit.DomainName(), + IsVerified: true, + IsPrimary: true, + } + err = orgRepo.Domains(false).Add(ctx, d) + require.NoError(t, err) + + org.Domains = []*domain.OrganizationDomain{ + { + InstanceID: d.InstanceID, + OrgID: d.OrgID, + ValidationType: d.ValidationType, + Domain: d.Domain, + IsPrimary: d.IsPrimary, + IsVerified: d.IsVerified, + CreatedAt: d.CreatedAt, + UpdatedAt: d.UpdatedAt, + }, + } + + return &org + }, + orgIdentifierCondition: orgRepo.IDCondition(organizationId), + } + }(), func() test { organizationName := gofakeit.Name() return test{