blob: 952c4d05972859d88e421bf9a912c5da3de0c874 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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 com.yahoo.security.tls.policy.Role;
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 java.util.Collections.singleton;
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()
.withCaCertificates(Paths.get("/path/to/ca-certs.pem"))
.withCertificates(Paths.get("/path/to/cert.pem"), Paths.get("/path/to/key.pem"))
.withAuthorizedPeers(
new AuthorizedPeers(
new HashSet<>(Arrays.asList(
new PeerPolicy("cfgserver", singleton(new Role("myrole")), Arrays.asList(
new RequiredPeerCredential(CN, new HostGlobPattern("mycfgserver")),
new RequiredPeerCredential(SAN_DNS, new HostGlobPattern("*.suffix.com")))),
new PeerPolicy("node", singleton(new Role("anotherrole")), 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);
}
}
|