From fb44b7c59ea6ae429e270b8e24ff9c49c7146701 Mon Sep 17 00:00:00 2001 From: Eric Leung Date: Fri, 6 Oct 2023 15:31:56 -0400 Subject: [PATCH] [ELY-2621] Add a test that makes use of the RoleMapper#or method to RoleMappingTest --- .../security/authz/RoleMappingTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java b/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java index 22b526d1cb6..3cec301e615 100644 --- a/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java +++ b/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java @@ -294,6 +294,41 @@ public void testIntersectionMappedRoles() { assertEquals(1, count); } + @Test + public void testUnionMappedRoles() { + Roles roles = createRoles("foo", "joe"); + + Map> mappingMap1 = new HashMap<>(); + mappingMap1.put("foo", createSet("bar", "role")); + + RoleMapper mapper1 = new MappedRoleMapper.Builder() + .setRoleMap(mappingMap1).build(); + + Map> mappingMap2 = new HashMap<>(); + mappingMap2.put("foo", createSet("bar", "test")); + + RoleMapper mapper2 = new MappedRoleMapper.Builder() + .setRoleMap(mappingMap2).build(); + + RoleMapper mapper3 = mapper1.or(mapper2); + + Roles mappedRoles = mapper3.mapRoles(roles); + + assertTrue(mappedRoles.contains("bar")); + assertTrue(mappedRoles.contains("role")); + assertTrue(mappedRoles.contains("test")); + assertFalse(mappedRoles.contains("foo")); + assertFalse(mappedRoles.contains("joe")); + + Iterator iterator = mappedRoles.iterator(); + int count = 0; + while (iterator.hasNext()) { + iterator.next(); + count++; + } + assertEquals(3, count); + } + private Set createSet(String... values) { HashSet set = new HashSet<>(); for (String s : values) set.add(s);