diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-11-19 16:37:32 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-11-19 16:37:35 +0100 |
commit | 64ad086cb1789f1881ff44d1432c905fecc07e41 (patch) | |
tree | 6e511dffa8039e3749303053d8fa3be7c4bd882b /security-utils/src/test/java/com/yahoo/security/tls/json/TransportSecurityOptionsJsonSerializerTest.java | |
parent | aa8dfde70a0c045629d645f49c50a2963f8ff66a (diff) |
Rewrite JSON serialization of TransportSecurityOptions
- Use Jackson data bindings on TransportSecurityOptionsEntity
- Add serialization to JSON
- Add AuthorizedPeers to TransportSecurityOptions
Diffstat (limited to 'security-utils/src/test/java/com/yahoo/security/tls/json/TransportSecurityOptionsJsonSerializerTest.java')
-rw-r--r-- | security-utils/src/test/java/com/yahoo/security/tls/json/TransportSecurityOptionsJsonSerializerTest.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/json/TransportSecurityOptionsJsonSerializerTest.java b/security-utils/src/test/java/com/yahoo/security/tls/json/TransportSecurityOptionsJsonSerializerTest.java new file mode 100644 index 00000000000..a3e5bef115b --- /dev/null +++ b/security-utils/src/test/java/com/yahoo/security/tls/json/TransportSecurityOptionsJsonSerializerTest.java @@ -0,0 +1,46 @@ +package com.yahoo.security.tls.json; + +import com.yahoo.security.tls.TransportSecurityOptions; +import com.yahoo.security.tls.policy.AuthorizedPeers; +import com.yahoo.security.tls.policy.HostGlobPattern; +import com.yahoo.security.tls.policy.PeerPolicy; +import com.yahoo.security.tls.policy.RequiredPeerCredential; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; + +import static com.yahoo.security.tls.policy.RequiredPeerCredential.Field.*; +import static org.junit.Assert.*; + +/** + * @author bjorncs + */ +public class TransportSecurityOptionsJsonSerializerTest { + + @Test + public void can_serialize_and_deserialize_transport_security_options() { + TransportSecurityOptions options = new TransportSecurityOptions.Builder() + .withCaCertificate(Paths.get("/path/to/ca-certs.pem")) + .withCertificate(Paths.get("/path/to/cert.pem"), Paths.get("/path/to/key.pem")) + .withAuthorizedPeers( + new AuthorizedPeers( + new HashSet<>(Arrays.asList( + new PeerPolicy("cfgserver", Arrays.asList( + new RequiredPeerCredential(CN, new HostGlobPattern("mycfgserver")), + new RequiredPeerCredential(SAN_DNS, new HostGlobPattern("*.suffix.com")))), + new PeerPolicy("node", Collections.singletonList(new RequiredPeerCredential(CN, new HostGlobPattern("hostname")))))))) + .build(); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + TransportSecurityOptionsJsonSerializer serializer = new TransportSecurityOptionsJsonSerializer(); + serializer.serialize(out, options); + TransportSecurityOptions deserializedOptions = serializer.deserialize(new ByteArrayInputStream(out.toByteArray())); + assertEquals(options, deserializedOptions); + } + +}
\ No newline at end of file |