Search in sources :

Example 21 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_validates_user_AD_group_name_on_user_group_addition.

@Test
public void test_that_validates_user_AD_group_name_on_user_group_addition() {
    String id = "111";
    String categoryId = "222";
    String readId = "333";
    String sdbName = "HEALTH CHECK BUCKET";
    SafeDepositBoxV2 sdbObject = new SafeDepositBoxV2();
    sdbObject.setId(id);
    sdbObject.setPath("app/health-check-bucket/");
    sdbObject.setCategoryId(categoryId);
    sdbObject.setName(sdbName);
    sdbObject.setOwner("app.mock.test");
    sdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    sdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    sdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    sdbObject.setCreatedBy("foobar@nike.com");
    sdbObject.setLastUpdatedBy("foobar@nike.com");
    SafeDepositBoxV2 newSdbObject = new SafeDepositBoxV2();
    newSdbObject.setId(id);
    newSdbObject.setPath("app/health-check-bucket/");
    newSdbObject.setCategoryId(categoryId);
    newSdbObject.setName(sdbName);
    newSdbObject.setOwner("app.mock.test");
    newSdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    newSdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    newSdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    newSdbObject.setCreatedBy("foobar@nike.com");
    newSdbObject.setLastUpdatedBy("foobar@nike.com");
    safeDepositBoxService.adGroupNamePrefix = "app.mock";
    Set<UserGroupPermission> userPerms = new HashSet<>();
    userPerms.add(new UserGroupPermission().withName("lst.mock").withRoleId(readId));
    userPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
    sdbObject.setUserGroupPermissions(userPerms);
    Set<UserGroupPermission> newUserPerms = new HashSet<>();
    newUserPerms.add(new UserGroupPermission().withName("lst.mock").withRoleId(readId));
    newUserPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
    newUserPerms.add(new UserGroupPermission().withName("app.mock.foobar").withRoleId(readId));
    newSdbObject.setUserGroupPermissions(newUserPerms);
    safeDepositBoxService.validateNewUserGroupPermissions(sdbObject, newSdbObject);
}
Also used : SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_invalidates_user_AD_group_name_on_user_group_addition.

@Test(expected = ApiException.class)
public void test_that_invalidates_user_AD_group_name_on_user_group_addition() {
    String id = "111";
    String categoryId = "222";
    String readId = "333";
    String sdbName = "HEALTH CHECK BUCKET";
    SafeDepositBoxV2 sdbObject = new SafeDepositBoxV2();
    sdbObject.setId(id);
    sdbObject.setPath("app/health-check-bucket/");
    sdbObject.setCategoryId(categoryId);
    sdbObject.setName(sdbName);
    sdbObject.setOwner("app.mock.test");
    sdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    sdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    sdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    sdbObject.setCreatedBy("foobar@nike.com");
    sdbObject.setLastUpdatedBy("foobar@nike.com");
    SafeDepositBoxV2 newSdbObject = new SafeDepositBoxV2();
    newSdbObject.setId(id);
    newSdbObject.setPath("app/health-check-bucket/");
    newSdbObject.setCategoryId(categoryId);
    newSdbObject.setName(sdbName);
    newSdbObject.setOwner("app.mock.test");
    newSdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    newSdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    newSdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    newSdbObject.setCreatedBy("foobar@nike.com");
    newSdbObject.setLastUpdatedBy("foobar@nike.com");
    safeDepositBoxService.adGroupNamePrefix = "app.mock";
    Set<UserGroupPermission> userPerms = new HashSet<>();
    userPerms.add(new UserGroupPermission().withName("lst.mock").withRoleId(readId));
    userPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
    sdbObject.setUserGroupPermissions(userPerms);
    Set<UserGroupPermission> newUserPerms = new HashSet<>();
    newUserPerms.add(new UserGroupPermission().withName("lst.mock").withRoleId(readId));
    newUserPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
    newUserPerms.add(new UserGroupPermission().withName("app.exception").withRoleId(readId));
    newSdbObject.setUserGroupPermissions(newUserPerms);
    safeDepositBoxService.validateNewUserGroupPermissions(sdbObject, newSdbObject);
}
Also used : SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_rejects_bad_owner_AD_group_name.

