Search in sources :

Example 1 with SafeDepositBoxSummary

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

the class SafeDepositBoxControllerV2Test method testGetSafeDepositBoxes.

@Test
public void testGetSafeDepositBoxes() {
    CerberusPrincipal cerberusPrincipal = Mockito.mock(CerberusPrincipal.class);
    SafeDepositBoxSummary safeDepositBoxSummary = Mockito.mock(SafeDepositBoxSummary.class);
    List<SafeDepositBoxSummary> safeDepositBoxSummaries = new ArrayList<>();
    safeDepositBoxSummaries.add(safeDepositBoxSummary);
    Mockito.when(safeDepositBoxService.getAssociatedSafeDepositBoxes(cerberusPrincipal)).thenReturn(safeDepositBoxSummaries);
    List<SafeDepositBoxSummary> actualSafeDepositBoSummaries = safeDepositBoxControllerV2.getSafeDepositBoxes(cerberusPrincipal);
    Assert.assertSame(safeDepositBoxSummaries, actualSafeDepositBoSummaries);
    Assert.assertEquals(safeDepositBoxSummaries, actualSafeDepositBoSummaries);
}
Also used : ArrayList(java.util.ArrayList) SafeDepositBoxSummary(com.nike.cerberus.domain.SafeDepositBoxSummary) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) Test(org.junit.Test)

Example 2 with SafeDepositBoxSummary

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

the class SafeDepositBoxServiceTest method test_that_getAssociatedSafeDepositBoxes_checks_assumed_role_and_its_base_iam_role.

@Test
@SuppressFBWarnings
public void test_that_getAssociatedSafeDepositBoxes_checks_assumed_role_and_its_base_iam_role() {
    String assumedRoleArn = "arn:aws:sts::123456789012:assumed-role/Accounting-Role/Mary";
    String iamRoleArn = "arn:aws:iam::123456789012:role/Accounting-Role";
    String rootArn = "arn:aws:iam::123456789012:root";
    CerberusPrincipal AssumedRoleArnPrincipal = mock(CerberusPrincipal.class);
    doReturn(PrincipalType.IAM).when(AssumedRoleArnPrincipal).getPrincipalType();
    doReturn(assumedRoleArn).when(AssumedRoleArnPrincipal).getName();
    when(awsIamRoleArnParser.isAssumedRoleArn(assumedRoleArn)).thenReturn(true);
    when(awsIamRoleArnParser.convertPrincipalArnToRoleArn(assumedRoleArn)).thenReturn(iamRoleArn);
    when(awsIamRoleArnParser.convertPrincipalArnToRootArn(assumedRoleArn)).thenReturn(rootArn);
    SafeDepositBoxRecord safeDepositBoxRecord1 = new SafeDepositBoxRecord();
    SafeDepositBoxRecord safeDepositBoxRecord2 = new SafeDepositBoxRecord();
    List<SafeDepositBoxRecord> assumedRoleArnRecords = Lists.newArrayList(safeDepositBoxRecord1, safeDepositBoxRecord2);
    when(safeDepositBoxDao.getAssumedRoleAssociatedSafeDepositBoxes(assumedRoleArn, iamRoleArn, rootArn)).thenReturn(assumedRoleArnRecords);
    List<SafeDepositBoxSummary> sdbSummaries = safeDepositBoxServiceSpy.getAssociatedSafeDepositBoxes(AssumedRoleArnPrincipal);
    assertEquals(assumedRoleArnRecords.size(), sdbSummaries.size());
}
Also used : SafeDepositBoxSummary(com.nike.cerberus.domain.SafeDepositBoxSummary) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) SafeDepositBoxRecord(com.nike.cerberus.record.SafeDepositBoxRecord) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with SafeDepositBoxSummary

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

the class SafeDepositBoxServiceTest method test_that_getAssociatedSafeDepositBoxes_checks_iam_role.

@Test
@SuppressFBWarnings
public void test_that_getAssociatedSafeDepositBoxes_checks_iam_role() {
    String iamRoleArn = "arn:aws:iam::123456789012:role/Accounting-Role";
    String rootArn = "arn:aws:iam::123456789012:root";
    SafeDepositBoxRecord safeDepositBoxRecord1 = new SafeDepositBoxRecord();
    List<SafeDepositBoxRecord> roleArnRecords = Lists.newArrayList(safeDepositBoxRecord1);
    when(safeDepositBoxDao.getIamPrincipalAssociatedSafeDepositBoxes(iamRoleArn, rootArn)).thenReturn(roleArnRecords);
    when(awsIamRoleArnParser.isAssumedRoleArn(iamRoleArn)).thenReturn(false);
    when(awsIamRoleArnParser.convertPrincipalArnToRootArn(iamRoleArn)).thenReturn(rootArn);
    CerberusPrincipal roleArnPrincipal = mock(CerberusPrincipal.class);
    doReturn(PrincipalType.IAM).when(roleArnPrincipal).getPrincipalType();
    doReturn(iamRoleArn).when(roleArnPrincipal).getName();
    List<SafeDepositBoxSummary> roleArnSdbSummaries = safeDepositBoxServiceSpy.getAssociatedSafeDepositBoxes(roleArnPrincipal);
    assertEquals(roleArnRecords.size(), roleArnSdbSummaries.size());
}
Also used : SafeDepositBoxSummary(com.nike.cerberus.domain.SafeDepositBoxSummary) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) SafeDepositBoxRecord(com.nike.cerberus.record.SafeDepositBoxRecord) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SafeDepositBoxSummary (com.nike.cerberus.domain.SafeDepositBoxSummary)3 CerberusPrincipal (com.nike.cerberus.security.CerberusPrincipal)3 Test (org.junit.Test)3 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ArrayList (java.util.ArrayList)1