### Question:
InternalTlsCertificateService { @PreAuthorize("hasAuthority('EXPORT_PROXY_INTERNAL_CERT')") public byte[] exportInternalTlsCertificate() { X509Certificate certificate = internalTlsCertificateRepository.getInternalTlsCertificate(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try ( GzipCompressorOutputStream gzipCompressorOutputStream = new GzipCompressorOutputStream(byteArrayOutputStream); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(gzipCompressorOutputStream); TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(bufferedOutputStream) ) { ByteArrayOutputStream pemStream = new ByteArrayOutputStream(); CryptoUtils.writeCertificatePem(certificate.getEncoded(), pemStream); writeFileToArchive(tarOutputStream, pemStream.toByteArray(), CERT_PEM_FILENAME); writeFileToArchive(tarOutputStream, certificate.getEncoded(), CERT_CER_FILENAME); } catch (IOException | CertificateEncodingException e) { log.error("writing certificate file failed", e); throw new RuntimeException(e); } return byteArrayOutputStream.toByteArray(); }  @PreAuthorize("hasAuthority('VIEW_PROXY_INTERNAL_CERT')") X509Certificate getInternalTlsCertificate(); @PreAuthorize("hasAuthority('EXPORT_PROXY_INTERNAL_CERT')") byte[] exportInternalTlsCertificate();  }### Answer:
@Test public void getExportedInternalTlsCertificate() throws Exception { byte[] certFileData = internalTlsCertificateService.exportInternalTlsCertificate(); assertTrue(certFileData.length > 100); InputStream exportedTarStream = getClass().getClassLoader() .getResourceAsStream("exported-example-certs.tar.gz"); Map<String, byte[]> exportedExampleFiles = extractTarGZ(IOUtils.toByteArray(exportedTarStream)); Map<String, byte[]> filesFromService = extractTarGZ( internalTlsCertificateService.exportInternalTlsCertificate()); assertEquals(exportedExampleFiles.size(), filesFromService.size()); for (String fileName: exportedExampleFiles.keySet()) { assertTrue(filesFromService.containsKey(fileName)); assertTrue(Arrays.equals(exportedExampleFiles.get(fileName), filesFromService.get(fileName))); } }