Skip to content

Commit 0735ac6

Browse files
authored
Update FedAuth test (#1452)
* reflect expected behavior in test * comment steps
1 parent 5e7d5ce commit 0735ac6

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

test/int/federated_auth_test.go

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var _ = Describe("AtlasFederatedAuth test", Label("AtlasFederatedAuth", "federat
2929
var originalIdp *admin.FederationIdentityProvider
3030

3131
resourceName := "fed-auth-test"
32+
newRoleMapName := "ako_team"
3233
ctx := context.Background()
3334

3435
BeforeEach(func() {
@@ -78,6 +79,7 @@ var _ = Describe("AtlasFederatedAuth test", Label("AtlasFederatedAuth", "federat
7879

7980
It("Should be able to update existing Organization's federations settings", func() {
8081
By("Creating a FederatedAuthConfig resource", func() {
82+
// Construct list of role mappings from pre-existing configuration
8183
atlasRoleMappings := originalConnectedOrgConfig.GetRoleMappings()
8284
roles := make([]akov2.RoleMapping, 0, len(atlasRoleMappings))
8385
for i := range atlasRoleMappings {
@@ -102,10 +104,11 @@ var _ = Describe("AtlasFederatedAuth test", Label("AtlasFederatedAuth", "federat
102104
}
103105
roles = append(roles, newRole)
104106
}
107+
// Add new role mapping
105108
roles = append(
106109
roles,
107110
akov2.RoleMapping{
108-
ExternalGroupName: "ako_team",
111+
ExternalGroupName: newRoleMapName,
109112
RoleAssignments: []akov2.RoleAssignment{
110113
{Role: "ORG_OWNER"},
111114
},
@@ -150,58 +153,15 @@ var _ = Describe("AtlasFederatedAuth test", Label("AtlasFederatedAuth", "federat
150153
fedAuth.Spec.DomainRestrictionEnabled = &originalConnectedOrgConfig.DomainRestrictionEnabled
151154
fedAuth.Spec.SSODebugEnabled = originalIdp.SsoDebugEnabled
152155
fedAuth.Spec.PostAuthRoleGrants = originalConnectedOrgConfig.GetPostAuthRoleGrants()
153-
fedAuth.Spec.RoleMappings = nil
154-
155-
if len(originalConnectedOrgConfig.GetRoleMappings()) > 0 {
156-
GinkgoWriter.Println("HAS ROLE MAPPINGS", len(originalConnectedOrgConfig.GetRoleMappings()), originalConnectedOrgConfig.GetRoleMappings()[0])
157-
roles := make([]akov2.RoleMapping, len(originalConnectedOrgConfig.GetRoleMappings()))
158-
159-
for _, roleMapping := range originalConnectedOrgConfig.GetRoleMappings() {
160-
assignments := make([]akov2.RoleAssignment, len(roleMapping.GetRoleAssignments()))
161-
for _, roleAssignment := range roleMapping.GetRoleAssignments() {
162-
var projectName string
163-
164-
if pID, ok := roleAssignment.GetGroupIdOk(); ok {
165-
project, _, err := atlasClient.ProjectsApi.GetProject(ctx, *pID).Execute()
166-
Expect(err).ToNot(HaveOccurred())
167-
Expect(project).NotTo(BeNil())
168-
169-
projectName = project.GetName()
170-
}
171-
172-
assignments = append(
173-
assignments,
174-
akov2.RoleAssignment{
175-
ProjectName: projectName,
176-
Role: roleAssignment.GetRole(),
177-
},
178-
)
179-
}
180-
181-
roles = append(
182-
roles,
183-
akov2.RoleMapping{
184-
ExternalGroupName: roleMapping.GetExternalGroupName(),
185-
RoleAssignments: assignments,
186-
},
187-
)
188-
}
189156

190-
fedAuth.Spec.RoleMappings = roles
191-
} else {
192-
roleMappings, _, err := atlasClient.FederatedAuthenticationApi.
193-
ListRoleMappings(ctx, originalFederationSettings.GetId(), orgID).
194-
Execute()
195-
Expect(err).ToNot(HaveOccurred())
196-
197-
for _, roleMapping := range roleMappings.GetResults() {
198-
GinkgoWriter.Println("DELETING ROLE MAPPING", roleMapping.GetId())
199-
_, err := atlasClient.FederatedAuthenticationApi.
200-
DeleteRoleMapping(ctx, originalFederationSettings.GetId(), roleMapping.GetId(), orgID).
201-
Execute()
202-
Expect(err).ToNot(HaveOccurred())
157+
// Delete role mapping added for test
158+
roleMappings := make([]akov2.RoleMapping, 0, len(fedAuth.Spec.RoleMappings))
159+
for _, roleMap := range fedAuth.Spec.RoleMappings {
160+
if roleMap.ExternalGroupName != newRoleMapName {
161+
roleMappings = append(roleMappings, roleMap)
203162
}
204163
}
164+
fedAuth.Spec.RoleMappings = roleMappings
205165

206166
Expect(k8sClient.Update(ctx, fedAuth)).NotTo(HaveOccurred())
207167
})

0 commit comments

Comments
 (0)