Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from myrle-krantz/develop
Browse files Browse the repository at this point in the history
roles sorted by identifier.
  • Loading branch information
myrle-krantz committed May 3, 2017
2 parents debe7f9 + cdd7a89 commit 3644db1
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 31 deletions.
4 changes: 2 additions & 2 deletions component-test/src/main/java/AbstractComponentTest.java
Expand Up @@ -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);
Expand All @@ -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)));

{
Expand Down
4 changes: 2 additions & 2 deletions component-test/src/main/java/TestApplications.java
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions component-test/src/main/java/TestAuthentication.java
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion component-test/src/main/java/TestKeyRotation.java
Expand Up @@ -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.
}
Expand Down
12 changes: 6 additions & 6 deletions component-test/src/main/java/TestPasswords.java
Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions component-test/src/main/java/TestPermittableGroups.java
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion component-test/src/main/java/TestRefreshToken.java
Expand Up @@ -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);
}
Expand Down
57 changes: 48 additions & 9 deletions component-test/src/main/java/TestRoles.java
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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());

Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions component-test/src/main/java/TestUsers.java
Expand Up @@ -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());
Expand All @@ -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"));
Expand Down Expand Up @@ -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));

Expand Down
Expand Up @@ -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());
}

Expand Down

0 comments on commit 3644db1

Please sign in to comment.