From bfe6164022e7001b6fee2dfc4f31fc55bb294df3 Mon Sep 17 00:00:00 2001 From: Eric Leung Date: Fri, 6 Oct 2023 16:06:18 -0400 Subject: [PATCH] [ELY-2620] Add a test that makes use of the RoleMapper#and 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 7bf83335c08..22b526d1cb6 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 @@ -259,6 +259,41 @@ public void testDifferenceRoles() { assertEquals(1, count); } + @Test + public void testIntersectionMappedRoles() { + 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.and(mapper2); + + Roles mappedRoles = mapper3.mapRoles(roles); + + assertTrue(mappedRoles.contains("bar")); + assertFalse(mappedRoles.contains("role")); + assertFalse(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(1, count); + } + private Set createSet(String... values) { HashSet set = new HashSet<>(); for (String s : values) set.add(s);