SSLCertificateService { public ResponseEntity<String> getServiceCertificates(String token, UserDetails userDetails, String certName, Integer limit, Integer offset, String certType) throws Exception { if(!certType.matches(SSLCertificateConstants.CERT_TYPE_MATCH_STRING)){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, "getServiceCertificates") .put(LogMessage.MESSAGE, "Invalid user inputs") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid input values\"]}"); } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getServiceCertificates"). put(LogMessage.MESSAGE, String.format("Trying to get list of Ssl certificatests")). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String metaDataPath = (certType.equalsIgnoreCase("internal"))? SSLCertificateConstants.SSL_CERT_PATH :SSLCertificateConstants.SSL_EXTERNAL_CERT_PATH; Response response = new Response(); String certListStr = ""; String tokenValue= (userDetails.isAdmin())? token :userDetails.getSelfSupportToken(); response = getMetadata(tokenValue, metaDataPath); if (HttpStatus.OK.equals(response.getHttpstatus())) { certListStr = getsslmetadatalist(response.getResponse(),tokenValue,userDetails,certName,limit,offset,metaDataPath); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getServiceCertificates"). put(LogMessage.MESSAGE, "Certificates fetched from metadata"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(certListStr); } else if (HttpStatus.NOT_FOUND.equals(response.getHttpstatus())) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getServiceCertificates"). put(LogMessage.MESSAGE, "Reterived empty certificate list from metadata"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body(certListStr); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getServiceCertificates"). put(LogMessage.MESSAGE, "Failed to get certificate list from metadata"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(certListStr); }  ResponseEntity<String> authenticate(CertManagerLoginRequest certManagerLoginRequest); CertManagerLogin login(CertManagerLoginRequest certManagerLoginRequest); ResponseEntity<String> generateSSLCertificate(SSLCertificateRequest sslCertificateRequest,
                                                               UserDetails userDetails ,String token); ResponseEntity<String> getServiceCertificates(String token, UserDetails userDetails, String certName, Integer limit, Integer offset, String certType); String getNclmToken(); ResponseEntity<String> getTargetSystemList(String token, UserDetails userDetails,String certType); ResponseEntity<String> getTargetSystemServiceList(String token, UserDetails userDetails, String targetSystemId); ResponseEntity<String> getRevocationReasons(Integer certificateId, String token); ResponseEntity<String> issueRevocationRequest(String certType, String certificateName, UserDetails userDetails, String token,
			RevocationRequest revocationRequest); String getCurrentLocalDateTimeStamp(); Boolean validateOwnerPermissionForNonAdmin(UserDetails userDetails, String certificateName); ResponseEntity<String> addUserToCertificate(CertificateUser certificateUser, UserDetails userDetails, boolean addSudoPermission); ResponseEntity<String> addGroupToCertificate(UserDetails userDetails, String userToken, CertificateGroup certificateGroup); boolean isAuthorized(UserDetails userDetails, String certificatename, String certType); ResponseEntity<String> addingGroupToCertificate(String token, CertificateGroup certificateGroup, UserDetails userDetails); ResponseEntity<String> associateApproletoCertificate(CertificateApprole certificateApprole, UserDetails userDetails); boolean hasDownloadPermission(String certificateName, UserDetails userDetails, String certType); SSLCertificateMetadataDetails getCertificateMetadata(String token, String certificateName); ResponseEntity<InputStreamResource> downloadCertificateWithPrivateKey(String token, CertificateDownloadRequest certificateDownloadRequest, UserDetails userDetails); ResponseEntity<InputStreamResource> downloadCertificateWithPrivateKey(CertificateDownloadRequest certificateDownloadRequest, SSLCertificateMetadataDetails sslCertificateMetadataDetails); ResponseEntity<InputStreamResource> downloadCertificate(String token, UserDetails userDetails,
                                                                   String certificateName, String certificateType,
                                                                   String sslCertType); ResponseEntity<String> getCertificateDetails(String token, String certificateName, String certificateType); ResponseEntity<String> renewCertificate(String certType, String certificateName, UserDetails userDetails, String token); ResponseEntity<String> removeUserFromCertificate(CertificateUser certificateUser, UserDetails userDetails); ResponseEntity<String> removeGroupFromCertificate(CertificateGroup certificateGroup, UserDetails userDetails); ResponseEntity<String> getListOfCertificates(String token, String certificateType); ResponseEntity<String> updateCertOwner(String token, String certType,String certName,String certOwnerEmailId,  UserDetails userDetails); ResponseEntity<String> validateApprovalStatusAndGetCertificateDetails(String certName, String certType,
			UserDetails userDetails); ResponseEntity<String> deleteCertificate( String token, String certType, String certificateName, UserDetails userDetails); Boolean validateCertOwnerPermissionForNonAdmin(UserDetails userDetails, String certificateName, String certType); ResponseEntity<String> getAllCertificates(String token, String certName, Integer limit, Integer offset); ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType); ResponseEntity<String> checkCertificateStatus(String certName, String certType,	
			UserDetails userDetails); ResponseEntity<String> getAllSelfServiceGroups(UserDetails userDetails); ResponseEntity<String> removeGroupFromCertificateForDelete(CertificateGroup certificateGroup, UserDetails userDetails); @Value("${sslcertmanager.targetsystemgroup.public_single_san.ts_gp_id}")
    private int public_single_san_ts_gp_id; @Value("${sslcertmanager.targetsystemgroup.public_multi_san.ts_gp_id}")
    private int public_multi_san_ts_gp_id; }
