Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
astrozzc committed Jun 25, 2024
1 parent 6637ae9 commit aba92eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 5 additions & 7 deletions rbac/migration_tool/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ def migrate_role(role: Role):
# With the replicated role bindings algorithm, role bindings are scoped by group, so we need to add groups
# TODO: replace the hard coded groups
policies = role.policies.all()
groups = frozenset(
{
V1group(str(policy.group.uuid), frozenset(policy.group.principals.values_list("uuid", flat=True)))
for policy in policies
}
)
v1_role = dataclasses.replace(v1_role, groups=groups)
groups = set()
for policy in policies:
principals = [str(principal) for principal in policy.group.principals.values_list("uuid", flat=True)]
groups.add(V1group(str(policy.group.uuid), frozenset(principals)))
v1_role = dataclasses.replace(v1_role, groups=frozenset(groups))

# This is where we wire in the implementation we're using into the Migrator
v1_to_v2_mapping = shared_system_role_replicated_role_bindings_v1_to_v2_mapping
Expand Down
3 changes: 2 additions & 1 deletion tests/migration_tool/tests_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def setUp(self):
self.groupA21 = Group.objects.create(name="groupA21", tenant=self.tenant)
self.principal1 = Principal.objects.create(username="principal1", tenant=self.tenant)
self.principal2 = Principal.objects.create(username="principal2", tenant=self.tenant)
self.groupA21.principals.add(self.principal1, self.principal2)
self.policyA21 = Policy.objects.create(name="System PolicyA21", group=self.groupA21, tenant=self.tenant)
self.policyA21.roles.add(self.roleA2)
self.policyA21.save()
Expand All @@ -82,5 +83,5 @@ def test_migration_of_roles(self, logger_mock):
migrate_roles(**kwargs)
self.assertEqual(
len(logger_mock.info.call_args_list),
16,
18,
)

0 comments on commit aba92eb

Please sign in to comment.