Skip to content
Permalink
Browse files
Merge pull request #11 from myrle-krantz/develop
roles sorted by identifier.
  • Loading branch information
myrle-krantz committed May 3, 2017
2 parents debe7f9 + cdd7a89 commit 3644db1b41243e135457e0b643dd50c3333cf057
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 31 deletions.
@@ -123,7 +123,7 @@ IdentityManager getTestSubject()
return identityManager;
}

AutoUserContext enableAndLoginAdmin() throws InterruptedException {
AutoUserContext loginAdmin() throws InterruptedException {
final Authentication adminAuthentication =
getTestSubject().login(ADMIN_IDENTIFIER, TestEnvironment.encodePassword(ADMIN_PASSWORD));
Assert.assertNotNull(adminAuthentication);
@@ -143,7 +143,7 @@ AutoUserContext enableAndLoginAdmin() throws InterruptedException {
*/
String createUserWithNonexpiredPassword(final String password, final String role) throws InterruptedException {
final String username = testEnvironment.generateUniqueIdentifer("Ahmes");
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
getTestSubject().createUser(new UserWithPassword(username, role, TestEnvironment.encodePassword(password)));

{
@@ -141,7 +141,7 @@ public void testApplicationPermissionUserApprovalProvisioning() throws Interrupt
final String user1id;
final String user2Password;
final String user2id;
try (final AutoUserContext ignored = enableAndLoginAdmin()) {
try (final AutoUserContext ignored = loginAdmin()) {
final String selfManagementRoleId = createSelfManagementRole();
final String roleManagementRoleId = createRoleManagementRole();

@@ -272,7 +272,7 @@ public void applicationIssuedRefreshTokenHappyCase() throws InterruptedException

final String userid;
final String userPassword;
try (final AutoUserContext ignored = enableAndLoginAdmin()) {
try (final AutoUserContext ignored = loginAdmin()) {
final String selfManagementRoleId = createRole(rolePermission, userPermission);

userPassword = RandomStringUtils.randomAlphanumeric(5);
@@ -40,13 +40,13 @@ public class TestAuthentication extends AbstractComponentTest {
//@Repeat(25)
public void testAdminLogin() throws InterruptedException {
//noinspection EmptyTryBlock
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
}
}

@Test
public void testAdminLogout() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
getTestSubject().logout();

try {
@@ -79,7 +79,7 @@ public void testAdminMissingTenantHeader() throws InterruptedException {

@Test()
public void testPermissionsCorrectInAdminToken() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final Authentication adminAuthentication =
getTestSubject().login(ADMIN_IDENTIFIER, TestEnvironment.encodePassword(ADMIN_PASSWORD));
Assert.assertNotNull(adminAuthentication);
@@ -101,7 +101,7 @@ public void testPermissionsCorrectInAdminToken() throws InterruptedException {

@Test()
public void testPermissionsCorrectInTokenWhenMultiplePermittableGroupsInRole() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final PermittableEndpoint horusEndpoint = buildPermittableEndpoint("horus");
final PermittableGroup horusGroup = buildPermittableGroup("horus_Group", horusEndpoint);
getTestSubject().createPermittableGroup(horusGroup);
@@ -37,7 +37,7 @@ public void testKeyRotation() throws InterruptedException {
final Anubis anubis = tenantApplicationSecurityEnvironment.getAnubis();

//noinspection EmptyTryBlock
try (final AutoUserContext ignored = enableAndLoginAdmin())
try (final AutoUserContext ignored = loginAdmin())
{
//Don't do anything yet.
}
@@ -37,7 +37,7 @@ public class TestPasswords extends AbstractComponentTest {
public void testAdminChangeUserPassword() throws InterruptedException {
final String username = createUserWithNonexpiredPassword(AHMES_PASSWORD, ADMIN_ROLE);

try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String newPassword = TestEnvironment.encodePassword(
AHMES_PASSWORD + "make_it_a_little_longer");

@@ -79,7 +79,7 @@ public void testAdminChangeUserPassword() throws InterruptedException {

@Test
public void testAdminChangeAdminPassword() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String newPassword = TestEnvironment.encodePassword(
ADMIN_PASSWORD + "make_it_a_little_longer");

@@ -149,15 +149,15 @@ public void testUserChangeOwnPasswordButNotAdminPassword() throws InterruptedExc
}

//noinspection EmptyTryBlock
try (final AutoUserContext ignored2 = enableAndLoginAdmin()) { //logging into admin with the old password should *not* fail.
try (final AutoUserContext ignored2 = loginAdmin()) { //logging into admin with the old password should *not* fail.
}
}
}

@Test(expected = IllegalArgumentException.class)
public void loginWithUnencodedPasswordShouldThrowIllegalArgumentException() throws InterruptedException {

try (final AutoUserContext ignored = enableAndLoginAdmin()) {
try (final AutoUserContext ignored = loginAdmin()) {
final String selfManagementRoleId = createSelfManagementRole();

final String userPassword = RandomStringUtils.randomAlphanumeric(5);
@@ -171,7 +171,7 @@ public void loginWithUnencodedPasswordShouldThrowIllegalArgumentException() thro
@Test
public void activatedAntonyPasswordDoesntExpire() throws InterruptedException {

try (final AutoUserContext ignored = enableAndLoginAdmin()) {
try (final AutoUserContext ignored = loginAdmin()) {
final Authentication adminAuthentication =
getTestSubject().login(ADMIN_IDENTIFIER, TestEnvironment.encodePassword(ADMIN_PASSWORD));
Assert.assertEquals(null, adminAuthentication.getPasswordExpiration());
@@ -180,7 +180,7 @@ public void activatedAntonyPasswordDoesntExpire() throws InterruptedException {

@Test
public void onlyAntonyCanSetAntonyPassword() throws InterruptedException {
try (final AutoUserContext ignored = enableAndLoginAdmin()) {
try (final AutoUserContext ignored = loginAdmin()) {

final String roleIdentifier = createRole(buildUserPermission(), buildSelfPermission(), buildRolePermission());
final String username = createUserWithNonexpiredPassword(AHMES_PASSWORD, roleIdentifier);
@@ -30,7 +30,7 @@
public class TestPermittableGroups extends AbstractComponentTest {
@Test
public void getPermittableGroups() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final PermittableGroup identityManagementPermittableGroup
= getTestSubject().getPermittableGroup(PermittableGroupIds.IDENTITY_MANAGEMENT);
Assert.assertNotNull(identityManagementPermittableGroup);
@@ -50,7 +50,7 @@ public void getPermittableGroups() throws InterruptedException {

@Test(expected = IllegalArgumentException.class)
public void createWithIllegalMethodThrows() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String identifier = testEnvironment.generateUniqueIdentifer("group");

final PermittableEndpoint permittableEndpoint = buildPermittableEndpoint();
@@ -64,7 +64,7 @@ public void createWithIllegalMethodThrows() throws InterruptedException {

@Test
public void create() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String identifier = testEnvironment.generateUniqueIdentifer("group");

final PermittableEndpoint permittableEndpoint = buildPermittableEndpoint();
@@ -44,7 +44,7 @@ public static void setup() throws Exception {

@Test(expected = InvalidTokenException.class)
public void adminLoginAccessTokenShouldTimeOut() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
Thread.sleep(TimeUnit.SECONDS.toMillis(ACCESS_TOKEN_TIME_TO_LIVE + 1));
getTestSubject().getUser(ADMIN_IDENTIFIER);
}
@@ -22,19 +22,58 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

import static io.mifos.identity.internal.util.IdentityConstants.SU_ROLE;

/**
* @author Myrle Krantz
*/
public class TestRoles extends AbstractComponentTest {
@Test
public void testRolesSortedAlphabetically() throws InterruptedException {
try (final AutoUserContext ignore = loginAdmin()) {
final Permission rolePermission = buildRolePermission();

final Role role1 = buildRole(testEnvironment.generateUniqueIdentifer("abba"), rolePermission);
final Role role2 = buildRole(testEnvironment.generateUniqueIdentifer("bubba"), rolePermission);
final Role role3 = buildRole(testEnvironment.generateUniqueIdentifer("c1"), rolePermission);
final Role role4 = buildRole(testEnvironment.generateUniqueIdentifer("calla"), rolePermission);
final Role role5 = buildRole(testEnvironment.generateUniqueIdentifer("uelf"), rolePermission);
final Role role6 = buildRole(testEnvironment.generateUniqueIdentifer("ulf"), rolePermission);

getTestSubject().createRole(role2);
getTestSubject().createRole(role1);
getTestSubject().createRole(role6);
getTestSubject().createRole(role4);
getTestSubject().createRole(role3);
getTestSubject().createRole(role5);

Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, role1.getIdentifier()));
Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, role2.getIdentifier()));
Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, role3.getIdentifier()));
Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, role4.getIdentifier()));
Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, role5.getIdentifier()));
Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, role6.getIdentifier()));

final List<Role> roles = getTestSubject().getRoles();
final List<String> idList = roles.stream().map(Role::getIdentifier).collect(Collectors.toList());
final List<String> sortedList = Arrays.asList(
role1.getIdentifier(),
role2.getIdentifier(),
role3.getIdentifier(),
role4.getIdentifier(),
role5.getIdentifier(),
role6.getIdentifier());
final List<String> filterOutIdsFromOtherTests = idList.stream().filter(sortedList::contains).collect(Collectors.toList());
Assert.assertEquals(sortedList, filterOutIdsFromOtherTests);
}
}

@Test
public void testCreateRole() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String roleIdentifier = generateRoleIdentifier();

final Permission rolePermission = buildRolePermission();
@@ -59,7 +98,7 @@ public void testCreateRole() throws InterruptedException {

@Test(expected = IllegalArgumentException.class)
public void shouldNotBeAbleToCreateRoleNamedDeactivated() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final Permission rolePermission = buildRolePermission();
final Role deactivated = buildRole("deactivated", rolePermission);

@@ -69,7 +108,7 @@ public void shouldNotBeAbleToCreateRoleNamedDeactivated() throws InterruptedExce

@Test
public void deleteRole() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String roleIdentifier = createRoleManagementRole();

final Role role = getTestSubject().getRole(roleIdentifier);
@@ -89,7 +128,7 @@ public void deleteRole() throws InterruptedException {

@Test(expected= NotFoundException.class)
public void deleteRoleThatDoesntExist() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String randomIdentifier = generateRoleIdentifier();

getTestSubject().deleteRole(randomIdentifier);
@@ -98,7 +137,7 @@ public void deleteRoleThatDoesntExist() throws InterruptedException {

@Test()
public void changeRole() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final String roleIdentifier = createRoleManagementRole();

final Role role = getTestSubject().getRole(roleIdentifier);
@@ -118,7 +157,7 @@ public void changeRole() throws InterruptedException {

@Test
public void testChangePharaohRoleFails() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final Role referenceRole = getTestSubject().getRole(SU_ROLE);
final Role roleChangeRequest = buildRole(SU_ROLE, buildSelfPermission());

@@ -138,7 +177,7 @@ public void testChangePharaohRoleFails() throws InterruptedException {
@Test
public void testDeletePharaohRoleFails() throws InterruptedException {

try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final Role adminRole = getTestSubject().getRole(ADMIN_ROLE);
try {
getTestSubject().deleteRole(ADMIN_ROLE);
@@ -41,7 +41,7 @@ public void testAddLogin() throws InterruptedException {

final String username = createUserWithNonexpiredPassword(AHMES_PASSWORD, ADMIN_ROLE);

try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final User user = getTestSubject().getUser(username);
Assert.assertNotNull(user);
Assert.assertEquals("Correct user identifier?", username, user.getIdentifier());
@@ -61,7 +61,7 @@ public void testAddLogin() throws InterruptedException {
Assert.assertTrue(found);
}

try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final List<User> users = getTestSubject().getUsers();
Assert.assertTrue(Helpers.instancePresent(users, User::getIdentifier, username));
Assert.assertTrue(Helpers.instancePresent(users, User::getIdentifier, "Ahmes_friend"));
@@ -118,7 +118,7 @@ public void testChangeAntonyRoleFails() throws InterruptedException {

@Test
public void testAdminProvisioning() throws InterruptedException {
try (final AutoUserContext ignore = enableAndLoginAdmin()) {
try (final AutoUserContext ignore = loginAdmin()) {
final List<Role> roleIdentifiers = getTestSubject().getRoles();
Assert.assertTrue(Helpers.instancePresent(roleIdentifiers, Role::getIdentifier, ADMIN_ROLE));

@@ -41,6 +41,7 @@ public RoleService(final Roles repository) {
public List<Role> findAll() {
return repository.getAll().stream()
.map(this::mapEntity)
.sorted((x, y) -> (x.getIdentifier().compareTo(y.getIdentifier())))
.collect(Collectors.toList());
}

0 comments on commit 3644db1

Please sign in to comment.