@Test public void getSSLCertificate_Succes()throws Exception{ String token = "12345"; Response response =getMockResponse(HttpStatus.OK, true, "{ \"keys\": [ { \"akamid\": \"102463\", \"applicationName\": \"tvs\", " + " \"applicationOwnerEmailId\": \"abcdef@mail.com\", \"applicationTag\": \"TVS\", " + " \"authority\": \"T-Mobile Issuing CA 01 - SHA2\", \"certCreatedBy\": \"rob\", " + " \"certOwnerEmailId\": \"ntest@gmail.com\", \"certType\": \"internal\", " + " \"certificateId\": 59480, \"certificateName\": \"CertificateName.t-mobile.com\", " + " \"certificateStatus\": \"Active\", \"containerName\": \"VenafiBin_12345\", " + " \"createDate\": \"2020-06-24T03:16:29-07:00\", \"expiryDate\": \"2021-06-24T03:16:29-07:00\", " + " \"projectLeadEmailId\": \"project@email.com\" } ]}"); Response certResponse =getMockResponse(HttpStatus.OK, true, "{ \"data\": { \"keys\": [ \"CertificateName.t-mobile.com\" ] }}"); token = "5PDrOhsy4ig8L3EpsJZSLAMg"; UserDetails user1 = new UserDetails(); user1.setUsername("normaluser"); user1.setAdmin(true); user1.setClientToken(token); user1.setSelfSupportToken(token); when(reqProcessor.process(Mockito.eq("/sslcert"),Mockito.anyString(),Mockito.eq(token))).thenReturn(certResponse); when(reqProcessor.process("/sslcert", "{\"path\":\"metadata/sslcerts/CertificateName.t-mobile.com\"}",token)).thenReturn(response); ResponseEntity<String> responseEntityActual = sSLCertificateService.getServiceCertificates(token, user1, "",1,0,"internal"); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); }
@Test public void getSSLCertificate_Failure()throws Exception{ String token = "12345"; Response response =getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, "{ \"keys\": [ { \"akamid\": \"102463\", \"applicationName\": \"tvs\", " + " \"applicationOwnerEmailId\": \"abcdef@mail.com\", \"applicationTag\": \"TVS\", " + " \"authority\": \"T-Mobile Issuing CA 01 - SHA2\", \"certCreatedBy\": \"rob\", " + " \"certOwnerEmailId\": \"ntest@gmail.com\", \"certType\": \"internal\", " + " \"certificateId\": 59480, \"certificateName\": \"CertificateName.t-mobile.com\", " + " \"certificateStatus\": \"Active\", \"containerName\": \"VenafiBin_12345\", " + " \"createDate\": \"2020-06-24T03:16:29-07:00\", \"expiryDate\": \"2021-06-24T03:16:29-07:00\", " + " \"projectLeadEmailId\": \"project@email.com\" } ]}"); Response certResponse =getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, "{ \"data\": { \"keys\": [ \"CertificateName.t-mobile.com\" ] }}"); token = "5PDrOhsy4ig8L3EpsJZSLAMg"; UserDetails user1 = new UserDetails(); user1.setUsername("normaluser"); user1.setAdmin(true); user1.setClientToken(token); user1.setSelfSupportToken(token); when(reqProcessor.process(Mockito.eq("/sslcert"),Mockito.anyString(),Mockito.eq(token))).thenReturn(certResponse); when(reqProcessor.process("/sslcert", "{\"path\":\"metadata/sslcerts/CertificateName.t-mobile.com\"}",token)).thenReturn(response); ResponseEntity<String> responseEntityActual = sSLCertificateService.getServiceCertificates(token, user1, "",1,0,"internal"); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntityActual.getStatusCode()); }