@Test public void test_deleteFromVault_successfully() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String path = "shared/mysafe01/myfolder"; Response response = getMockResponse(HttpStatus.NO_CONTENT, true, ""); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Secrets deleted\"]}"); when(ControllerUtil.isValidDataPath(path)).thenReturn(true); when(reqProcessor.process("/delete","{\"path\":\""+path+"\"}",token)).thenReturn(response); ResponseEntity<String> responseEntity = secretService.deleteFromVault(token, path); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> deleteFromVault(String token, String path){ if(ControllerUtil.isValidDataPath(path)){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Trying to delete secret [%s]", path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/delete","{\"path\":\""+path+"\"}",token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] completed", path)). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Secrets deleted\"]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] failed", path)). put(LogMessage.RESPONSE, "Invalid path"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}"); } }
SecretService { public ResponseEntity<String> deleteFromVault(String token, String path){ if(ControllerUtil.isValidDataPath(path)){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Trying to delete secret [%s]", path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/delete","{\"path\":\""+path+"\"}",token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] completed", path)). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Secrets deleted\"]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] failed", path)). put(LogMessage.RESPONSE, "Invalid path"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}"); } } }
SecretService { public ResponseEntity<String> deleteFromVault(String token, String path){ if(ControllerUtil.isValidDataPath(path)){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Trying to delete secret [%s]", path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/delete","{\"path\":\""+path+"\"}",token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] completed", path)). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Secrets deleted\"]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] failed", path)). put(LogMessage.RESPONSE, "Invalid path"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}"); } }  }
SecretService { public ResponseEntity<String> deleteFromVault(String token, String path){ if(ControllerUtil.isValidDataPath(path)){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Trying to delete secret [%s]", path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/delete","{\"path\":\""+path+"\"}",token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] completed", path)). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Secrets deleted\"]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] failed", path)). put(LogMessage.RESPONSE, "Invalid path"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}"); } }  ResponseEntity<String> readFromVault(String token, String path); ResponseEntity<String> write(String token, Secret secret, UserDetails userDetails); ResponseEntity<String> deleteFromVault(String token, String path); ResponseEntity<String> readFromVaultRecursive(String token, String path); ResponseEntity<String> readFoldersAndSecrets(String token, String path); }
SecretService { public ResponseEntity<String> deleteFromVault(String token, String path){ if(ControllerUtil.isValidDataPath(path)){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Trying to delete secret [%s]", path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/delete","{\"path\":\""+path+"\"}",token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] completed", path)). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Secrets deleted\"]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Secret"). put(LogMessage.MESSAGE, String.format("Deleting secret [%s] failed", path)). put(LogMessage.RESPONSE, "Invalid path"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}"); } }  ResponseEntity<String> readFromVault(String token, String path); ResponseEntity<String> write(String token, Secret secret, UserDetails userDetails); ResponseEntity<String> deleteFromVault(String token, String path); ResponseEntity<String> readFromVaultRecursive(String token, String path); ResponseEntity<String> readFoldersAndSecrets(String token, String path);  }