@Test(expected = ApiException.class)
public void test_that_rejects_bad_owner_AD_group_name() {
    String id = "111";
    String categoryId = "222";
    String readId = "333";
    String sdbName = "HEALTH CHECK BUCKET";
    SafeDepositBoxV2 sdbObject = new SafeDepositBoxV2();
    sdbObject.setId(id);
    sdbObject.setPath("app/health-check-bucket/");
    sdbObject.setCategoryId(categoryId);
    sdbObject.setName(sdbName);
    sdbObject.setOwner("app.mock.test");
    sdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    sdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    sdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    sdbObject.setCreatedBy("foobar@nike.com");
    sdbObject.setLastUpdatedBy("foobar@nike.com");
    safeDepositBoxService.adGroupNamePrefix = "blah";
    safeDepositBoxService.validateSDBOwnerName(sdbObject);
}
Also used : SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) Test(org.junit.Test)

Example 24 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_validates_user_AD_group_name_on_user_group_removal.

@Test
public void test_that_validates_user_AD_group_name_on_user_group_removal() {
    String id = "111";
    String categoryId = "222";
    String readId = "333";
    String sdbName = "HEALTH CHECK BUCKET";
    SafeDepositBoxV2 sdbObject = new SafeDepositBoxV2();
    sdbObject.setId(id);
    sdbObject.setPath("app/health-check-bucket/");
    sdbObject.setCategoryId(categoryId);
    sdbObject.setName(sdbName);
    sdbObject.setOwner("app.mock.test");
    sdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    sdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    sdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    sdbObject.setCreatedBy("foobar@nike.com");
    sdbObject.setLastUpdatedBy("foobar@nike.com");
    SafeDepositBoxV2 newSdbObject = new SafeDepositBoxV2();
    newSdbObject.setId(id);
    newSdbObject.setPath("app/health-check-bucket/");
    newSdbObject.setCategoryId(categoryId);
    newSdbObject.setName(sdbName);
    newSdbObject.setOwner("app.mock.test");
    newSdbObject.setDescription("This SDB is read by the Health Check Lambda...");
    newSdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    newSdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    newSdbObject.setCreatedBy("foobar@nike.com");
    newSdbObject.setLastUpdatedBy("foobar@nike.com");
    safeDepositBoxService.adGroupNamePrefix = "app.mock";
    Set<UserGroupPermission> userPerms = new HashSet<>();
    userPerms.add(new UserGroupPermission().withName("lst.mock").withRoleId(readId));
    userPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
    sdbObject.setUserGroupPermissions(userPerms);
    Set<UserGroupPermission> newUserPerms = new HashSet<>();
    newUserPerms.add(new UserGroupPermission().withName("lst.mock").withRoleId(readId));
    newSdbObject.setUserGroupPermissions(newUserPerms);
    safeDepositBoxService.validateNewUserGroupPermissions(sdbObject, newSdbObject);
}
Also used : SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_convertSafeDepositBoxV1ToV2_creates_expected_safe_deposit_box_v2.

