summaryrefslogtreecommitdiff
path: root/caddytest/integration
diff options
context:
space:
mode:
authorMark Sargent <99003+sarge@users.noreply.github.com>2020-03-14 06:32:53 +1300
committerGitHub <noreply@github.com>2020-03-13 11:32:53 -0600
commitc4472363579e26485fdfc01f4fd79b86d44acd86 (patch)
tree9a59e09cd79f9d1c5efbca8723bfffc2d21afbf2 /caddytest/integration
parent5a19db5dc2db7c02d0f99630a07a64cacb7f7b44 (diff)
caddyhttp: Fix default SNI for default conn policy (#3141)
* add integration tests * removed SNI test * remove integration test condition * minor edit * fix sni when using static certificates Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'caddytest/integration')
-rw-r--r--caddytest/integration/caddyfile_test.go91
1 files changed, 91 insertions, 0 deletions
diff --git a/caddytest/integration/caddyfile_test.go b/caddytest/integration/caddyfile_test.go
new file mode 100644
index 0000000..33b4b2d
--- /dev/null
+++ b/caddytest/integration/caddyfile_test.go
@@ -0,0 +1,91 @@
+package integration
+
+import (
+ "testing"
+
+ "github.com/caddyserver/caddy/v2/caddytest"
+)
+
+func TestRespond(t *testing.T) {
+
+ // arrange
+ caddytest.InitServer(t, `
+ {
+ http_port 9080
+ https_port 9443
+ }
+
+ localhost:9080 {
+ respond /version 200 {
+ body "hello from a.caddy.localhost"
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ caddytest.AssertGetResponse(t, "http://localhost:9080/version", 200, "hello from a.caddy.localhost")
+}
+
+func TestRedirect(t *testing.T) {
+
+ // arrange
+ caddytest.InitServer(t, `
+ {
+ http_port 9080
+ https_port 9443
+ }
+
+ localhost:9080 {
+
+ redir / http://localhost:9080/hello 301
+
+ respond /hello 200 {
+ body "hello from b"
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ caddytest.AssertRedirect(t, "http://localhost:9080/", "http://localhost:9080/hello", 301)
+
+ // follow redirect
+ caddytest.AssertGetResponse(t, "http://localhost:9080/", 200, "hello from b")
+}
+
+func TestDuplicateHosts(t *testing.T) {
+
+ // act and assert
+ caddytest.AssertLoadError(t,
+ `
+ localhost:9080 {
+ }
+
+ localhost:9080 {
+ }
+ `,
+ "caddyfile",
+ "duplicate site address not allowed")
+}
+
+func TestDefaultSNI(t *testing.T) {
+
+ // arrange
+ caddytest.InitServer(t, `
+ {
+ http_port 9080
+ https_port 9443
+ default_sni *.caddy.localhost
+ }
+
+ 127.0.0.1:9443 {
+ tls /caddy.localhost.crt /caddy.localhost.key {
+ }
+ respond /version 200 {
+ body "hello from a.caddy.localhost"
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
+}