@Test public void test_unseal_successfully_https() { String jsonStr = "{ \"serverip\": \"localhost\", \"port\": 8200, \"key\": \"LwRw+j0I7L4ff4no50fduaF5OeTZJEOQFwdjWZcee0s=\", \"reset\": true}"; String jsonStr1 = "{ \"serverip\": \"localhost\", \"port\": 8200, \"key\": \"LwRw+j0I7L4ff4no50fduaF5OeTZJEOQFwdjWZcee0s=\", \"reset\": true,\"port\":\"null\"}"; Unseal unseal = new Unseal("localhost", "8200", "LwRw+j0I7L4ff4no50fduaF5OeTZJEOQFwdjWZcee0s=", true); Response response = getMockResponse(HttpStatus.OK, true, "{\"messages\": [ \"vault is unsealed\" ]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\": [ \"vault is unsealed\" ]}"); when(JSONUtil.getJSON(unseal)).thenReturn(jsonStr); when(reqProcessor.process("/unseal",jsonStr1,"")).thenReturn(response); ResponseEntity<String> responseEntity = sysService.unseal(unseal); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> unseal (Unseal unseal){ String jsonStr = JSONUtil.getJSON(unseal); jsonStr = jsonStr.substring(0,jsonStr.lastIndexOf("}")); jsonStr = jsonStr+ ",\"port\":\""+vaultPort+"\"}"; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Trying to unseal Vault Server"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/unseal",jsonStr,""); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Unsealing Vault server completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { if(HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { response = reqProcessor.process("/v2/unseal",jsonStr,""); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }
SysService { public ResponseEntity<String> unseal (Unseal unseal){ String jsonStr = JSONUtil.getJSON(unseal); jsonStr = jsonStr.substring(0,jsonStr.lastIndexOf("}")); jsonStr = jsonStr+ ",\"port\":\""+vaultPort+"\"}"; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Trying to unseal Vault Server"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/unseal",jsonStr,""); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Unsealing Vault server completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { if(HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { response = reqProcessor.process("/v2/unseal",jsonStr,""); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } } }
SysService { public ResponseEntity<String> unseal (Unseal unseal){ String jsonStr = JSONUtil.getJSON(unseal); jsonStr = jsonStr.substring(0,jsonStr.lastIndexOf("}")); jsonStr = jsonStr+ ",\"port\":\""+vaultPort+"\"}"; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Trying to unseal Vault Server"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/unseal",jsonStr,""); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Unsealing Vault server completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { if(HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { response = reqProcessor.process("/v2/unseal",jsonStr,""); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }  }
SysService { public ResponseEntity<String> unseal (Unseal unseal){ String jsonStr = JSONUtil.getJSON(unseal); jsonStr = jsonStr.substring(0,jsonStr.lastIndexOf("}")); jsonStr = jsonStr+ ",\"port\":\""+vaultPort+"\"}"; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Trying to unseal Vault Server"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/unseal",jsonStr,""); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Unsealing Vault server completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { if(HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { response = reqProcessor.process("/v2/unseal",jsonStr,""); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }  ResponseEntity<String> checkVaultHealth(); ResponseEntity<String> checkVaultSealStatus(); ResponseEntity<String> unseal(Unseal unseal); ResponseEntity<String> unsealProgress(String serverip); }
SysService { public ResponseEntity<String> unseal (Unseal unseal){ String jsonStr = JSONUtil.getJSON(unseal); jsonStr = jsonStr.substring(0,jsonStr.lastIndexOf("}")); jsonStr = jsonStr+ ",\"port\":\""+vaultPort+"\"}"; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Trying to unseal Vault Server"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/unseal",jsonStr,""); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, "Unsealing Vault server completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { if(HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { response = reqProcessor.process("/v2/unseal",jsonStr,""); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }  ResponseEntity<String> checkVaultHealth(); ResponseEntity<String> checkVaultSealStatus(); ResponseEntity<String> unseal(Unseal unseal); ResponseEntity<String> unsealProgress(String serverip);  }