@Test
public void test_that_convertSafeDepositBoxV1ToV2_creates_expected_safe_deposit_box_v2() {
    String id = "id";
    String name = "name";
    String description = "description";
    String path = "path";
    String categoryId = "category id";
    String createdBy = "created by";
    String lastUpdatedBy = "last updated by";
    OffsetDateTime createdTs = OffsetDateTime.now();
    OffsetDateTime lastUpdatedTs = OffsetDateTime.now();
    String owner = "owner";
    String accountId = "123";
    String roleName = "abc";
    String arn = "arn:aws:iam::123:role/abc";
    String roleId = "role id";
    Set<UserGroupPermission> userGroupPermissions = Sets.newHashSet();
    UserGroupPermission userGroupPermission = new UserGroupPermission();
    userGroupPermissions.add(userGroupPermission);
    Set<IamPrincipalPermission> iamRolePermissions = Sets.newHashSet();
    IamPrincipalPermission iamRolePermission = new IamPrincipalPermission().withIamPrincipalArn(arn).withRoleId(roleId);
    iamRolePermissions.add(iamRolePermission);
    SafeDepositBoxV2 safeDepositBoxV2 = new SafeDepositBoxV2();
    safeDepositBoxV2.setId(id);
    safeDepositBoxV2.setName(name);
    safeDepositBoxV2.setDescription(description);
    safeDepositBoxV2.setPath(path);
    safeDepositBoxV2.setCategoryId(categoryId);
    safeDepositBoxV2.setCreatedBy(createdBy);
    safeDepositBoxV2.setLastUpdatedBy(lastUpdatedBy);
    safeDepositBoxV2.setCreatedTs(createdTs);
    safeDepositBoxV2.setLastUpdatedTs(lastUpdatedTs);
    safeDepositBoxV2.setOwner(owner);
    safeDepositBoxV2.setUserGroupPermissions(userGroupPermissions);
    safeDepositBoxV2.setIamPrincipalPermissions(iamRolePermissions);
    when(awsIamRoleArnParser.getAccountId(arn)).thenReturn(accountId);
    when(awsIamRoleArnParser.getRoleName(arn)).thenReturn(roleName);
    SafeDepositBoxV1 resultantSDBV1 = safeDepositBoxService.convertSafeDepositBoxV2ToV1(safeDepositBoxV2);
    SafeDepositBoxV1 expectedSdbV1 = new SafeDepositBoxV1();
    expectedSdbV1.setId(id);
    expectedSdbV1.setName(name);
    expectedSdbV1.setDescription(description);
    expectedSdbV1.setPath(path);
    expectedSdbV1.setCategoryId(categoryId);
    expectedSdbV1.setCreatedBy(createdBy);
    expectedSdbV1.setLastUpdatedBy(lastUpdatedBy);
    expectedSdbV1.setCreatedTs(createdTs);
    expectedSdbV1.setLastUpdatedTs(lastUpdatedTs);
    expectedSdbV1.setOwner(owner);
    expectedSdbV1.setUserGroupPermissions(userGroupPermissions);
    Set<IamRolePermission> expectedIamRolePermissionsV1 = Sets.newHashSet();
    IamRolePermission expectedIamRolePermission = new IamRolePermission().withAccountId(accountId).withIamRoleName(roleName).withRoleId(roleId);
    expectedIamRolePermissionsV1.add(expectedIamRolePermission);
    expectedSdbV1.setIamRolePermissions(expectedIamRolePermissionsV1);
    assertEquals(expectedSdbV1, resultantSDBV1);
}
Also used : SafeDepositBoxV1(com.nike.cerberus.domain.SafeDepositBoxV1) SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) OffsetDateTime(java.time.OffsetDateTime) IamRolePermission(com.nike.cerberus.domain.IamRolePermission) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Aggregations

SafeDepositBoxV2 (com.nike.cerberus.domain.SafeDepositBoxV2)31 Test (org.junit.Test)29 UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)15 HashSet (java.util.HashSet)15 CerberusPrincipal (com.nike.cerberus.security.CerberusPrincipal)7 IamPrincipalPermission (com.nike.cerberus.domain.IamPrincipalPermission)6 SafeDepositBoxV1 (com.nike.cerberus.domain.SafeDepositBoxV1)6 OffsetDateTime (java.time.OffsetDateTime)3 IamRolePermission (com.nike.cerberus.domain.IamRolePermission)2 SDBMetadata (com.nike.cerberus.domain.SDBMetadata)2 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Role (com.nike.cerberus.domain.Role)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 HttpHeaders (org.springframework.http.HttpHeaders)1 Authentication (org.springframework.security.core.Authentication)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1