Search in sources :

Example 11 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_validates_owner_AD_group_name.

@Test
public void test_that_validates_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 = "app.mock";
    safeDepositBoxService.validateSDBOwnerName(sdbObject);
}
Also used : SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) Test(org.junit.Test)

Example 12 with SafeDepositBoxV2

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

the class SafeDepositBoxServiceTest method test_that_validates_user_group_sanitization.

@Test
public void test_that_validates_user_group_sanitization() {
    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");
    Set<UserGroupPermission> userPerms = new HashSet<>();
    userPerms.add(new UserGroupPermission().withName("app.Mock.blah").withRoleId(readId));
    userPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
    sdbObject.setUserGroupPermissions(userPerms);
    safeDepositBoxService.sanitizeUserGroupPermissions(sdbObject);
    assertEquals(sdbObject.getUserGroupPermissions().size(), 1);
}
Also used : SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with SafeDepositBoxV2

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

the class UniqueOwnerValidatorTest method owner_in_group_permissions_is_invalid.

@Test
public void owner_in_group_permissions_is_invalid() {
    UserGroupPermission userGroupPermission = new UserGroupPermission();
    userGroupPermission.setName("owner");
    SafeDepositBoxV1 safeDepositBox1 = new SafeDepositBoxV1();
    safeDepositBox1.setOwner("owner");
    safeDepositBox1.getUserGroupPermissions().add(userGroupPermission);
    SafeDepositBoxV2 safeDepositBox2 = new SafeDepositBoxV2();
    safeDepositBox2.setOwner("owner");
    safeDepositBox2.getUserGroupPermissions().add(userGroupPermission);
    Assert.assertFalse(subject.isValid(safeDepositBox1, mockConstraintValidatorContext));
    Assert.assertFalse(subject.isValid(safeDepositBox2, mockConstraintValidatorContext));
}
Also used : SafeDepositBoxV1(com.nike.cerberus.domain.SafeDepositBoxV1) SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 14 with SafeDepositBoxV2

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

the class UniqueOwnerValidatorTest method unique_owner_is_valid.

@Test
public void unique_owner_is_valid() {
    UserGroupPermission userGroupPermission = new UserGroupPermission();
    userGroupPermission.setName("group");
    SafeDepositBoxV1 safeDepositBox1 = new SafeDepositBoxV1();
    safeDepositBox1.setOwner("owner");
    safeDepositBox1.getUserGroupPermissions().add(userGroupPermission);
    SafeDepositBoxV2 safeDepositBox2 = new SafeDepositBoxV2();
    safeDepositBox2.setOwner("owner");
    safeDepositBox2.getUserGroupPermissions().add(userGroupPermission);
    Assert.assertTrue(subject.isValid(safeDepositBox1, mockConstraintValidatorContext));
    Assert.assertTrue(subject.isValid(safeDepositBox2, mockConstraintValidatorContext));
}
Also used : SafeDepositBoxV1(com.nike.cerberus.domain.SafeDepositBoxV1) SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 15 with SafeDepositBoxV2

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

the class UniqueOwnerValidatorTest method empty_user_group_set_is_valid.

@Test
public void empty_user_group_set_is_valid() {
    SafeDepositBoxV1 safeDepositBox1 = new SafeDepositBoxV1();
    safeDepositBox1.setOwner("owner");
    SafeDepositBoxV2 safeDepositBox2 = new SafeDepositBoxV2();
    safeDepositBox2.setOwner("owner");
    Assert.assertTrue(subject.isValid(safeDepositBox1, mockConstraintValidatorContext));
    Assert.assertTrue(subject.isValid(safeDepositBox2, mockConstraintValidatorContext));
}
Also used : SafeDepositBoxV1(com.nike.cerberus.domain.SafeDepositBoxV1) SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) 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