@Test public void test_createSafe_successfully() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; UserDetails userDetails = getMockUser(false); SafeBasicDetails safeBasicDetails = new SafeBasicDetails("mysafe01", "youremail@yourcompany.com", null, "My first safe"); Safe safe = new Safe("shared/mysafe01",safeBasicDetails); ResponseEntity<String> readResponse = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Safe and associated read/write/deny policies created \"]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Safe and associated read/write/deny policies created \"]}"); ReflectionTestUtils.setField(selfSupportService, "safeQuota", "2"); when(ControllerUtil.getSafeType("shared/mysafe01")).thenReturn("shared"); String [] policies = {"s_shared_s1"}; when(policyUtils.getCurrentPolicies(token, "normaluser", userDetails)).thenReturn(policies); String [] safes = {"s1"}; when(safeUtils.getManagedSafes(policies, "shared")).thenReturn(safes); when(safesService.createSafe(token, safe)).thenReturn(readResponse); ResponseEntity<String> responseEntity = selfSupportService.createSafe(userDetails, token, safe); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe) { String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.createSafe(token, safe); } else { token = userDetails.getSelfSupportToken(); if (!isSafeValid(safe)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid input values\"]}"); } if (isSafeQuotaReached(token, userDetails.getUsername(), ControllerUtil.getSafeType(safe.getPath()), userDetails)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"You have reached the limit of number of allowed safes that can be created\"]}"); } if (safe != null && safe.getSafeBasicDetails() != null) { safe.getSafeBasicDetails().setOwnerid(userDetails.getUsername()); } ResponseEntity<String> safe_creation_response = safesService.createSafe(token, safe); if (HttpStatus.OK.equals(safe_creation_response.getStatusCode() )) { SafeUser safeUser = new SafeUser(); safeUser.setAccess(TVaultConstants.SUDO_POLICY); safeUser.setPath(safe.getPath()); safeUser.setUsername(userDetails.getUsername()); safesService.addUserToSafe(token, safeUser, null); } return safe_creation_response; } }
SelfSupportService { public ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe) { String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.createSafe(token, safe); } else { token = userDetails.getSelfSupportToken(); if (!isSafeValid(safe)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid input values\"]}"); } if (isSafeQuotaReached(token, userDetails.getUsername(), ControllerUtil.getSafeType(safe.getPath()), userDetails)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"You have reached the limit of number of allowed safes that can be created\"]}"); } if (safe != null && safe.getSafeBasicDetails() != null) { safe.getSafeBasicDetails().setOwnerid(userDetails.getUsername()); } ResponseEntity<String> safe_creation_response = safesService.createSafe(token, safe); if (HttpStatus.OK.equals(safe_creation_response.getStatusCode() )) { SafeUser safeUser = new SafeUser(); safeUser.setAccess(TVaultConstants.SUDO_POLICY); safeUser.setPath(safe.getPath()); safeUser.setUsername(userDetails.getUsername()); safesService.addUserToSafe(token, safeUser, null); } return safe_creation_response; } } }
SelfSupportService { public ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe) { String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.createSafe(token, safe); } else { token = userDetails.getSelfSupportToken(); if (!isSafeValid(safe)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid input values\"]}"); } if (isSafeQuotaReached(token, userDetails.getUsername(), ControllerUtil.getSafeType(safe.getPath()), userDetails)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"You have reached the limit of number of allowed safes that can be created\"]}"); } if (safe != null && safe.getSafeBasicDetails() != null) { safe.getSafeBasicDetails().setOwnerid(userDetails.getUsername()); } ResponseEntity<String> safe_creation_response = safesService.createSafe(token, safe); if (HttpStatus.OK.equals(safe_creation_response.getStatusCode() )) { SafeUser safeUser = new SafeUser(); safeUser.setAccess(TVaultConstants.SUDO_POLICY); safeUser.setPath(safe.getPath()); safeUser.setUsername(userDetails.getUsername()); safesService.addUserToSafe(token, safeUser, null); } return safe_creation_response; } }  }
SelfSupportService { public ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe) { String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.createSafe(token, safe); } else { token = userDetails.getSelfSupportToken(); if (!isSafeValid(safe)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid input values\"]}"); } if (isSafeQuotaReached(token, userDetails.getUsername(), ControllerUtil.getSafeType(safe.getPath()), userDetails)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"You have reached the limit of number of allowed safes that can be created\"]}"); } if (safe != null && safe.getSafeBasicDetails() != null) { safe.getSafeBasicDetails().setOwnerid(userDetails.getUsername()); } ResponseEntity<String> safe_creation_response = safesService.createSafe(token, safe); if (HttpStatus.OK.equals(safe_creation_response.getStatusCode() )) { SafeUser safeUser = new SafeUser(); safeUser.setAccess(TVaultConstants.SUDO_POLICY); safeUser.setPath(safe.getPath()); safeUser.setUsername(userDetails.getUsername()); safesService.addUserToSafe(token, safeUser, null); } return safe_creation_response; } }  ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> addUserToSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getInfo(UserDetails userDetails, String userToken, String path); ResponseEntity<String> getSafe(UserDetails userDetails, String userToken, String path); ResponseEntity<String> removeUserFromSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getFoldersRecursively(UserDetails userDetails, String userToken, String path); ResponseEntity<String> isAuthorized(UserDetails userDetails, String path); ResponseEntity<String> updateSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> deletefolder(UserDetails userDetails, String userToken, String path); ResponseEntity<String> addGroupToSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> removeGroupFromSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> addAwsRoleToSafe(UserDetails userDetails, String userToken, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(UserDetails userDetails, String userToken, AWSRole awsRole, boolean detachOnly); ResponseEntity<String> associateApproletoSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> createRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> updateRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> createIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> updateIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> getAllSafeNames(UserDetails userDetails); ResponseEntity<String> createAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> getSafes(UserDetails userDetails, String userToken); ResponseEntity<String> readAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> listAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> readAppRole(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String userToken, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> updateAppRole(String userToken, AppRole appRole, UserDetails userDetails); }
SelfSupportService { public ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe) { String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.createSafe(token, safe); } else { token = userDetails.getSelfSupportToken(); if (!isSafeValid(safe)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid input values\"]}"); } if (isSafeQuotaReached(token, userDetails.getUsername(), ControllerUtil.getSafeType(safe.getPath()), userDetails)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"You have reached the limit of number of allowed safes that can be created\"]}"); } if (safe != null && safe.getSafeBasicDetails() != null) { safe.getSafeBasicDetails().setOwnerid(userDetails.getUsername()); } ResponseEntity<String> safe_creation_response = safesService.createSafe(token, safe); if (HttpStatus.OK.equals(safe_creation_response.getStatusCode() )) { SafeUser safeUser = new SafeUser(); safeUser.setAccess(TVaultConstants.SUDO_POLICY); safeUser.setPath(safe.getPath()); safeUser.setUsername(userDetails.getUsername()); safesService.addUserToSafe(token, safeUser, null); } return safe_creation_response; } }  ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> addUserToSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getInfo(UserDetails userDetails, String userToken, String path); ResponseEntity<String> getSafe(UserDetails userDetails, String userToken, String path); ResponseEntity<String> removeUserFromSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getFoldersRecursively(UserDetails userDetails, String userToken, String path); ResponseEntity<String> isAuthorized(UserDetails userDetails, String path); ResponseEntity<String> updateSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> deletefolder(UserDetails userDetails, String userToken, String path); ResponseEntity<String> addGroupToSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> removeGroupFromSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> addAwsRoleToSafe(UserDetails userDetails, String userToken, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(UserDetails userDetails, String userToken, AWSRole awsRole, boolean detachOnly); ResponseEntity<String> associateApproletoSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> createRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> updateRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> createIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> updateIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> getAllSafeNames(UserDetails userDetails); ResponseEntity<String> createAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> getSafes(UserDetails userDetails, String userToken); ResponseEntity<String> readAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> listAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> readAppRole(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String userToken, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> updateAppRole(String userToken, AppRole appRole, UserDetails userDetails);  }