forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpsTest.java
More file actions
153 lines (125 loc) · 4.65 KB
/
HttpsTest.java
File metadata and controls
153 lines (125 loc) · 4.65 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package io.jooby;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class HttpsTest {
@ServerTest
public void httpsPkcs12(ServerTestRunner runner) {
runner.define(app -> {
app.setServerOptions(new ServerOptions().setSecurePort(8433));
app.get("/",
ctx -> "schema: " + ctx.getScheme() + "; protocol: " + ctx.getProtocol() + "; secure: "
+ ctx.isSecure() + "; ssl: " + app.getServerOptions().getSsl().getType());
}).ready((http, https) -> {
https.get("/", rsp -> {
assertEquals("schema: https; protocol: HTTP/1.1; secure: true; ssl: PKCS12",
rsp.body().string());
});
http.get("/", rsp -> {
assertEquals("schema: http; protocol: HTTP/1.1; secure: false; ssl: PKCS12",
rsp.body().string());
});
});
}
@ServerTest
public void httpsX509(ServerTestRunner runner) {
runner.define(app -> {
SslOptions options = SslOptions.selfSigned(SslOptions.X509);
app.setServerOptions(new ServerOptions().setSsl(options));
app.get("/",
ctx -> "schema: " + ctx.getScheme() + "; protocol: " + ctx.getProtocol() + "; secure: "
+ ctx.isSecure() + "; ssl: " + app.getServerOptions().getSsl().getType());
}).ready((http, https) -> {
https.get("/", rsp -> {
assertEquals("schema: https; protocol: HTTP/1.1; secure: true; ssl: X509",
rsp.body().string());
});
http.get("/", rsp -> {
assertEquals("schema: http; protocol: HTTP/1.1; secure: false; ssl: X509",
rsp.body().string());
});
});
}
@ServerTest
public void forceSSL(ServerTestRunner runner) {
runner.define(app -> {
app.setContextPath("/secure");
app.setServerOptions(new ServerOptions().setSecurePort(8433));
app.before(new SSLHandler(true));
app.get("/{path}", ctx -> ctx.getRequestPath());
}).dontFollowRedirects().ready((http, https) -> {
http.get("/secure/path", rsp -> {
assertEquals("https://localhost:" + https.getPort() + "/secure/path",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
http.header("X-Forwarded-Host", "myhost.org");
http.get("/secure/path?a=b", rsp -> {
assertEquals("https://myhost.org/secure/path?a=b",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
});
}
@ServerTest
public void forceSSL2(ServerTestRunner runner) {
runner.define(app -> {
app.setServerOptions(new ServerOptions().setSecurePort(8433));
app.before(new SSLHandler(true));
app.get("/{path}", ctx -> ctx.getRequestPath());
}).dontFollowRedirects().ready((http, https) -> {
http.get("/path", rsp -> {
assertEquals("https://localhost:" + https.getPort() + "/path",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
http.header("X-Forwarded-Host", "myhost.org");
http.get("/path?a=b", rsp -> {
assertEquals("https://myhost.org/path?a=b",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
});
}
@ServerTest
public void forceSSLStatic(ServerTestRunner runner) {
runner.define(app -> {
app.setServerOptions(new ServerOptions().setSecurePort(8433));
app.before(new SSLHandler("static.org"));
app.get("/{path}", ctx -> ctx.getRequestPath());
}).dontFollowRedirects().ready(http -> {
http.get("/path", rsp -> {
assertEquals("https://static.org/path",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
http.header("X-Forwarded-Host", "myhost.org");
http.get("/path?a=b", rsp -> {
assertEquals("https://static.org/path?a=b",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
});
}
@ServerTest
public void forceSSLStatic2(ServerTestRunner runner) {
runner.define(app -> {
app.setContextPath("/ppp");
app.setServerOptions(new ServerOptions().setSecurePort(8433));
app.before(new SSLHandler("static.org"));
app.get("/{path}", ctx -> ctx.getRequestPath());
}).dontFollowRedirects().ready(http -> {
http.get("/ppp/path", rsp -> {
assertEquals("https://static.org/ppp/path",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
http.header("X-Forwarded-Host", "myhost.org");
http.get("/ppp/path?a=b", rsp -> {
assertEquals("https://static.org/ppp/path?a=b",
rsp.header("Location"));
assertEquals(302, rsp.code());
});
});
}
}