RoleExtractor { public Set<String> extractRoles(HttpServerRequest request) { return extractRoles(request.headers()); } RoleExtractor(String rolePattern);  RoleExtractor(); Set<String> extractRoles(HttpServerRequest request); Set<String> extractRoles(MultiMap headers); final static String groupHeader; final static String roleHeader; }
@Test public void testExtractRolesNotMatchingPattern(TestContext context) throws Exception { context.assertNull(roleExtractor.extractRoles(new TestHttpServerRequest( new CaseInsensitiveHeaders())), "No roles should have been found and returned as null"); context.assertTrue(roleExtractor.extractRoles(new TestHttpServerRequest( buildGroupHeaders("grp_1,grp_2,grp_3"))).isEmpty(), "An empty set of roles should have been returned"); context.assertTrue(roleExtractor.extractRoles(new TestHttpServerRequest( buildRoleHeaders("grp_1,grp_2,grp_3"))).isEmpty(), "An empty set of roles should have been returned"); context.assertTrue(roleExtractor.extractRoles(new TestHttpServerRequest( buildGroupHeaders(""))).isEmpty(), "An empty set of roles should have been returned"); context.assertTrue(roleExtractor.extractRoles(new TestHttpServerRequest( buildRoleHeaders(""))).isEmpty(), "An empty set of roles should have been returned"); }
@Test public void testExtractRolesMatchingPattern(TestContext context) throws Exception { context.assertFalse(roleExtractor.extractRoles(new TestHttpServerRequest( buildGroupHeaders("grp_1,grp_2,grp_3,z-gateleen-grp_4"))).isEmpty(), "A non-empty set of roles should have been returned"); context.assertFalse(roleExtractor.extractRoles(new TestHttpServerRequest( buildRoleHeaders("grp_1,grp_2,grp_3,z-gateleen-grp_4"))).isEmpty(), "A non-empty set of roles should have been returned"); Set<String> groupRoles = roleExtractor.extractRoles(new TestHttpServerRequest( buildGroupHeaders("z-gateleen-abc,z-gateleen-xyz,grp_3,z-gateleen-grp_4,gateleen-grp_5"))); context.assertEquals(3, groupRoles.size()); context.assertTrue(groupRoles.contains("abc")); context.assertTrue(groupRoles.contains("xyz")); context.assertTrue(groupRoles.contains("grp_4")); context.assertFalse(groupRoles.contains("grp_3")); context.assertFalse(groupRoles.contains("gateleen-grp_5")); Set<String> roleRoles = roleExtractor.extractRoles(new TestHttpServerRequest( buildRoleHeaders("z-gateleen-abc,z-gateleen-xyz,grp_3,z-gateleen-grp_4,gateleen-grp_5"))); context.assertEquals(3, roleRoles.size()); context.assertTrue(roleRoles.contains("abc")); context.assertTrue(roleRoles.contains("xyz")); context.assertTrue(roleRoles.contains("grp_4")); context.assertFalse(roleRoles.contains("grp_3")); context.assertFalse(roleRoles.contains("gateleen-grp_5")); }
@Test public void testExtractRolesCaseInsitivity(TestContext context) throws Exception { Set<String> groupRoles = roleExtractor.extractRoles(new TestHttpServerRequest( buildGroupHeaders("z-gateleen-abC,z-gateleen-XYZ,z-gateleen-DeF,z-gateleen-ghi"))); context.assertEquals(4, groupRoles.size()); context.assertTrue(groupRoles.contains("abc")); context.assertTrue(groupRoles.contains("xyz")); context.assertTrue(groupRoles.contains("def")); context.assertTrue(groupRoles.contains("ghi")); Set<String> roleRoles = roleExtractor.extractRoles(new TestHttpServerRequest( buildRoleHeaders("z-gateleen-abC,z-gateleen-XYZ,z-gateleen-DeF,z-gateleen-ghi"))); context.assertEquals(4, roleRoles.size()); context.assertTrue(roleRoles.contains("abc")); context.assertTrue(roleRoles.contains("xyz")); context.assertTrue(roleRoles.contains("def")); context.assertTrue(roleRoles.contains("ghi")); }