@Test public void test_getSafe_successfully() { String path = "shared/mysafe01"; String _path = "metadata/"+path; String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String responseJson = "{ \"keys\": [ \"mysafe01\" ]}"; Response response = getMockResponse(HttpStatus.OK, true, responseJson); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(responseJson); when(ControllerUtil.isValidSafePath(path)).thenReturn(true); when(ControllerUtil.getSafeName(path)).thenReturn("mysafe01"); when(reqProcessor.process("/sdb/list","{\"path\":\""+path+"\"}",token)).thenReturn(response); when(reqProcessor.process("/sdb","{\"path\":\""+_path+"\"}",token)).thenReturn(response); ResponseEntity<String> responseEntity = safesService.getSafe(token, path); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> getSafe(String token, String path) { if (path != null && path.startsWith("/")) { path = path.substring(1, path.length()); } if (path != null && path.endsWith("/")) { path = path.substring(0, path.length()-1); } String _path = "metadata/"+path; if( TVaultConstants.APPS.equals(path)||TVaultConstants.SHARED.equals(path)||TVaultConstants.USERS.equals(path)){ Response response = reqProcessor.process("/sdb/list","{\"path\":\""+_path+"\"}",token); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ boolean isPathValid = ControllerUtil.isValidSafePath(path); if (!isPathValid) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'path' specified\"]}"); } String safeName = ControllerUtil.getSafeName(path); if (StringUtils.isEmpty(safeName)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'Safe Name' specified\"]}"); } Response response = reqProcessor.process("/sdb","{\"path\":\""+_path+"\"}",token); if (HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Unable to get Safe information\"]}"); } } }
SafesService { public ResponseEntity<String> getSafe(String token, String path) { if (path != null && path.startsWith("/")) { path = path.substring(1, path.length()); } if (path != null && path.endsWith("/")) { path = path.substring(0, path.length()-1); } String _path = "metadata/"+path; if( TVaultConstants.APPS.equals(path)||TVaultConstants.SHARED.equals(path)||TVaultConstants.USERS.equals(path)){ Response response = reqProcessor.process("/sdb/list","{\"path\":\""+_path+"\"}",token); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ boolean isPathValid = ControllerUtil.isValidSafePath(path); if (!isPathValid) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'path' specified\"]}"); } String safeName = ControllerUtil.getSafeName(path); if (StringUtils.isEmpty(safeName)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'Safe Name' specified\"]}"); } Response response = reqProcessor.process("/sdb","{\"path\":\""+_path+"\"}",token); if (HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Unable to get Safe information\"]}"); } } } }
SafesService { public ResponseEntity<String> getSafe(String token, String path) { if (path != null && path.startsWith("/")) { path = path.substring(1, path.length()); } if (path != null && path.endsWith("/")) { path = path.substring(0, path.length()-1); } String _path = "metadata/"+path; if( TVaultConstants.APPS.equals(path)||TVaultConstants.SHARED.equals(path)||TVaultConstants.USERS.equals(path)){ Response response = reqProcessor.process("/sdb/list","{\"path\":\""+_path+"\"}",token); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ boolean isPathValid = ControllerUtil.isValidSafePath(path); if (!isPathValid) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'path' specified\"]}"); } String safeName = ControllerUtil.getSafeName(path); if (StringUtils.isEmpty(safeName)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'Safe Name' specified\"]}"); } Response response = reqProcessor.process("/sdb","{\"path\":\""+_path+"\"}",token); if (HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Unable to get Safe information\"]}"); } } }  }
SafesService { public ResponseEntity<String> getSafe(String token, String path) { if (path != null && path.startsWith("/")) { path = path.substring(1, path.length()); } if (path != null && path.endsWith("/")) { path = path.substring(0, path.length()-1); } String _path = "metadata/"+path; if( TVaultConstants.APPS.equals(path)||TVaultConstants.SHARED.equals(path)||TVaultConstants.USERS.equals(path)){ Response response = reqProcessor.process("/sdb/list","{\"path\":\""+_path+"\"}",token); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ boolean isPathValid = ControllerUtil.isValidSafePath(path); if (!isPathValid) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'path' specified\"]}"); } String safeName = ControllerUtil.getSafeName(path); if (StringUtils.isEmpty(safeName)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'Safe Name' specified\"]}"); } Response response = reqProcessor.process("/sdb","{\"path\":\""+_path+"\"}",token); if (HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Unable to get Safe information\"]}"); } } }  ResponseEntity<String> getFolders( String token, String path); ResponseEntity<String> getInfo(String token, String path); ResponseEntity<String> createfolder(String token, String path); ResponseEntity<String> createSafe(String token, Safe safe); ResponseEntity<String> getSafe(String token, String path); ResponseEntity<String> deleteSafe(String token, Safe safe, UserDetails userDetails); ResponseEntity<String> updateSafe(String token, Safe safe); ResponseEntity<String> addUserToSafe(String token, SafeUser safeUser, UserDetails userDetails); ResponseEntity<String> addGroupToSafe(String token, SafeGroup safeGroup, UserDetails userDetails); ResponseEntity<String> removeUserFromSafe(String token, SafeUser safeUser, UserDetails userDetails); ResponseEntity<String> removeGroupFromSafe(String token, SafeGroup safeGroup, UserDetails userDetails); ResponseEntity<String> addAwsRoleToSafe(String token, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(String token, AWSRole awsRole, boolean detachOnly, UserDetails userDetails); ResponseEntity<String> deletefolder(String token, String path, UserDetails userDetails); ResponseEntity<String> getFoldersRecursively(String token, String path); ResponseEntity<String> createNestedfolder(String token, String path, UserDetails userDetails); ResponseEntity<String> associateApproletoSDB(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> removeApproleFromSafe(String token, String jsonstr); }
SafesService { public ResponseEntity<String> getSafe(String token, String path) { if (path != null && path.startsWith("/")) { path = path.substring(1, path.length()); } if (path != null && path.endsWith("/")) { path = path.substring(0, path.length()-1); } String _path = "metadata/"+path; if( TVaultConstants.APPS.equals(path)||TVaultConstants.SHARED.equals(path)||TVaultConstants.USERS.equals(path)){ Response response = reqProcessor.process("/sdb/list","{\"path\":\""+_path+"\"}",token); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ boolean isPathValid = ControllerUtil.isValidSafePath(path); if (!isPathValid) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'path' specified\"]}"); } String safeName = ControllerUtil.getSafeName(path); if (StringUtils.isEmpty(safeName)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid 'Safe Name' specified\"]}"); } Response response = reqProcessor.process("/sdb","{\"path\":\""+_path+"\"}",token); if (HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Unable to get Safe information\"]}"); } } }  ResponseEntity<String> getFolders( String token, String path); ResponseEntity<String> getInfo(String token, String path); ResponseEntity<String> createfolder(String token, String path); ResponseEntity<String> createSafe(String token, Safe safe); ResponseEntity<String> getSafe(String token, String path); ResponseEntity<String> deleteSafe(String token, Safe safe, UserDetails userDetails); ResponseEntity<String> updateSafe(String token, Safe safe); ResponseEntity<String> addUserToSafe(String token, SafeUser safeUser, UserDetails userDetails); ResponseEntity<String> addGroupToSafe(String token, SafeGroup safeGroup, UserDetails userDetails); ResponseEntity<String> removeUserFromSafe(String token, SafeUser safeUser, UserDetails userDetails); ResponseEntity<String> removeGroupFromSafe(String token, SafeGroup safeGroup, UserDetails userDetails); ResponseEntity<String> addAwsRoleToSafe(String token, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(String token, AWSRole awsRole, boolean detachOnly, UserDetails userDetails); ResponseEntity<String> deletefolder(String token, String path, UserDetails userDetails); ResponseEntity<String> getFoldersRecursively(String token, String path); ResponseEntity<String> createNestedfolder(String token, String path, UserDetails userDetails); ResponseEntity<String> associateApproletoSDB(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> removeApproleFromSafe(String token, String jsonstr);  }