Skip to content

Commit

Permalink
Added tests for roles being named close to default-roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasvoelcker committed Dec 7, 2023
1 parent 1e844f4 commit 34f6d9d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1083,21 +1083,17 @@ void shouldCreateUserAndRemoveDefaultRole() throws IOException {
}
}

@SuppressWarnings("SpringJavaAutowiredMembersInspection")
@Nested
@Order(65)
@TestPropertySource(properties = {
"import.remote-state.enabled=false"
})
class NotDeletingDefaultRolesNotMentioned {

@Autowired
public RealmImportService realmImportService;
class ImportRemoteStateDisabled {

@Test
@Order(0)
void shouldNotDeleteUnmentionedDefaultRoles() throws IOException {
doImport("65_import_realm_without_mentioned_default_roles.json", realmImportService);
doImport("65_import_realm_without_mentioned_default_roles.json");

String REALM_NAME = "realmWithoutMentionedDefaultRoles";

Expand All @@ -1112,5 +1108,40 @@ void shouldNotDeleteUnmentionedDefaultRoles() throws IOException {
assertThat(realmRole.getClientRole(), is(false));
assertThat(realmRole.getDescription(), is("${role_default-roles}"));
}

@Test
@Order(1)
void shouldContainFakeDefaultRoles() throws IOException {
doImport("66_import_realm_with_fake_default_roles.json");

String REALM_NAME = "realmWithFakeDefaultRoles";

RealmRepresentation realm = keycloakProvider.getInstance().realm(REALM_NAME).partialExport(true, true);

assertThat(realm.getRealm(), is(REALM_NAME));

RoleRepresentation realmRole = keycloakRepository.getRealmRole(realm, "default-roles-fake");

assertThat(realmRole.getName(), is("default-roles-fake"));
assertThat(realmRole.isComposite(), is(false));
assertThat(realmRole.getClientRole(), is(false));
assertThat(realmRole.getDescription(), is("no default roles description"));
}

@Test
@Order(2)
void shouldHaveDeletedFakeDefaultRoles() throws IOException {
doImport("67_import_realm_without_fake_default_roles.json");

String REALM_NAME = "realmWithFakeDefaultRoles";

RealmRepresentation realm = keycloakProvider.getInstance().realm(REALM_NAME).partialExport(true, true);

assertThat(realm.getRealm(), is(REALM_NAME));

RoleRepresentation realmRole = keycloakRepository.getRealmRole(realm, "default-roles-fake");

assertThat(realmRole, nullValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"enabled": true,
"realm": "realmWithFakeDefaultRoles",
"roles": {
"realm": [
{
"name": "default-roles-fake",
"description": "no default roles description",
"composite": false,
"clientRole": false,
"containerId": "realmWithoutMentionedDefaultRoles",
"attributes": {}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"enabled": true,
"realm": "realmWithFakeDefaultRoles",
"roles": {
"realm": [
]
}
}

0 comments on commit 34f6d9d

Please sign in to comment.