@marcel91200 / caddy Mirror · read-only / commits / b5727b9c
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 10:30 UTC

ci: fix integration tests (#5079)

Mohammed Al Sahaf committed Sep 24, 2022 at 22:00 UTC b5727b9c443b45a83c463caa85a24783e901f144
9 files changed +379 -248
caddytest/caddytest.go
+1 -1
@@ -237,7 +237,7 @@ func validateTestPrerequisites() error {
237
238 if isCaddyAdminRunning() != nil {
239 // start inprocess caddy server
240 - os.Args = []string{"caddy", "run"}
240 + os.Args = []string{"caddy", "run", "--config", "./test.init.config", "--adapter", "caddyfile"}
241 go func() {
242 caddycmd.Main()
243 }()
caddytest/integration/autohttps_test.go
+21 -1
@@ -11,6 +11,8 @@ func TestAutoHTTPtoHTTPSRedirectsImplicitPort(t *testing.T) {
11 tester := caddytest.NewTester(t)
12 tester.InitServer(`
13 {
14 + admin localhost:2999
15 + skip_install_trust
16 http_port 9080
17 https_port 9443
18 }
@@ -25,6 +27,8 @@ func TestAutoHTTPtoHTTPSRedirectsExplicitPortSameAsHTTPSPort(t *testing.T) {
27 tester := caddytest.NewTester(t)
28 tester.InitServer(`
29 {
30 + skip_install_trust
31 + admin localhost:2999
32 http_port 9080
33 https_port 9443
34 }
@@ -39,6 +43,8 @@ func TestAutoHTTPtoHTTPSRedirectsExplicitPortDifferentFromHTTPSPort(t *testing.T
43 tester := caddytest.NewTester(t)
44 tester.InitServer(`
45 {
46 + skip_install_trust
47 + admin localhost:2999
48 http_port 9080
49 https_port 9443
50 }
@@ -53,6 +59,9 @@ func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
59 tester := caddytest.NewTester(t)
60 tester.InitServer(`
61 {
62 + "admin": {
63 + "listen": "localhost:2999"
64 + },
65 "apps": {
66 "http": {
67 "http_port": 9080,
@@ -74,7 +83,14 @@ func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
83 ]
84 }
85 }
77 - }
86 + },
87 + "pki": {
88 + "certificate_authorities": {
89 + "local": {
90 + "install_trust": false
91 + }
92 + }
93 + }
94 }
95 }
96 `, "json")
@@ -85,6 +101,8 @@ func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAll(t *testing.T) {
101 tester := caddytest.NewTester(t)
102 tester.InitServer(`
103 {
104 + skip_install_trust
105 + admin localhost:2999
106 http_port 9080
107 https_port 9443
108 local_certs
@@ -108,6 +126,8 @@ func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAllWithNoExplicitHTTPSit
126 tester := caddytest.NewTester(t)
127 tester.InitServer(`
128 {
129 + skip_install_trust
130 + admin localhost:2999
131 http_port 9080
132 https_port 9443
133 local_certs
caddytest/integration/caddyfile_test.go
+10 -4
@@ -14,9 +14,10 @@ func TestRespond(t *testing.T) {
14 tester := caddytest.NewTester(t)
15 tester.InitServer(`
16 {
17 + admin localhost:2999
18 http_port 9080
19 https_port 9443
19 - grace_period 1
20 + grace_period 1ns
21 }
22
23 localhost:9080 {
@@ -36,9 +37,10 @@ func TestRedirect(t *testing.T) {
37 tester := caddytest.NewTester(t)
38 tester.InitServer(`
39 {
40 + admin localhost:2999
41 http_port 9080
42 https_port 9443
41 - grace_period 1
43 + grace_period 1ns
44 }
45
46 localhost:9080 {
@@ -86,9 +88,11 @@ func TestReadCookie(t *testing.T) {
88 tester.Client.Jar.SetCookies(localhost, []*http.Cookie{&cookie})
89 tester.InitServer(`
90 {
91 + skip_install_trust
92 + admin localhost:2999
93 http_port 9080
94 https_port 9443
91 - grace_period 1
95 + grace_period 1ns
96 }
97
98 localhost:9080 {
@@ -110,9 +114,11 @@ func TestReplIndex(t *testing.T) {
114 tester := caddytest.NewTester(t)
115 tester.InitServer(`
116 {
117 + skip_install_trust
118 + admin localhost:2999
119 http_port 9080
120 https_port 9443
115 - grace_period 1
121 + grace_period 1ns
122 }
123
124 localhost:9080 {
caddytest/integration/handler_test.go
+3 -1
@@ -11,9 +11,11 @@ func TestBrowse(t *testing.T) {
11 tester := caddytest.NewTester(t)
12 tester.InitServer(`
13 {
14 + skip_install_trust
15 + admin localhost:2999
16 http_port 9080
17 https_port 9443
16 - grace_period 1
18 + grace_period 1ns
19 }
20 http://localhost:9080 {
21 file_server browse
caddytest/integration/map_test.go
+15 -1
@@ -11,9 +11,11 @@ func TestMap(t *testing.T) {
11 // arrange
12 tester := caddytest.NewTester(t)
13 tester.InitServer(`{
14 + skip_install_trust
15 + admin localhost:2999
16 http_port 9080
17 https_port 9443
16 - grace_period 1
18 + grace_period 1ns
19 }
20
21 localhost:9080 {
@@ -39,6 +41,8 @@ func TestMapRespondWithDefault(t *testing.T) {
41 // arrange
42 tester := caddytest.NewTester(t)
43 tester.InitServer(`{
44 + skip_install_trust
45 + admin localhost:2999
46 http_port 9080
47 https_port 9443
48 }
@@ -66,7 +70,17 @@ func TestMapAsJSON(t *testing.T) {
70 tester := caddytest.NewTester(t)
71 tester.InitServer(`
72 {
73 + "admin": {
74 + "listen": "localhost:2999"
75 + },
76 "apps": {
77 + "pki": {
78 + "certificate_authorities" : {
79 + "local" : {
80 + "install_trust": false
81 + }
82 + }
83 + },
84 "http": {
85 "http_port": 9080,
86 "https_port": 9443,
caddytest/integration/reverseproxy_test.go
+63
@@ -16,7 +16,17 @@ func TestSRVReverseProxy(t *testing.T) {
16 tester := caddytest.NewTester(t)
17 tester.InitServer(`
18 {
19 + "admin": {
20 + "listen": "localhost:2999"
21 + },
22 "apps": {
23 + "pki": {
24 + "certificate_authorities" : {
25 + "local" : {
26 + "install_trust": false
27 + }
28 + }
29 + },
30 "http": {
31 "grace_period": 1,
32 "servers": {
@@ -50,6 +60,13 @@ func TestSRVWithDial(t *testing.T) {
60 caddytest.AssertLoadError(t, `
61 {
62 "apps": {
63 + "pki": {
64 + "certificate_authorities" : {
65 + "local" : {
66 + "install_trust": false
67 + }
68 + }
69 + },
70 "http": {
71 "grace_period": 1,
72 "servers": {
@@ -115,7 +132,17 @@ func TestDialWithPlaceholderUnix(t *testing.T) {
132 tester := caddytest.NewTester(t)
133 tester.InitServer(`
134 {
135 + "admin": {
136 + "listen": "localhost:2999"
137 + },
138 "apps": {
139 + "pki": {
140 + "certificate_authorities" : {
141 + "local" : {
142 + "install_trust": false
143 + }
144 + }
145 + },
146 "http": {
147 "grace_period": 1,
148 "servers": {
@@ -157,7 +184,17 @@ func TestReverseProxyWithPlaceholderDialAddress(t *testing.T) {
184 tester := caddytest.NewTester(t)
185 tester.InitServer(`
186 {
187 + "admin": {
188 + "listen": "localhost:2999"
189 + },
190 "apps": {
191 + "pki": {
192 + "certificate_authorities" : {
193 + "local" : {
194 + "install_trust": false
195 + }
196 + }
197 + },
198 "http": {
199 "grace_period": 1,
200 "servers": {
@@ -241,7 +278,17 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
278 tester := caddytest.NewTester(t)
279 tester.InitServer(`
280 {
281 + "admin": {
282 + "listen": "localhost:2999"
283 + },
284 "apps": {
285 + "pki": {
286 + "certificate_authorities" : {
287 + "local" : {
288 + "install_trust": false
289 + }
290 + }
291 + },
292 "http": {
293 "grace_period": 1,
294 "servers": {
@@ -325,6 +372,13 @@ func TestSRVWithActiveHealthcheck(t *testing.T) {
372 caddytest.AssertLoadError(t, `
373 {
374 "apps": {
375 + "pki": {
376 + "certificate_authorities" : {
377 + "local" : {
378 + "install_trust": false
379 + }
380 + }
381 + },
382 "http": {
383 "grace_period": 1,
384 "servers": {
@@ -363,8 +417,11 @@ func TestReverseProxyHealthCheck(t *testing.T) {
417 tester := caddytest.NewTester(t)
418 tester.InitServer(`
419 {
420 + skip_install_trust
421 + admin localhost:2999
422 http_port 9080
423 https_port 9443
424 + grace_period 1ns
425 }
426 http://localhost:2020 {
427 respond "Hello, World!"
@@ -424,8 +481,11 @@ func TestReverseProxyHealthCheckUnixSocket(t *testing.T) {
481
482 tester.InitServer(fmt.Sprintf(`
483 {
484 + skip_install_trust
485 + admin localhost:2999
486 http_port 9080
487 https_port 9443
488 + grace_period 1ns
489 }
490 http://localhost:9080 {
491 reverse_proxy {
@@ -479,8 +539,11 @@ func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
539
540 tester.InitServer(fmt.Sprintf(`
541 {
542 + skip_install_trust
543 + admin localhost:2999
544 http_port 9080
545 https_port 9443
546 + grace_period 1ns
547 }
548 http://localhost:9080 {
549 reverse_proxy {
caddytest/integration/sni_test.go
+257 -240
@@ -11,92 +11,95 @@ func TestDefaultSNI(t *testing.T) {
11 // arrange
12 tester := caddytest.NewTester(t)
13 tester.InitServer(`{
14 - "apps": {
15 - "http": {
16 - "http_port": 9080,
17 - "https_port": 9443,
18 - "grace_period": 1,
19 - "servers": {
20 - "srv0": {
21 - "listen": [
22 - ":9443"
23 - ],
24 - "routes": [
25 - {
26 - "handle": [
27 - {
28 - "handler": "subroute",
29 - "routes": [
30 - {
31 - "handle": [
32 - {
33 - "body": "hello from a.caddy.localhost",
34 - "handler": "static_response",
35 - "status_code": 200
36 - }
37 - ],
38 - "match": [
39 - {
40 - "path": [
41 - "/version"
42 - ]
43 - }
44 - ]
45 - }
46 - ]
47 - }
48 - ],
49 - "match": [
50 - {
51 - "host": [
52 - "127.0.0.1"
53 - ]
54 - }
55 - ],
56 - "terminal": true
57 - }
58 - ],
59 - "tls_connection_policies": [
60 - {
61 - "certificate_selection": {
62 - "any_tag": ["cert0"]
63 - },
64 - "match": {
65 - "sni": [
66 - "127.0.0.1"
67 - ]
68 - }
69 - },
70 - {
71 - "default_sni": "*.caddy.localhost"
72 - }
73 - ]
74 - }
75 - }
76 - },
77 - "tls": {
78 - "certificates": {
79 - "load_files": [
80 - {
81 - "certificate": "/caddy.localhost.crt",
82 - "key": "/caddy.localhost.key",
83 - "tags": [
84 - "cert0"
85 - ]
86 - }
87 - ]
88 - }
89 - },
90 - "pki": {
91 - "certificate_authorities" : {
92 - "local" : {
93 - "install_trust": false
94 - }
95 - }
96 - }
97 - }
98 - }
99 - `, "json")
14 + "admin": {
15 + "listen": "localhost:2999"
16 + },
17 + "apps": {
18 + "http": {
19 + "http_port": 9080,
20 + "https_port": 9443,
21 + "grace_period": 1,
22 + "servers": {
23 + "srv0": {
24 + "listen": [
25 + ":9443"
26 + ],
27 + "routes": [
28 + {
29 + "handle": [
30 + {
31 + "handler": "subroute",
32 + "routes": [
33 + {
34 + "handle": [
35 + {
36 + "body": "hello from a.caddy.localhost",
37 + "handler": "static_response",
38 + "status_code": 200
39 + }
40 + ],
41 + "match": [
42 + {
43 + "path": [
44 + "/version"
45 + ]
46 + }
47 + ]
48 + }
49 + ]
50 + }
51 + ],
52 + "match": [
53 + {
54 + "host": [
55 + "127.0.0.1"
56 + ]
57 + }
58 + ],
59 + "terminal": true
60 + }
61 + ],
62 + "tls_connection_policies": [
63 + {
64 + "certificate_selection": {
65 + "any_tag": ["cert0"]
66 + },
67 + "match": {
68 + "sni": [
69 + "127.0.0.1"
70 + ]
71 + }
72 + },
73 + {
74 + "default_sni": "*.caddy.localhost"
75 + }
76 + ]
77 + }
78 + }
79 + },
80 + "tls": {
81 + "certificates": {
82 + "load_files": [
83 + {
84 + "certificate": "/caddy.localhost.crt",
85 + "key": "/caddy.localhost.key",
86 + "tags": [
87 + "cert0"
88 + ]
89 + }
90 + ]
91 + }
92 + },
93 + "pki": {
94 + "certificate_authorities" : {
95 + "local" : {
96 + "install_trust": false
97 + }
98 + }
99 + }
100 + }
101 + }
102 + `, "json")
103
104 // act and assert
105 // makes a request with no sni
@@ -108,97 +111,100 @@ func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
111 // arrange
112 tester := caddytest.NewTester(t)
113 tester.InitServer(`
111 - {
112 - "apps": {
113 - "http": {
114 - "http_port": 9080,
115 - "https_port": 9443,
116 - "grace_period": 1,
117 - "servers": {
118 - "srv0": {
119 - "listen": [
120 - ":9443"
121 - ],
122 - "routes": [
123 - {
124 - "handle": [
125 - {
126 - "handler": "subroute",
127 - "routes": [
128 - {
129 - "handle": [
130 - {
131 - "body": "hello from a",
132 - "handler": "static_response",
133 - "status_code": 200
134 - }
135 - ],
136 - "match": [
137 - {
138 - "path": [
139 - "/version"
140 - ]
141 - }
142 - ]
143 - }
144 - ]
145 - }
146 - ],
147 - "match": [
148 - {
149 - "host": [
150 - "a.caddy.localhost",
151 - "127.0.0.1"
152 - ]
153 - }
154 - ],
155 - "terminal": true
156 - }
157 - ],
158 - "tls_connection_policies": [
159 - {
160 - "certificate_selection": {
161 - "any_tag": ["cert0"]
162 - },
163 - "default_sni": "a.caddy.localhost",
164 - "match": {
165 - "sni": [
166 - "a.caddy.localhost",
167 - "127.0.0.1",
168 - ""
169 - ]
170 - }
171 - },
172 - {
173 - "default_sni": "a.caddy.localhost"
174 - }
175 - ]
176 - }
177 - }
178 - },
179 - "tls": {
180 - "certificates": {
181 - "load_files": [
182 - {
183 - "certificate": "/a.caddy.localhost.crt",
184 - "key": "/a.caddy.localhost.key",
185 - "tags": [
186 - "cert0"
187 - ]
188 - }
189 - ]
190 - }
191 - },
192 - "pki": {
193 - "certificate_authorities" : {
194 - "local" : {
195 - "install_trust": false
196 - }
197 - }
198 - }
199 - }
200 - }
201 - `, "json")
114 + {
115 + "admin": {
116 + "listen": "localhost:2999"
117 + },
118 + "apps": {
119 + "http": {
120 + "http_port": 9080,
121 + "https_port": 9443,
122 + "grace_period": 1,
123 + "servers": {
124 + "srv0": {
125 + "listen": [
126 + ":9443"
127 + ],
128 + "routes": [
129 + {
130 + "handle": [
131 + {
132 + "handler": "subroute",
133 + "routes": [
134 + {
135 + "handle": [
136 + {
137 + "body": "hello from a",
138 + "handler": "static_response",
139 + "status_code": 200
140 + }
141 + ],
142 + "match": [
143 + {
144 + "path": [
145 + "/version"
146 + ]
147 + }
148 + ]
149 + }
150 + ]
151 + }
152 + ],
153 + "match": [
154 + {
155 + "host": [
156 + "a.caddy.localhost",
157 + "127.0.0.1"
158 + ]
159 + }
160 + ],
161 + "terminal": true
162 + }
163 + ],
164 + "tls_connection_policies": [
165 + {
166 + "certificate_selection": {
167 + "any_tag": ["cert0"]
168 + },
169 + "default_sni": "a.caddy.localhost",
170 + "match": {
171 + "sni": [
172 + "a.caddy.localhost",
173 + "127.0.0.1",
174 + ""
175 + ]
176 + }
177 + },
178 + {
179 + "default_sni": "a.caddy.localhost"
180 + }
181 + ]
182 + }
183 + }
184 + },
185 + "tls": {
186 + "certificates": {
187 + "load_files": [
188 + {
189 + "certificate": "/a.caddy.localhost.crt",
190 + "key": "/a.caddy.localhost.key",
191 + "tags": [
192 + "cert0"
193 + ]
194 + }
195 + ]
196 + }
197 + },
198 + "pki": {
199 + "certificate_authorities" : {
200 + "local" : {
201 + "install_trust": false
202 + }
203 + }
204 + }
205 + }
206 + }
207 + `, "json")
208
209 // act and assert
210 // makes a request with no sni
@@ -209,69 +215,72 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
215 // arrange
216 tester := caddytest.NewTester(t)
217 tester.InitServer(`
212 - {
213 - "apps": {
214 - "http": {
215 - "http_port": 9080,
216 - "https_port": 9443,
217 - "grace_period": 1,
218 - "servers": {
219 - "srv0": {
220 - "listen": [
221 - ":9443"
222 - ],
223 - "routes": [
224 - {
225 - "handle": [
226 - {
227 - "body": "hello from a.caddy.localhost",
228 - "handler": "static_response",
229 - "status_code": 200
230 - }
231 - ],
232 - "match": [
233 - {
234 - "path": [
235 - "/version"
236 - ]
237 - }
238 - ]
239 - }
240 - ],
241 - "tls_connection_policies": [
242 - {
243 - "certificate_selection": {
244 - "any_tag": ["cert0"]
245 - },
246 - "default_sni": "a.caddy.localhost"
247 - }
248 - ]
249 - }
250 - }
251 - },
252 - "tls": {
253 - "certificates": {
254 - "load_files": [
255 - {
256 - "certificate": "/a.caddy.localhost.crt",
257 - "key": "/a.caddy.localhost.key",
258 - "tags": [
259 - "cert0"
260 - ]
261 - }
262 - ]
263 - }
264 - },
265 - "pki": {
266 - "certificate_authorities" : {
267 - "local" : {
268 - "install_trust": false
269 - }
270 - }
271 - }
272 - }
273 - }
274 - `, "json")
218 + {
219 + "admin": {
220 + "listen": "localhost:2999"
221 + },
222 + "apps": {
223 + "http": {
224 + "http_port": 9080,
225 + "https_port": 9443,
226 + "grace_period": 1,
227 + "servers": {
228 + "srv0": {
229 + "listen": [
230 + ":9443"
231 + ],
232 + "routes": [
233 + {
234 + "handle": [
235 + {
236 + "body": "hello from a.caddy.localhost",
237 + "handler": "static_response",
238 + "status_code": 200
239 + }
240 + ],
241 + "match": [
242 + {
243 + "path": [
244 + "/version"
245 + ]
246 + }
247 + ]
248 + }
249 + ],
250 + "tls_connection_policies": [
251 + {
252 + "certificate_selection": {
253 + "any_tag": ["cert0"]
254 + },
255 + "default_sni": "a.caddy.localhost"
256 + }
257 + ]
258 + }
259 + }
260 + },
261 + "tls": {
262 + "certificates": {
263 + "load_files": [
264 + {
265 + "certificate": "/a.caddy.localhost.crt",
266 + "key": "/a.caddy.localhost.key",
267 + "tags": [
268 + "cert0"
269 + ]
270 + }
271 + ]
272 + }
273 + },
274 + "pki": {
275 + "certificate_authorities" : {
276 + "local" : {
277 + "install_trust": false
278 + }
279 + }
280 + }
281 + }
282 + }
283 + `, "json")
284
285 // act and assert
286 // makes a request with no sni
@@ -281,6 +290,7 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
290 func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
291 caddytest.AssertAdapt(t, `
292 {
293 + skip_install_trust
294 default_sni a.caddy.localhost
295 }
296 :80 {
@@ -316,6 +326,13 @@ func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
326 ]
327 }
328 }
329 + },
330 + "pki": {
331 + "certificate_authorities": {
332 + "local": {
333 + "install_trust": false
334 + }
335 + }
336 }
337 }
338 }`)
caddytest/integration/stream_test.go
+6
@@ -23,6 +23,9 @@ func TestH2ToH2CStream(t *testing.T) {
23 tester := caddytest.NewTester(t)
24 tester.InitServer(`
25 {
26 + "admin": {
27 + "listen": "localhost:2999"
28 + },
29 "apps": {
30 "http": {
31 "http_port": 9080,
@@ -206,6 +209,9 @@ func TestH2ToH1ChunkedResponse(t *testing.T) {
209 tester := caddytest.NewTester(t)
210 tester.InitServer(`
211 {
212 + "admin": {
213 + "listen": "localhost:2999"
214 + },
215 "logging": {
216 "logs": {
217 "default": {
caddytest/integration/test.init.config new
+3
@@ -0,0 +1,3 @@
1 +{
2 + admin localhost:2999
3 +}