use of com.nike.cerberus.domain.SDBMetadata in project cerberus by Nike-Inc.
the class SdbMetadataControllerTest method testRestoreSdbIncludingDataInRequestIfSafeBoIdIsNotPresent.
@Test
public void testRestoreSdbIncludingDataInRequestIfSafeBoIdIsNotPresent() {
SDBMetadata sdbMetadata = Mockito.mock(SDBMetadata.class);
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authentication.getName()).thenReturn("name");
Mockito.when(sdbMetadata.getPath()).thenReturn("path");
Mockito.when(safeDepositBoxService.getSafeDepositBoxIdByPath("path")).thenReturn(Optional.empty());
sdbMetadataController.restoreSdbIncludingDataInRequest(sdbMetadata, authentication);
Mockito.verify(safeDepositBoxService, Mockito.never()).deleteSafeDepositBox(Mockito.anyString());
Mockito.verify(metadataService).restoreMetadata(sdbMetadata, "name");
}
use of com.nike.cerberus.domain.SDBMetadata in project cerberus by Nike-Inc.
the class MetadataServiceTest method test_that_get_sdb_metadata_properly_sets_result_metadata.
@Test
public void test_that_get_sdb_metadata_properly_sets_result_metadata() {
int limit = 5;
int offset = 0;
int totalSDBs = 20;
when(safeDepositBoxService.getTotalNumberOfSafeDepositBoxes()).thenReturn(totalSDBs);
SDBMetadata sdbMD = new SDBMetadata();
doReturn(Arrays.asList(sdbMD)).when(metadataServiceSpy).getSDBMetadataList(limit, offset, null);
SDBMetadataResult actual = metadataServiceSpy.getSDBMetadata(limit, offset, null);
assertEquals("expected actual limit to be passed in limit", limit, actual.getLimit());
assertEquals("expected actual offset to be passed in offset", offset, actual.getOffset());
assertEquals("expected next offset to be limit + offset", limit + offset, actual.getNextOffset());
assertEquals("expected there to be another page of results", true, actual.isHasNext());
assertEquals("expected the sdb count to equal 1", 1, actual.getSdbCountInResult());
assertEquals("expected total sdbs to equal the sdb total count", totalSDBs, actual.getTotalSDBCount());
}
use of com.nike.cerberus.domain.SDBMetadata in project cerberus by Nike-Inc.
the class MetadataServiceTest method test_that_get_sdb_metadata_set_has_next_to_no_when_done_paging.
@Test
public void test_that_get_sdb_metadata_set_has_next_to_no_when_done_paging() {
int limit = 5;
int offset = 15;
int totalSDBs = 20;
when(safeDepositBoxService.getTotalNumberOfSafeDepositBoxes()).thenReturn(totalSDBs);
doReturn(Arrays.asList(new SDBMetadata())).when(metadataServiceSpy).getSDBMetadataList(limit, offset, null);
SDBMetadataResult actual = metadataServiceSpy.getSDBMetadata(limit, offset, null);
assertEquals("expected actual limit to be passed in limit", limit, actual.getLimit());
assertEquals("expected actual offset to be passed in offset", offset, actual.getOffset());
assertEquals("expected next offset to be 0 because no more paging", 0, actual.getNextOffset());
assertEquals("expected there to be another page of results", false, actual.isHasNext());
assertEquals("expected the sdb count to equal 1", 1, actual.getSdbCountInResult());
assertEquals("expected total sdbs to equal the sdb total count", totalSDBs, actual.getTotalSDBCount());
}
use of com.nike.cerberus.domain.SDBMetadata in project cerberus by Nike-Inc.
the class MetadataServiceTest method test_that_restore_metadata_calls_the_sdb_service_with_expected_sdb_box.
@Test
public void test_that_restore_metadata_calls_the_sdb_service_with_expected_sdb_box() throws IOException {
String user = "unit-test-user";
String id = "111";
String categoryId = "222";
String categoryName = "Applications";
String readId = "333";
String sdbName = "HEALTH CHECK BUCKET";
ObjectMapper mapper = ApplicationConfiguration.getObjectMapper();
InputStream metadataStream = getClass().getClassLoader().getResourceAsStream("com/nike/cerberus/service/sdb_metadata_backup.json");
SDBMetadata sdbMetadata = mapper.readValue(metadataStream, SDBMetadata.class);
when(safeDepositBoxService.getSafeDepositBoxIdByName(sdbName)).thenReturn(Optional.ofNullable(null));
when(uuidSupplier.get()).thenReturn(id);
when(categoryService.getCategoryIdByName(categoryName)).thenReturn(Optional.of(categoryId));
Role readRole = new Role();
readRole.setId(readId);
when(roleService.getRoleByName(RoleRecord.ROLE_READ)).thenReturn(Optional.of(readRole));
metadataService.restoreMetadata(sdbMetadata, user);
SafeDepositBoxV2 expectedSdb = new SafeDepositBoxV2();
expectedSdb.setId(id);
expectedSdb.setPath("app/health-check-bucket/");
expectedSdb.setCategoryId(categoryId);
expectedSdb.setName(sdbName);
expectedSdb.setOwner("Lst-Squad.Carebears");
expectedSdb.setDescription("This SDB is read by the Health Check Lambda...");
expectedSdb.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
expectedSdb.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
expectedSdb.setCreatedBy("justin.field@nike.com");
expectedSdb.setLastUpdatedBy("todd.lisonbee@nike.com");
Set<UserGroupPermission> userPerms = new HashSet<>();
userPerms.add(new UserGroupPermission().withName("Foundation.Prod.Support").withRoleId(readId));
userPerms.add(new UserGroupPermission().withName("Lst-NIKE.FOO.ISL").withRoleId(readId));
expectedSdb.setUserGroupPermissions(userPerms);
Set<IamPrincipalPermission> iamPerms = new HashSet<>();
String arn = "arn:aws:iam::1111111111:role/lambda_prod_healthcheck";
iamPerms.add(new IamPrincipalPermission().withIamPrincipalArn(arn).withRoleId(readId));
expectedSdb.setIamPrincipalPermissions(iamPerms);
expectedSdb.setUserGroupPermissions(userPerms);
expectedSdb.setIamPrincipalPermissions(iamPerms);
verify(safeDepositBoxService, times(1)).restoreSafeDepositBox(expectedSdb, user);
}
use of com.nike.cerberus.domain.SDBMetadata in project cerberus by Nike-Inc.
the class MetadataServiceTest method test_that_get_sdb_metadata_list_returns_valid_list.
@Test
public void test_that_get_sdb_metadata_list_returns_valid_list() {
String sdbId = "123";
String categoryName = "foo";
String categoryId = "321";
String name = "test-name";
String path = "app/test-name";
String desc = "blah blah blah";
String by = "justin.field@nike.com";
String careBearsGroup = "care-bears";
String careBearsId = "000-abc";
String grumpyBearsGroup = "grumpy-bears";
String grumpyBearsId = "111-def";
String ownerId = "000";
String readId = "111";
String arn = "arn:aws:iam::12345:role/foo-role";
OffsetDateTime offsetDateTime = OffsetDateTime.now();
Map<String, String> catMap = new HashMap<>();
catMap.put(categoryId, categoryName);
Map<String, String> roleIdToStringMap = new HashMap<>();
roleIdToStringMap.put(ownerId, RoleRecord.ROLE_OWNER);
roleIdToStringMap.put(readId, RoleRecord.ROLE_READ);
when(roleService.getRoleIdToStringMap()).thenReturn(roleIdToStringMap);
when(categoryService.getCategoryIdToCategoryNameMap()).thenReturn(catMap);
SafeDepositBoxV2 box = new SafeDepositBoxV2();
box.setId(sdbId);
box.setName(name);
box.setPath(path);
box.setDescription(desc);
box.setCategoryId(categoryId);
box.setCreatedBy(by);
box.setLastUpdatedBy(by);
box.setCreatedTs(offsetDateTime);
box.setLastUpdatedTs(offsetDateTime);
box.setOwner(careBearsGroup);
Set<UserGroupPermission> userPerms = new HashSet<>();
userPerms.add(new UserGroupPermission().withName(grumpyBearsGroup).withRoleId(readId));
box.setUserGroupPermissions(userPerms);
Set<IamPrincipalPermission> iamPerms = new HashSet<>();
iamPerms.add(new IamPrincipalPermission().withIamPrincipalArn(arn).withRoleId(readId));
box.setIamPrincipalPermissions(iamPerms);
when(safeDepositBoxService.getSafeDepositBoxes(1, 0)).thenReturn(Arrays.asList(box));
List<SDBMetadata> actual = metadataService.getSDBMetadataList(1, 0, null);
assertEquals("List should have 1 entry", 1, actual.size());
SDBMetadata data = actual.get(0);
assertEquals("Name should match record", name, data.getName());
assertEquals("path should match record", path, data.getPath());
assertEquals("", categoryName, data.getCategory());
assertEquals("desc should match record", desc, data.getDescription());
assertEquals("created by should match record", by, data.getCreatedBy());
assertEquals("last updated by should match record", by, data.getLastUpdatedBy());
assertEquals("created ts should match record", offsetDateTime, data.getCreatedTs());
assertEquals("updated ts should match record", offsetDateTime, data.getLastUpdatedTs());
Map<String, String> expectedIamPermMap = new HashMap<>();
expectedIamPermMap.put(arn, RoleRecord.ROLE_READ);
assertEquals("iam role perm map should match what is returned by getIamPrincipalPermissionMap", expectedIamPermMap, data.getIamRolePermissions());
Map<String, String> expectedGroupPermMap = new HashMap<>();
expectedGroupPermMap.put(grumpyBearsGroup, RoleRecord.ROLE_READ);
assertEquals("Owner group should be care-bears", careBearsGroup, data.getOwner());
assertEquals("The user group perms should match the expected map", expectedGroupPermMap, data.getUserGroupPermissions());
}
Aggregations