diff --git a/core/src/test/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImplTests.java b/core/src/test/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImplTests.java index d3835ea81b..f5ee43d566 100644 --- a/core/src/test/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImplTests.java +++ b/core/src/test/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImplTests.java @@ -233,4 +233,47 @@ public class RoleHierarchyImplTests { roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities3)).isTrue(); } + + // gh-6954 + @Test + public void testJavadoc() { + List flatAuthorities = AuthorityUtils.createAuthorityList( + "ROLE_A"); + List allAuthorities = AuthorityUtils.createAuthorityList( + "ROLE_A", "ROLE_B", "ROLE_AUTHENTICATED", "ROLE_UNAUTHENTICATED"); + RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl(); + roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\n" + + "ROLE_B > ROLE_AUTHENTICATED\n" + + "ROLE_AUTHENTICATED > ROLE_UNAUTHENTICATED"); + + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)).containsExactlyInAnyOrderElementsOf(allAuthorities); + } + + // gh-6954 + @Test + public void testInterfaceJavadoc() { + List flatAuthorities = AuthorityUtils.createAuthorityList( + "ROLE_HIGHEST"); + List allAuthorities = AuthorityUtils.createAuthorityList( + "ROLE_HIGHEST", "ROLE_HIGHER", "ROLE_LOW", "ROLE_LOWER"); + RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl(); + roleHierarchyImpl.setHierarchy("ROLE_HIGHEST > ROLE_HIGHER\n" + + "ROLE_HIGHER > ROLE_LOW\n" + + "ROLE_LOW > ROLE_LOWER"); + + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)).containsExactlyInAnyOrderElementsOf(allAuthorities); + } + + // gh-6954 + @Test + public void singleLineLargeHierarchy() { + List flatAuthorities = AuthorityUtils.createAuthorityList( + "ROLE_HIGHEST"); + List allAuthorities = AuthorityUtils.createAuthorityList( + "ROLE_HIGHEST", "ROLE_HIGHER", "ROLE_LOW", "ROLE_LOWER"); + RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl(); + roleHierarchyImpl.setHierarchy("ROLE_HIGHEST > ROLE_HIGHER > ROLE_LOW > ROLE_LOWER"); + + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)).containsExactlyInAnyOrderElementsOf(allAuthorities); + } }