Search in sources :

Example 21 with IamPrincipalPermission

use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.

the class IamPrincipalPermissionServiceTest method testGrantIamPermissionIfRoleIsNotPresentByRoleId.

@Test(expected = ApiException.class)
public void testGrantIamPermissionIfRoleIsNotPresentByRoleId() {
    IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
    iamPrincipalPermission.setIamPrincipalArn("arn");
    iamPrincipalPermission.setRoleId("roleId");
    Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.empty());
    Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.empty());
    iamPrincipalPermissionService.grantIamPrincipalPermission("boxId", iamPrincipalPermission, "user", OffsetDateTime.MAX);
}
Also used : IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Example 22 with IamPrincipalPermission

use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.

the class IamPrincipalPermissionServiceTest method testIamPrincipalPermissionUpdateWhenIamRoleIsNotPresent.

@Test(expected = ApiException.class)
public void testIamPrincipalPermissionUpdateWhenIamRoleIsNotPresent() {
    IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
    iamPrincipalPermission.setIamPrincipalArn("arn");
    Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.empty());
    iamPrincipalPermissionService.updateIamPrincipalPermission("boxId", iamPrincipalPermission, "user", OffsetDateTime.MAX);
}
Also used : IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Example 23 with IamPrincipalPermission

use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.

the class IamPrincipalPermissionServiceTest method testRevokePermissionWhenIamRoleIsPresent.

@Test
public void testRevokePermissionWhenIamRoleIsPresent() {
    IamPrincipalPermission iamPrincipalPermission = Mockito.mock(IamPrincipalPermission.class);
    Mockito.when(iamPrincipalPermission.getIamPrincipalArn()).thenReturn("arn");
    AwsIamRoleRecord awsIamRoleRecord = Mockito.mock(AwsIamRoleRecord.class);
    Mockito.when(awsIamRoleRecord.getId()).thenReturn("id");
    Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.of(awsIamRoleRecord));
    iamPrincipalPermissionService.revokeIamPrincipalPermission("boxId", iamPrincipalPermission);
    Mockito.verify(awsIamRoleDao).deleteIamRolePermission("boxId", "id");
}
Also used : AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Example 24 with IamPrincipalPermission

use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.

the class IamPrincipalPermissionServiceTest method testGetIamPrincipalPermissionsWhenIamRoleIsPresent.

@Test
public void testGetIamPrincipalPermissionsWhenIamRoleIsPresent() {
    List<AwsIamRolePermissionRecord> awsIamRolePermissionRecords = new ArrayList<>();
    AwsIamRolePermissionRecord awsIamRolePermissionRecord = new AwsIamRolePermissionRecord().setId("id").setCreatedBy("createdBy").setLastUpdatedBy("lastUpdatedBy").setRoleId("roleId").setCreatedTs(OffsetDateTime.MAX).setLastUpdatedTs(OffsetDateTime.MAX);
    awsIamRolePermissionRecords.add(awsIamRolePermissionRecord);
    AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord().setAwsIamRoleArn("awsIamRoleArn");
    Mockito.when(awsIamRoleDao.getIamRolePermissions("boxId")).thenReturn(awsIamRolePermissionRecords);
    Mockito.when(awsIamRoleDao.getIamRoleById(Mockito.anyString())).thenReturn(Optional.of(awsIamRoleRecord));
    Set<IamPrincipalPermission> boxIds = iamPrincipalPermissionService.getIamPrincipalPermissions("boxId");
    Assert.assertTrue(boxIds.size() == 1);
    boxIds.forEach(iamPrincipalPermission -> {
        Assert.assertEquals("id", iamPrincipalPermission.getId());
        Assert.assertEquals("lastUpdatedBy", iamPrincipalPermission.getLastUpdatedBy());
        Assert.assertEquals("createdBy", iamPrincipalPermission.getCreatedBy());
        Assert.assertEquals("roleId", iamPrincipalPermission.getRoleId());
        Assert.assertEquals("awsIamRoleArn", iamPrincipalPermission.getIamPrincipalArn());
        Assert.assertEquals(OffsetDateTime.MAX, iamPrincipalPermission.getCreatedTs());
        Assert.assertEquals(OffsetDateTime.MAX, iamPrincipalPermission.getLastUpdatedTs());
    });
}
Also used : ArrayList(java.util.ArrayList) AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) AwsIamRolePermissionRecord(com.nike.cerberus.record.AwsIamRolePermissionRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Example 25 with IamPrincipalPermission

use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.

the class IamPrincipalPermissionService method getIamPrincipalPermissions.

public Set<IamPrincipalPermission> getIamPrincipalPermissions(final String safeDepositBoxId) {
    final Set<IamPrincipalPermission> iamPrincipalPermissionSet = Sets.newHashSet();
    final List<AwsIamRolePermissionRecord> permissionRecords = awsIamRoleDao.getIamRolePermissions(safeDepositBoxId);
    permissionRecords.forEach(r -> {
        final Optional<AwsIamRoleRecord> iamRoleRecord = awsIamRoleDao.getIamRoleById(r.getAwsIamRoleId());
        if (iamRoleRecord.isPresent()) {
            final IamPrincipalPermission permission = new IamPrincipalPermission();
            permission.setId(r.getId());
            permission.setIamPrincipalArn(iamRoleRecord.get().getAwsIamRoleArn());
            permission.setRoleId(r.getRoleId());
            permission.setCreatedBy(r.getCreatedBy());
            permission.setLastUpdatedBy(r.getLastUpdatedBy());
            permission.setCreatedTs(r.getCreatedTs());
            permission.setLastUpdatedTs(r.getLastUpdatedTs());
            iamPrincipalPermissionSet.add(permission);
        }
    });
    return iamPrincipalPermissionSet;
}
Also used : AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) AwsIamRolePermissionRecord(com.nike.cerberus.record.AwsIamRolePermissionRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission)

Aggregations

IamPrincipalPermission (com.nike.cerberus.domain.IamPrincipalPermission)25 Test (org.junit.Test)23 HashSet (java.util.HashSet)12 AwsIamRoleRecord (com.nike.cerberus.record.AwsIamRoleRecord)10 AwsIamRolePermissionRecord (com.nike.cerberus.record.AwsIamRolePermissionRecord)8 SafeDepositBoxV2 (com.nike.cerberus.domain.SafeDepositBoxV2)6 UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)6 Role (com.nike.cerberus.domain.Role)5 OffsetDateTime (java.time.OffsetDateTime)3 IamRolePermission (com.nike.cerberus.domain.IamRolePermission)2 SDBMetadata (com.nike.cerberus.domain.SDBMetadata)2 SafeDepositBoxV1 (com.nike.cerberus.domain.SafeDepositBoxV1)2 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1