forked from baron/baron-sso
조직 연동 오류 해결
This commit is contained in:
@@ -200,28 +200,28 @@ func TestCompareWorksmobileGroupsUsesOrganizationsAndBarongroupChildCompanies(t
|
||||
Type: domain.TenantTypeOrganization,
|
||||
ParentID: &hanmac.ID,
|
||||
}
|
||||
legacyUserGroup := domain.Tenant{
|
||||
userGroup := domain.Tenant{
|
||||
ID: "legacy-user-group-tenant",
|
||||
Name: "레거시 사용자 그룹",
|
||||
Name: "사용자 그룹 조직",
|
||||
Type: domain.TenantTypeUserGroup,
|
||||
ParentID: &hanmac.ID,
|
||||
}
|
||||
|
||||
items := compareWorksmobileGroups(
|
||||
[]domain.Tenant{root, hanmac, barongroup, barongroupChildCompany, organization, legacyUserGroup},
|
||||
[]domain.Tenant{root, hanmac, barongroup, barongroupChildCompany, organization, userGroup},
|
||||
[]WorksmobileRemoteGroup{
|
||||
{ID: "works-root", ExternalID: root.ID, DisplayName: root.Name},
|
||||
{ID: "works-hanmac", ExternalID: hanmac.ID, DisplayName: hanmac.Name, Email: "hanmac@hanmaceng.co.kr"},
|
||||
{ID: "works-barongroup", ExternalID: barongroup.ID, DisplayName: barongroup.Name},
|
||||
{ID: "works-barongroup-child", ExternalID: barongroupChildCompany.ID, DisplayName: barongroupChildCompany.Name},
|
||||
{ID: "works-organization", ExternalID: organization.ID, DisplayName: organization.Name, ParentID: "works-hanmac"},
|
||||
{ID: "works-legacy-user-group", ExternalID: legacyUserGroup.ID, DisplayName: legacyUserGroup.Name},
|
||||
{ID: "works-user-group", ExternalID: userGroup.ID, DisplayName: userGroup.Name, ParentID: "works-hanmac"},
|
||||
{ID: "works-orphan", ExternalID: "works-orphan", DisplayName: "WORKS 전용 조직"},
|
||||
},
|
||||
true,
|
||||
)
|
||||
|
||||
require.Len(t, items, 3)
|
||||
require.Len(t, items, 4)
|
||||
require.Equal(t, barongroupChildCompany.ID, items[0].BaronID)
|
||||
require.Equal(t, "matched", items[0].Status)
|
||||
require.Equal(t, organization.ID, items[1].BaronID)
|
||||
@@ -233,8 +233,159 @@ func TestCompareWorksmobileGroupsUsesOrganizationsAndBarongroupChildCompanies(t
|
||||
require.Equal(t, "works-hanmac", items[1].BaronParentWorksmobileID)
|
||||
require.Equal(t, hanmac.Name, items[1].BaronParentWorksmobileName)
|
||||
require.Equal(t, "hanmac@hanmaceng.co.kr", items[1].BaronParentWorksmobileEmail)
|
||||
require.Equal(t, "works-orphan", items[2].ExternalKey)
|
||||
require.Equal(t, "missing_in_baron", items[2].Status)
|
||||
require.Equal(t, userGroup.ID, items[2].BaronID)
|
||||
require.Equal(t, "matched", items[2].Status)
|
||||
require.Equal(t, "works-orphan", items[3].ExternalKey)
|
||||
require.Equal(t, "missing_in_baron", items[3].Status)
|
||||
}
|
||||
|
||||
func TestCompareWorksmobileGroupsShowsUserGroupMissingInWorksmobile(t *testing.T) {
|
||||
parentID := "company-tenant"
|
||||
userGroup := domain.Tenant{
|
||||
ID: "team-tenant",
|
||||
Name: "신규 팀",
|
||||
Slug: "new-team",
|
||||
Type: domain.TenantTypeUserGroup,
|
||||
ParentID: &parentID,
|
||||
}
|
||||
|
||||
items := compareWorksmobileGroups(
|
||||
[]domain.Tenant{
|
||||
{ID: parentID, Slug: "company", Name: "계열사", Type: domain.TenantTypeCompany},
|
||||
userGroup,
|
||||
},
|
||||
nil,
|
||||
false,
|
||||
)
|
||||
|
||||
require.Len(t, items, 1)
|
||||
require.Equal(t, userGroup.ID, items[0].BaronID)
|
||||
require.Equal(t, "missing_in_worksmobile", items[0].Status)
|
||||
}
|
||||
|
||||
func TestCompareWorksmobileGroupsMarksMatchedOrgUnitNeedsUpdate(t *testing.T) {
|
||||
parentID := "parent-tenant"
|
||||
tenant := domain.Tenant{
|
||||
ID: "team-tenant",
|
||||
Name: "변경된 팀명",
|
||||
Slug: "team",
|
||||
Type: domain.TenantTypeUserGroup,
|
||||
ParentID: &parentID,
|
||||
}
|
||||
|
||||
items := compareWorksmobileGroups(
|
||||
[]domain.Tenant{
|
||||
{ID: parentID, Slug: "parent", Name: "상위 조직", Type: domain.TenantTypeUserGroup},
|
||||
tenant,
|
||||
},
|
||||
[]WorksmobileRemoteGroup{
|
||||
{ID: "works-parent", ExternalID: parentID, DisplayName: "상위 조직"},
|
||||
{ID: "works-team", ExternalID: tenant.ID, DisplayName: "이전 팀명", ParentID: "works-parent"},
|
||||
},
|
||||
false,
|
||||
)
|
||||
|
||||
require.Len(t, items, 1)
|
||||
require.Equal(t, tenant.ID, items[0].BaronID)
|
||||
require.Equal(t, "needs_update", items[0].Status)
|
||||
}
|
||||
|
||||
func TestCompareWorksmobileGroupsCoversHanmacOrganizationRegressionIDs(t *testing.T) {
|
||||
rootID := "038326b6-954a-48a7-a85f-efd83f62b82a"
|
||||
samanID := "9caf62e1-297d-4e8f-870b-61780998bbeb"
|
||||
hanmacID := "369c1843-56af-4344-9c21-0e01197ab861"
|
||||
baronGroupID := "96369f12-6b66-4b2a-a916-d1c99d326f02"
|
||||
changedID := "818c856b-9545-442f-b827-d1c569f200b0"
|
||||
hanmacOnlyID := "2d217948-9c5a-42ea-805b-eef9c7421775"
|
||||
baronOnlyID := "32464fd6-da51-473f-844a-ab88603ad1f0"
|
||||
localTenants := []domain.Tenant{
|
||||
{ID: rootID, Slug: HanmacFamilyTenantSlug, Name: "한맥가족", Type: domain.TenantTypeCompanyGroup},
|
||||
{ID: samanID, Slug: "saman", Name: "삼안", Type: domain.TenantTypeCompany, ParentID: &rootID},
|
||||
{ID: hanmacID, Slug: "hanmac", Name: "한맥기술", Type: domain.TenantTypeCompany, ParentID: &rootID},
|
||||
{ID: baronGroupID, Slug: "baron-group", Name: "바론그룹", Type: domain.TenantTypeCompanyGroup, ParentID: &rootID},
|
||||
{ID: changedID, Slug: "rnd-saman", Name: "삼안기술개발센터(조직도용)", Type: domain.TenantTypeOrganization, ParentID: &samanID},
|
||||
{ID: hanmacOnlyID, Slug: "rnd-hanmac", Name: "한맥기술개발센터(조직도용)", Type: domain.TenantTypeOrganization, ParentID: &hanmacID},
|
||||
{ID: baronOnlyID, Slug: "rnd-baron", Name: "바론기술개발센터(조직도용)", Type: domain.TenantTypeOrganization, ParentID: &baronGroupID},
|
||||
}
|
||||
remoteGroups := []WorksmobileRemoteGroup{
|
||||
{ID: "works-saman", ExternalID: samanID, DisplayName: "삼안"},
|
||||
{ID: "works-hanmac", ExternalID: hanmacID, DisplayName: "한맥기술"},
|
||||
{
|
||||
ID: "works-rnd-saman",
|
||||
ExternalID: changedID,
|
||||
DisplayName: "삼안기술개발센터(조직도용)",
|
||||
},
|
||||
}
|
||||
|
||||
items := compareWorksmobileGroups(localTenants, remoteGroups, false)
|
||||
itemsByBaronID := map[string]WorksmobileComparisonItem{}
|
||||
for _, item := range items {
|
||||
itemsByBaronID[item.BaronID] = item
|
||||
}
|
||||
|
||||
require.Equal(t, "needs_update", itemsByBaronID[changedID].Status)
|
||||
require.Equal(t, "missing_in_worksmobile", itemsByBaronID[hanmacOnlyID].Status)
|
||||
require.Equal(t, "missing_in_worksmobile", itemsByBaronID[baronOnlyID].Status)
|
||||
}
|
||||
|
||||
func TestCompareWorksmobileGroupsDoesNotMatchBaronGroupOrganizationInGPDTDCDomain(t *testing.T) {
|
||||
t.Setenv("GPDTDC_DOMAIN_ID", "1003")
|
||||
t.Setenv("BARONGROUP_DOMAIN_ID", "1004")
|
||||
rootID := "038326b6-954a-48a7-a85f-efd83f62b82a"
|
||||
baronGroupID := "96369f12-6b66-4b2a-a916-d1c99d326f02"
|
||||
orgID := "32464fd6-da51-473f-844a-ab88603ad1f0"
|
||||
localTenants := []domain.Tenant{
|
||||
{ID: rootID, Slug: HanmacFamilyTenantSlug, Name: "한맥가족", Type: domain.TenantTypeCompanyGroup},
|
||||
{ID: baronGroupID, Slug: "baron-group", Name: "바론그룹", Type: domain.TenantTypeCompanyGroup, ParentID: &rootID},
|
||||
{ID: orgID, Slug: "rnd-baron", Name: "바론기술개발센터(조직도용)", Type: domain.TenantTypeOrganization, ParentID: &baronGroupID},
|
||||
}
|
||||
remoteGroups := []WorksmobileRemoteGroup{
|
||||
{
|
||||
ID: "works-rnd-baron-gpdtdc",
|
||||
ExternalID: orgID,
|
||||
DisplayName: "바론기술개발센터(조직도용)",
|
||||
DomainID: 1003,
|
||||
DomainName: "총괄기획&기술개발센터",
|
||||
},
|
||||
}
|
||||
|
||||
items := compareWorksmobileGroups(localTenants, remoteGroups, false)
|
||||
|
||||
require.Len(t, items, 1)
|
||||
require.Equal(t, orgID, items[0].BaronID)
|
||||
require.Equal(t, "missing_in_worksmobile", items[0].Status)
|
||||
require.Empty(t, items[0].WorksmobileID)
|
||||
}
|
||||
|
||||
func TestCompareWorksmobileGroupsMatchesBaronGroupOrganizationInBaronGroupDomain(t *testing.T) {
|
||||
t.Setenv("GPDTDC_DOMAIN_ID", "1003")
|
||||
t.Setenv("BARONGROUP_DOMAIN_ID", "1004")
|
||||
rootID := "038326b6-954a-48a7-a85f-efd83f62b82a"
|
||||
baronGroupID := "96369f12-6b66-4b2a-a916-d1c99d326f02"
|
||||
orgID := "32464fd6-da51-473f-844a-ab88603ad1f0"
|
||||
localTenants := []domain.Tenant{
|
||||
{ID: rootID, Slug: HanmacFamilyTenantSlug, Name: "한맥가족", Type: domain.TenantTypeCompanyGroup},
|
||||
{ID: baronGroupID, Slug: "baron-group", Name: "바론그룹", Type: domain.TenantTypeCompanyGroup, ParentID: &rootID},
|
||||
{ID: orgID, Slug: "rnd-baron", Name: "바론기술개발센터(조직도용)", Type: domain.TenantTypeOrganization, ParentID: &baronGroupID},
|
||||
}
|
||||
remoteGroups := []WorksmobileRemoteGroup{
|
||||
{
|
||||
ID: "works-rnd-baron",
|
||||
ExternalID: orgID,
|
||||
DisplayName: "바론기술개발센터(조직도용)",
|
||||
DomainID: 1004,
|
||||
DomainName: "바론그룹",
|
||||
},
|
||||
}
|
||||
|
||||
diffOnly := compareWorksmobileGroups(localTenants, remoteGroups, false)
|
||||
all := compareWorksmobileGroups(localTenants, remoteGroups, true)
|
||||
|
||||
require.Empty(t, diffOnly)
|
||||
require.Len(t, all, 1)
|
||||
require.Equal(t, orgID, all[0].BaronID)
|
||||
require.Equal(t, "matched", all[0].Status)
|
||||
require.Equal(t, int64(1004), all[0].WorksmobileDomainID)
|
||||
}
|
||||
|
||||
func TestWorksmobileSyncServiceRejectsDomainCompanyOrgUnitSync(t *testing.T) {
|
||||
@@ -733,6 +884,108 @@ func TestWorksmobileSyncServiceTreatsHanmacFamilyChildCompaniesAsDomainRoots(t *
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorksmobileSyncServiceUsesBaronGroupDomainForBaronGroupChildOrganization(t *testing.T) {
|
||||
t.Setenv("GPDTDC_DOMAIN_ID", "1003")
|
||||
t.Setenv("BARONGROUP_DOMAIN_ID", "1004")
|
||||
rootID := "038326b6-954a-48a7-a85f-efd83f62b82a"
|
||||
baronGroupID := "96369f12-6b66-4b2a-a916-d1c99d326f02"
|
||||
orgID := "32464fd6-da51-473f-844a-ab88603ad1f0"
|
||||
root := domain.Tenant{
|
||||
ID: rootID,
|
||||
Slug: HanmacFamilyTenantSlug,
|
||||
Name: "한맥가족",
|
||||
Type: domain.TenantTypeCompanyGroup,
|
||||
}
|
||||
baronGroup := domain.Tenant{
|
||||
ID: baronGroupID,
|
||||
Slug: "baron-group",
|
||||
Name: "바론그룹",
|
||||
Type: domain.TenantTypeCompanyGroup,
|
||||
ParentID: &rootID,
|
||||
}
|
||||
organization := domain.Tenant{
|
||||
ID: orgID,
|
||||
Slug: "rnd-baron",
|
||||
Name: "바론기술개발센터(조직도용)",
|
||||
Type: domain.TenantTypeOrganization,
|
||||
ParentID: &baronGroupID,
|
||||
}
|
||||
outboxRepo := &fakeWorksmobileOutboxRepo{}
|
||||
service := NewWorksmobileSyncService(
|
||||
&fakeWorksmobileTenantService{
|
||||
tenants: map[string]domain.Tenant{
|
||||
root.ID: root,
|
||||
baronGroup.ID: baronGroup,
|
||||
organization.ID: organization,
|
||||
},
|
||||
list: []domain.Tenant{root, baronGroup, organization},
|
||||
},
|
||||
&fakeWorksmobileUserRepo{},
|
||||
outboxRepo,
|
||||
nil,
|
||||
)
|
||||
|
||||
item, err := service.EnqueueOrgUnitSync(context.Background(), rootID, organization.ID)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, item)
|
||||
require.Len(t, outboxRepo.created, 1)
|
||||
request := outboxRepo.created[0].Payload["request"].(WorksmobileOrgUnitPayload)
|
||||
require.Equal(t, int64(1004), request.DomainID)
|
||||
require.Equal(t, "rnd-baron@brsw.kr", request.Email)
|
||||
}
|
||||
|
||||
func TestWorksmobileSyncServiceUsesGPDTDCDomainForGPDTDCChildOrganization(t *testing.T) {
|
||||
t.Setenv("GPDTDC_DOMAIN_ID", "1003")
|
||||
t.Setenv("BARONGROUP_DOMAIN_ID", "1004")
|
||||
rootID := "038326b6-954a-48a7-a85f-efd83f62b82a"
|
||||
gpdtdcID := "5530ca6e-c5e6-4bf0-84d6-76c6a8fb70ee"
|
||||
orgID := "gpdtdc-child-organization"
|
||||
root := domain.Tenant{
|
||||
ID: rootID,
|
||||
Slug: HanmacFamilyTenantSlug,
|
||||
Name: "한맥가족",
|
||||
Type: domain.TenantTypeCompanyGroup,
|
||||
}
|
||||
gpdtdc := domain.Tenant{
|
||||
ID: gpdtdcID,
|
||||
Slug: "gpdtdc",
|
||||
Name: "총괄기획&기술개발센터",
|
||||
Type: domain.TenantTypeOrganization,
|
||||
ParentID: &rootID,
|
||||
}
|
||||
organization := domain.Tenant{
|
||||
ID: orgID,
|
||||
Slug: "planning",
|
||||
Name: "기획",
|
||||
Type: domain.TenantTypeOrganization,
|
||||
ParentID: &gpdtdcID,
|
||||
}
|
||||
outboxRepo := &fakeWorksmobileOutboxRepo{}
|
||||
service := NewWorksmobileSyncService(
|
||||
&fakeWorksmobileTenantService{
|
||||
tenants: map[string]domain.Tenant{
|
||||
root.ID: root,
|
||||
gpdtdc.ID: gpdtdc,
|
||||
organization.ID: organization,
|
||||
},
|
||||
list: []domain.Tenant{root, gpdtdc, organization},
|
||||
},
|
||||
&fakeWorksmobileUserRepo{},
|
||||
outboxRepo,
|
||||
nil,
|
||||
)
|
||||
|
||||
item, err := service.EnqueueOrgUnitSync(context.Background(), rootID, organization.ID)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, item)
|
||||
require.Len(t, outboxRepo.created, 1)
|
||||
request := outboxRepo.created[0].Payload["request"].(WorksmobileOrgUnitPayload)
|
||||
require.Equal(t, int64(1003), request.DomainID)
|
||||
require.Equal(t, "planning@baroncs.co.kr", request.Email)
|
||||
}
|
||||
|
||||
func TestWorksmobileDomainClassificationUsesAncestorCompanyForGPDTDCOrganization(t *testing.T) {
|
||||
t.Setenv("GPDTDC_DOMAIN_ID", "1003")
|
||||
rootID := "root-tenant"
|
||||
|
||||
Reference in New Issue
Block a user