Skip to content

Commit

Permalink
Fixes tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>
  • Loading branch information
mdanish98 committed Oct 24, 2024
1 parent d61663f commit 75b8542
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
/**
* Tests the behaviour of {@link KeycloakRoleProvider}
*
* @author danish
*/
public class TestKeycloakRoleProvider {

Expand Down Expand Up @@ -70,9 +69,13 @@ public void getRoles_whenBothRealmAndResourceRolesPresent() {
Map<String, Collection<String>> realmAccess = new HashMap<>();
realmAccess.put("roles", Arrays.asList("ROLE_USER", "ROLE_ADMIN"));

Map<String, Collection<String>> resourceAccess = new HashMap<>();
resourceAccess.put("client1", Arrays.asList("ROLE_SUPERUSER", "ROLE_ADMIN"));
resourceAccess.put("client2", Arrays.asList("ROLE_SUPPORT"));
Map<String, Map<String, Collection<String>>> resourceAccess = new HashMap<>();
resourceAccess.put("client1", new HashMap<>() {{
put("roles", Arrays.asList("ROLE_SUPERUSER", "ROLE_ADMIN"));
}});
resourceAccess.put("client2", new HashMap<>() {{
put("roles", Arrays.asList("ROLE_SUPPORT"));
}});

when(jwt.hasClaim("realm_access")).thenReturn(true);
when(jwt.hasClaim("resource_access")).thenReturn(true);
Expand Down Expand Up @@ -107,8 +110,10 @@ public void getRoles_whenOnlyRealmRolesPresent() {

@Test
public void getRoles_whenOnlyResourceRolesPresent() {
Map<String, Collection<String>> resourceAccess = new HashMap<>();
resourceAccess.put("client1", Arrays.asList("ROLE_SUPERUSER", "ROLE_SUPPORT"));
Map<String, Map<String, Collection<String>>> resourceAccess = new HashMap<>();
resourceAccess.put("client1", new HashMap<>() {{
put("roles", Arrays.asList("ROLE_SUPERUSER", "ROLE_SUPPORT"));
}});

when(jwt.hasClaim("realm_access")).thenReturn(true);
when(jwt.hasClaim("resource_access")).thenReturn(true);
Expand Down Expand Up @@ -146,8 +151,10 @@ public void getRoles_whenJwtIsNull() {

@Test
public void getRoles_whenRealmAccessNotPresentButResourceAccessPresent() {
Map<String, Collection<String>> resourceAccess = new HashMap<>();
resourceAccess.put("client1", Arrays.asList("ROLE_SUPPORT", "ROLE_USER"));
Map<String, Map<String, Collection<String>>> resourceAccess = new HashMap<>();
resourceAccess.put("client1", new HashMap<>() {{
put("roles", Arrays.asList("ROLE_SUPPORT", "ROLE_USER"));
}});

when(jwt.hasClaim("realm_access")).thenReturn(false);
when(jwt.hasClaim("resource_access")).thenReturn(true);
Expand Down Expand Up @@ -186,3 +193,4 @@ public void getRoles_whenClaimNotPresent() {
assertTrue(roles.isEmpty());
}
}

0 comments on commit 75b8542

Please sign in to comment.