summaryrefslogtreecommitdiff
path: root/caddytest/integration/caddyfile_test.go
diff options
context:
space:
mode:
authorMark Sargent <99003+sarge@users.noreply.github.com>2020-03-18 07:39:01 +1300
committerGitHub <noreply@github.com>2020-03-17 12:39:01 -0600
commit3f48a2eb455167af8d77c5c4543bd17a80a93260 (patch)
tree3a104fabecf515b2d295f7e7240f506501ef3102 /caddytest/integration/caddyfile_test.go
parentf192ae5ea5c1e20e0c6aefc0772f0a92ee142f1e (diff)
caddyhttp: Add default SNI tests (#3146)
* added sni tests * set the default sni when there is no host to match * removed invalid sni test. Disabled tests that rely on host headers. * readded SNI tests. Added logging of config load times
Diffstat (limited to 'caddytest/integration/caddyfile_test.go')
-rw-r--r--caddytest/integration/caddyfile_test.go59
1 files changed, 52 insertions, 7 deletions
diff --git a/caddytest/integration/caddyfile_test.go b/caddytest/integration/caddyfile_test.go
index 33b4b2d..3e89a26 100644
--- a/caddytest/integration/caddyfile_test.go
+++ b/caddytest/integration/caddyfile_test.go
@@ -17,13 +17,13 @@ func TestRespond(t *testing.T) {
localhost:9080 {
respond /version 200 {
- body "hello from a.caddy.localhost"
+ body "hello from localhost"
}
}
`, "caddyfile")
// act and assert
- caddytest.AssertGetResponse(t, "http://localhost:9080/version", 200, "hello from a.caddy.localhost")
+ caddytest.AssertGetResponse(t, "http://localhost:9080/version", 200, "hello from localhost")
}
func TestRedirect(t *testing.T) {
@@ -40,7 +40,7 @@ func TestRedirect(t *testing.T) {
redir / http://localhost:9080/hello 301
respond /hello 200 {
- body "hello from b"
+ body "hello from localhost"
}
}
`, "caddyfile")
@@ -49,7 +49,7 @@ func TestRedirect(t *testing.T) {
caddytest.AssertRedirect(t, "http://localhost:9080/", "http://localhost:9080/hello", 301)
// follow redirect
- caddytest.AssertGetResponse(t, "http://localhost:9080/", 200, "hello from b")
+ caddytest.AssertGetResponse(t, "http://localhost:9080/", 200, "hello from localhost")
}
func TestDuplicateHosts(t *testing.T) {
@@ -78,8 +78,52 @@ func TestDefaultSNI(t *testing.T) {
}
127.0.0.1:9443 {
- tls /caddy.localhost.crt /caddy.localhost.key {
- }
+ tls /caddy.localhost.crt /caddy.localhost.key
+ respond /version 200 {
+ body "hello from a"
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
+}
+
+func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
+
+ // arrange
+ caddytest.InitServer(t, `
+ {
+ http_port 9080
+ https_port 9443
+ default_sni a.caddy.localhost
+ }
+
+ a.caddy.localhost:9443, 127.0.0.1:9443 {
+ tls /a.caddy.localhost.crt /a.caddy.localhost.key
+ respond /version 200 {
+ body "hello from a"
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ // makes a request with no sni
+ caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
+}
+
+func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
+
+ // arrange
+ caddytest.InitServer(t, `
+ {
+ http_port 9080
+ https_port 9443
+ default_sni a.caddy.localhost
+ }
+
+ :9443 {
+ tls /a.caddy.localhost.crt /a.caddy.localhost.key
respond /version 200 {
body "hello from a.caddy.localhost"
}
@@ -87,5 +131,6 @@ func TestDefaultSNI(t *testing.T) {
`, "caddyfile")
// act and assert
- caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
+ // makes a request with no sni
+ caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
}