TransportSecurityOptionsJsonSerializer { public void serialize(OutputStream out, TransportSecurityOptions options) { try { mapper.writerWithDefaultPrettyPrinter().writeValue(out, toTransportSecurityOptionsEntity(options)); } catch (IOException e) { throw new UncheckedIOException(e); } }  TransportSecurityOptions deserialize(InputStream in); void serialize(OutputStream out, TransportSecurityOptions options);  }
@Test public void can_serialize_options_without_authorized_peers() throws IOException { TransportSecurityOptions options = new TransportSecurityOptions.Builder() .withCertificates(Paths.get("certs.pem"), Paths.get("myhost.key")) .withCaCertificates(Paths.get("my_cas.pem")) .withAcceptedCiphers(com.yahoo.vespa.jdk8compat.List.of("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" , "TLS_AES_256_GCM_SHA384")) .withHostnameValidationDisabled(true) .build(); File outputFile = tempDirectory.newFile(); try (OutputStream out = Files.newOutputStream(outputFile.toPath())) { new TransportSecurityOptionsJsonSerializer().serialize(out, options); } String expectedOutput = new String(Files.readAllBytes(TEST_CONFIG_FILE)); String actualOutput = new String(Files.readAllBytes(outputFile.toPath())); assertJsonEquals(expectedOutput, actualOutput); }
@Test public void disable_hostname_validation_is_not_serialized_if_false() throws IOException { TransportSecurityOptions options = new TransportSecurityOptions.Builder() .withCertificates(Paths.get("certs.pem"), Paths.get("myhost.key")) .withCaCertificates(Paths.get("my_cas.pem")) .withHostnameValidationDisabled(false) .build(); File outputFile = tempDirectory.newFile(); try (OutputStream out = Files.newOutputStream(outputFile.toPath())) { new TransportSecurityOptionsJsonSerializer().serialize(out, options); } String expectedOutput = new String(Files.readAllBytes( Paths.get("src/test/resources/transport-security-options-with-disable-hostname-validation-set-to-false.json"))); String actualOutput = new String(Files.readAllBytes(outputFile.toPath())); assertJsonEquals(expectedOutput, actualOutput); }