-
-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathSslOptionsTest.java
More file actions
126 lines (105 loc) · 4.21 KB
/
SslOptionsTest.java
File metadata and controls
126 lines (105 loc) · 4.21 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import static com.typesafe.config.ConfigValueFactory.fromAnyRef;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
public class SslOptionsTest {
@Test
public void shouldDoNothingOnMissingPaths() {
Config config = ConfigFactory.empty().resolve();
assertEquals(false, SslOptions.from(config).isPresent());
}
@Test
public void shouldFailOnInvalidSslType() {
Config config = ConfigFactory.empty().withValue("ssl.type", fromAnyRef("xxxx")).resolve();
assertThrows(UnsupportedOperationException.class, () -> SslOptions.from(config));
}
@Test
public void shouldLoadSelfSigned() {
Config config =
ConfigFactory.empty().withValue("ssl.type", fromAnyRef("self-signed")).resolve();
SslOptions options = SslOptions.from(config).get();
assertEquals(SslOptions.PKCS12, options.getType());
assertNotNull(options.getCert());
assertEquals("changeit", options.getPassword());
}
@Test
public void shouldLoadPKCS12FromConfig() {
Config config =
ConfigFactory.empty()
.withValue("ssl.type", fromAnyRef("pkcs12"))
.withValue("ssl.cert", fromAnyRef("ssl/test.p12"))
.withValue("ssl.password", fromAnyRef("changeit"))
.withValue("ssl.trust.cert", fromAnyRef("ssl/trust.p12"))
.withValue("ssl.trust.password", fromAnyRef("pass"))
.resolve();
SslOptions options = SslOptions.from(config).get();
assertEquals(SslOptions.PKCS12, options.getType());
assertNotNull(options.getCert());
assertEquals("changeit", options.getPassword());
assertNotNull(options.getTrustCert());
assertEquals("pass", options.getTrustPassword());
}
@Test
public void shouldLoadX509FromConfig() {
Config config =
ConfigFactory.empty()
.withValue("ssl.type", fromAnyRef("x509"))
.withValue("ssl.cert", fromAnyRef("ssl/test.crt"))
.withValue("ssl.key", fromAnyRef("ssl/test.key"))
.resolve();
SslOptions options = SslOptions.from(config).get();
assertEquals(SslOptions.X509, options.getType());
assertNotNull(options.getCert());
assertNotNull(options.getPrivateKey());
}
@Test
public void shouldLoadX509WithPasswordFromConfig() {
Config config =
ConfigFactory.empty()
.withValue("ssl.type", fromAnyRef("x509"))
.withValue("ssl.cert", fromAnyRef("ssl/test.crt"))
.withValue("ssl.key", fromAnyRef("ssl/test.key"))
.withValue("ssl.password", fromAnyRef("changeit"))
.resolve();
SslOptions options = SslOptions.from(config).get();
assertEquals(SslOptions.X509, options.getType());
assertNotNull(options.getCert());
assertNotNull(options.getPrivateKey());
assertEquals("changeit", options.getPassword());
}
@Test
public void shouldParseSingleProtocol() {
Config config =
ConfigFactory.empty()
.withValue("ssl.protocol", fromAnyRef("TLSv1.2"))
.withValue("ssl.cert", fromAnyRef("ssl/test.crt"))
.withValue("ssl.key", fromAnyRef("ssl/test.key"))
.withValue("ssl.password", fromAnyRef("changeit"))
.resolve();
SslOptions options = SslOptions.from(config).get();
assertEquals(Collections.singletonList("TLSv1.2"), options.getProtocol());
}
@Test
public void shouldParseProtocols() {
Config config =
ConfigFactory.empty()
.withValue("ssl.protocol", fromAnyRef(Arrays.asList("TLSv1.2", "TLSv1.3")))
.withValue("ssl.cert", fromAnyRef("ssl/test.crt"))
.withValue("ssl.key", fromAnyRef("ssl/test.key"))
.withValue("ssl.password", fromAnyRef("changeit"))
.resolve();
SslOptions options = SslOptions.from(config).get();
assertEquals(Arrays.asList("TLSv1.2", "TLSv1.3"), options.getProtocol());
}
}