From 1f7ba47ce9298950c02b88050207112e25b62180 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Fri, 7 Jun 2019 10:59:42 -0500 Subject: [PATCH] Test Javadoc for RoleHiearchy Issue gh-6954 --- .../RoleHierarchyImplTests.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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); + } }