@marcel91200 / caddy Mirror · read-only / commits / 8cc60e68
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 14, 05:15 UTC

ci: test local CA and update SNI tests (#3145)

* run caddy tests in process * call main with run args * exclude tests - windows * include json example * disable caddyfile tests, include json test with non trusted local ca * converted SNI tests to json syntax

Mark Sargent committed Mar 23, 2020 at 13:08 UTC 8cc60e6896b7c030891a3578ae2405a14b2fed49
3 files changed +306 -69
caddytest/caddytest.go
+29 -1
@@ -18,6 +18,11 @@ import (
18 "strings"
19 "testing"
20 "time"
21 +
22 + caddycmd "github.com/caddyserver/caddy/v2/cmd"
23 +
24 + // plug in Caddy modules here
25 + _ "github.com/caddyserver/caddy/v2/modules/standard"
26 )
27
28 // Defaults store any configuration required to make the tests run
@@ -145,6 +150,30 @@ func validateTestPrerequisites() error {
150 }
151 }
152
153 + if isCaddyAdminRunning() != nil {
154 + // start inprocess caddy server
155 + os.Args = []string{"caddy", "run"}
156 + go func() {
157 + caddycmd.Main()
158 + }()
159 +
160 + // wait for caddy to start
161 + retries := 4
162 + for ; retries > 0 && isCaddyAdminRunning() != nil; retries-- {
163 + time.Sleep(10 * time.Millisecond)
164 + }
165 + }
166 +
167 + // assert that caddy is running
168 + if err := isCaddyAdminRunning(); err != nil {
169 + return err
170 + }
171 +
172 + arePrerequisitesValid = true
173 + return nil
174 +}
175 +
176 +func isCaddyAdminRunning() error {
177 // assert that caddy is running
178 client := &http.Client{
179 Timeout: time.Second * 2,
@@ -154,7 +183,6 @@ func validateTestPrerequisites() error {
183 return errors.New("caddy integration test caddy server not running. Expected to be listening on localhost:2019")
184 }
185
157 - arePrerequisitesValid = true
186 return nil
187 }
188
caddytest/integration/caddyfile_test.go
-68
@@ -66,71 +66,3 @@ func TestDuplicateHosts(t *testing.T) {
66 "caddyfile",
67 "duplicate site address not allowed")
68 }
69 -
70 -func TestDefaultSNI(t *testing.T) {
71 -
72 - // arrange
73 - caddytest.InitServer(t, `
74 - {
75 - http_port 9080
76 - https_port 9443
77 - default_sni *.caddy.localhost
78 - }
79 -
80 - 127.0.0.1:9443 {
81 - tls /caddy.localhost.crt /caddy.localhost.key
82 - respond /version 200 {
83 - body "hello from a"
84 - }
85 - }
86 - `, "caddyfile")
87 -
88 - // act and assert
89 - caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
90 -}
91 -
92 -func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
93 -
94 - // arrange
95 - caddytest.InitServer(t, `
96 - {
97 - http_port 9080
98 - https_port 9443
99 - default_sni a.caddy.localhost
100 - }
101 -
102 - a.caddy.localhost:9443, 127.0.0.1:9443 {
103 - tls /a.caddy.localhost.crt /a.caddy.localhost.key
104 - respond /version 200 {
105 - body "hello from a"
106 - }
107 - }
108 - `, "caddyfile")
109 -
110 - // act and assert
111 - // makes a request with no sni
112 - caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
113 -}
114 -
115 -func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
116 -
117 - // arrange
118 - caddytest.InitServer(t, `
119 - {
120 - http_port 9080
121 - https_port 9443
122 - default_sni a.caddy.localhost
123 - }
124 -
125 - :9443 {
126 - tls /a.caddy.localhost.crt /a.caddy.localhost.key
127 - respond /version 200 {
128 - body "hello from a.caddy.localhost"
129 - }
130 - }
131 - `, "caddyfile")
132 -
133 - // act and assert
134 - // makes a request with no sni
135 - caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
136 -}
caddytest/integration/sni_test.go new
+277
@@ -0,0 +1,277 @@
1 +package integration
2 +
3 +import (
4 + "testing"
5 +
6 + "github.com/caddyserver/caddy/v2/caddytest"
7 +)
8 +
9 +func TestDefaultSNI(t *testing.T) {
10 +
11 + // arrange
12 + caddytest.InitServer(t, `{
13 + "apps": {
14 + "http": {
15 + "http_port": 9080,
16 + "https_port": 9443,
17 + "servers": {
18 + "srv0": {
19 + "listen": [
20 + ":9443"
21 + ],
22 + "routes": [
23 + {
24 + "handle": [
25 + {
26 + "handler": "subroute",
27 + "routes": [
28 + {
29 + "handle": [
30 + {
31 + "body": "hello from a.caddy.localhost",
32 + "handler": "static_response",
33 + "status_code": 200
34 + }
35 + ],
36 + "match": [
37 + {
38 + "path": [
39 + "/version"
40 + ]
41 + }
42 + ]
43 + }
44 + ]
45 + }
46 + ],
47 + "match": [
48 + {
49 + "host": [
50 + "127.0.0.1"
51 + ]
52 + }
53 + ],
54 + "terminal": true
55 + }
56 + ],
57 + "tls_connection_policies": [
58 + {
59 + "certificate_selection": {
60 + "policy": "custom",
61 + "tag": "cert0"
62 + },
63 + "match": {
64 + "sni": [
65 + "127.0.0.1"
66 + ]
67 + }
68 + },
69 + {
70 + "default_sni": "*.caddy.localhost"
71 + }
72 + ]
73 + }
74 + }
75 + },
76 + "tls": {
77 + "certificates": {
78 + "load_files": [
79 + {
80 + "certificate": "/caddy.localhost.crt",
81 + "key": "/caddy.localhost.key",
82 + "tags": [
83 + "cert0"
84 + ]
85 + }
86 + ]
87 + }
88 + },
89 + "pki": {
90 + "certificate_authorities" : {
91 + "local" : {
92 + "install_trust": false
93 + }
94 + }
95 + }
96 + }
97 + }
98 + `, "json")
99 +
100 + // act and assert
101 + // makes a request with no sni
102 + caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
103 +}
104 +
105 +func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
106 +
107 + // arrange
108 + caddytest.InitServer(t, `
109 + {
110 + "apps": {
111 + "http": {
112 + "http_port": 9080,
113 + "https_port": 9443,
114 + "servers": {
115 + "srv0": {
116 + "listen": [
117 + ":9443"
118 + ],
119 + "routes": [
120 + {
121 + "handle": [
122 + {
123 + "handler": "subroute",
124 + "routes": [
125 + {
126 + "handle": [
127 + {
128 + "body": "hello from a",
129 + "handler": "static_response",
130 + "status_code": 200
131 + }
132 + ],
133 + "match": [
134 + {
135 + "path": [
136 + "/version"
137 + ]
138 + }
139 + ]
140 + }
141 + ]
142 + }
143 + ],
144 + "match": [
145 + {
146 + "host": [
147 + "a.caddy.localhost",
148 + "127.0.0.1"
149 + ]
150 + }
151 + ],
152 + "terminal": true
153 + }
154 + ],
155 + "tls_connection_policies": [
156 + {
157 + "certificate_selection": {
158 + "policy": "custom",
159 + "tag": "cert0"
160 + },
161 + "default_sni": "a.caddy.localhost",
162 + "match": {
163 + "sni": [
164 + "a.caddy.localhost",
165 + "127.0.0.1",
166 + ""
167 + ]
168 + }
169 + },
170 + {
171 + "default_sni": "a.caddy.localhost"
172 + }
173 + ]
174 + }
175 + }
176 + },
177 + "tls": {
178 + "certificates": {
179 + "load_files": [
180 + {
181 + "certificate": "/a.caddy.localhost.crt",
182 + "key": "/a.caddy.localhost.key",
183 + "tags": [
184 + "cert0"
185 + ]
186 + }
187 + ]
188 + }
189 + },
190 + "pki": {
191 + "certificate_authorities" : {
192 + "local" : {
193 + "install_trust": false
194 + }
195 + }
196 + }
197 + }
198 + }
199 + `, "json")
200 +
201 + // act and assert
202 + // makes a request with no sni
203 + caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
204 +}
205 +
206 +func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
207 +
208 + // arrange
209 + caddytest.InitServer(t, `
210 + {
211 + "apps": {
212 + "http": {
213 + "http_port": 9080,
214 + "https_port": 9443,
215 + "servers": {
216 + "srv0": {
217 + "listen": [
218 + ":9443"
219 + ],
220 + "routes": [
221 + {
222 + "handle": [
223 + {
224 + "body": "hello from a.caddy.localhost",
225 + "handler": "static_response",
226 + "status_code": 200
227 + }
228 + ],
229 + "match": [
230 + {
231 + "path": [
232 + "/version"
233 + ]
234 + }
235 + ]
236 + }
237 + ],
238 + "tls_connection_policies": [
239 + {
240 + "certificate_selection": {
241 + "policy": "custom",
242 + "tag": "cert0"
243 + },
244 + "default_sni": "a.caddy.localhost"
245 + }
246 + ]
247 + }
248 + }
249 + },
250 + "tls": {
251 + "certificates": {
252 + "load_files": [
253 + {
254 + "certificate": "/a.caddy.localhost.crt",
255 + "key": "/a.caddy.localhost.key",
256 + "tags": [
257 + "cert0"
258 + ]
259 + }
260 + ]
261 + }
262 + },
263 + "pki": {
264 + "certificate_authorities" : {
265 + "local" : {
266 + "install_trust": false
267 + }
268 + }
269 + }
270 + }
271 + }
272 + `, "json")
273 +
274 + // act and assert
275 + // makes a request with no sni
276 + caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
277 +}