@Test public void testGetCertificateMetaDataInvalidResponse() { UserDetails userDetails = getMockUser(true); userDetails.setUsername(ADMIN_USER); String certType = "internal"; String certificatePath = SSLCertificateConstants.SSL_CERT_PATH + '/' + CERT_NAME; Response responseObj = getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, "{}"); when(ControllerUtil.getReqProcessor().process(GET_CERT_DETAIL, GET_CERT_DETAIL_VAL +certificatePath+"\"}",userDetails.getClientToken())).thenReturn(responseObj); SSLCertificateMetadataDetails certificateMetadataObj = certificateUtils.getCertificateMetaData(userDetails.getClientToken(),CERT_NAME,certType); assertEquals(certificateMetadataObj, null); }
public SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType){ String metaDataPath = (certificateType.equalsIgnoreCase("internal"))? SSLCertificateConstants.SSL_CERT_PATH :SSLCertificateConstants.SSL_EXTERNAL_CERT_PATH; String certificatePath = metaDataPath + '/' + certificateName; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate Info"). put(LogMessage.MESSAGE, String.format ("Trying to get Info for [%s]", certificatePath)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); Response response = ControllerUtil.getReqProcessor().process("/certmanager","{\"path\":\""+certificatePath+"\"}",token); SSLCertificateMetadataDetails certificateMetadataDetails = null; if(HttpStatus.OK.equals(response.getHttpstatus())){ try { ObjectMapper objMapper = new ObjectMapper(); JsonNode dataNode = objMapper.readTree(response.getResponse()).get("data"); certificateMetadataDetails = getCertificateInfo(dataNode); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get details about the certificate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } }else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get certificate metadata"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate metadata Info"). put(LogMessage.MESSAGE, "Getting metaDataInfo completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return certificateMetadataDetails; }
CertificateUtils { public SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType){ String metaDataPath = (certificateType.equalsIgnoreCase("internal"))? SSLCertificateConstants.SSL_CERT_PATH :SSLCertificateConstants.SSL_EXTERNAL_CERT_PATH; String certificatePath = metaDataPath + '/' + certificateName; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate Info"). put(LogMessage.MESSAGE, String.format ("Trying to get Info for [%s]", certificatePath)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); Response response = ControllerUtil.getReqProcessor().process("/certmanager","{\"path\":\""+certificatePath+"\"}",token); SSLCertificateMetadataDetails certificateMetadataDetails = null; if(HttpStatus.OK.equals(response.getHttpstatus())){ try { ObjectMapper objMapper = new ObjectMapper(); JsonNode dataNode = objMapper.readTree(response.getResponse()).get("data"); certificateMetadataDetails = getCertificateInfo(dataNode); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get details about the certificate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } }else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get certificate metadata"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate metadata Info"). put(LogMessage.MESSAGE, "Getting metaDataInfo completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return certificateMetadataDetails; } }
CertificateUtils { public SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType){ String metaDataPath = (certificateType.equalsIgnoreCase("internal"))? SSLCertificateConstants.SSL_CERT_PATH :SSLCertificateConstants.SSL_EXTERNAL_CERT_PATH; String certificatePath = metaDataPath + '/' + certificateName; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate Info"). put(LogMessage.MESSAGE, String.format ("Trying to get Info for [%s]", certificatePath)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); Response response = ControllerUtil.getReqProcessor().process("/certmanager","{\"path\":\""+certificatePath+"\"}",token); SSLCertificateMetadataDetails certificateMetadataDetails = null; if(HttpStatus.OK.equals(response.getHttpstatus())){ try { ObjectMapper objMapper = new ObjectMapper(); JsonNode dataNode = objMapper.readTree(response.getResponse()).get("data"); certificateMetadataDetails = getCertificateInfo(dataNode); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get details about the certificate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } }else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get certificate metadata"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate metadata Info"). put(LogMessage.MESSAGE, "Getting metaDataInfo completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return certificateMetadataDetails; }  }
CertificateUtils { public SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType){ String metaDataPath = (certificateType.equalsIgnoreCase("internal"))? SSLCertificateConstants.SSL_CERT_PATH :SSLCertificateConstants.SSL_EXTERNAL_CERT_PATH; String certificatePath = metaDataPath + '/' + certificateName; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate Info"). put(LogMessage.MESSAGE, String.format ("Trying to get Info for [%s]", certificatePath)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); Response response = ControllerUtil.getReqProcessor().process("/certmanager","{\"path\":\""+certificatePath+"\"}",token); SSLCertificateMetadataDetails certificateMetadataDetails = null; if(HttpStatus.OK.equals(response.getHttpstatus())){ try { ObjectMapper objMapper = new ObjectMapper(); JsonNode dataNode = objMapper.readTree(response.getResponse()).get("data"); certificateMetadataDetails = getCertificateInfo(dataNode); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get details about the certificate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } }else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get certificate metadata"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate metadata Info"). put(LogMessage.MESSAGE, "Getting metaDataInfo completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return certificateMetadataDetails; }  boolean hasAddOrRemovePermission(UserDetails userDetails, SSLCertificateMetadataDetails certificateMetaData); SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType); }
CertificateUtils { public SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType){ String metaDataPath = (certificateType.equalsIgnoreCase("internal"))? SSLCertificateConstants.SSL_CERT_PATH :SSLCertificateConstants.SSL_EXTERNAL_CERT_PATH; String certificatePath = metaDataPath + '/' + certificateName; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate Info"). put(LogMessage.MESSAGE, String.format ("Trying to get Info for [%s]", certificatePath)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); Response response = ControllerUtil.getReqProcessor().process("/certmanager","{\"path\":\""+certificatePath+"\"}",token); SSLCertificateMetadataDetails certificateMetadataDetails = null; if(HttpStatus.OK.equals(response.getHttpstatus())){ try { ObjectMapper objMapper = new ObjectMapper(); JsonNode dataNode = objMapper.readTree(response.getResponse()).get("data"); certificateMetadataDetails = getCertificateInfo(dataNode); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get details about the certificate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } }else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getCertificateMetaData"). put(LogMessage.MESSAGE, "Error while trying to get certificate metadata"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "Get Certificate metadata Info"). put(LogMessage.MESSAGE, "Getting metaDataInfo completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return certificateMetadataDetails; }  boolean hasAddOrRemovePermission(UserDetails userDetails, SSLCertificateMetadataDetails certificateMetaData); SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType);  }