summaryrefslogtreecommitdiff
path: root/caddytest/integration
diff options
context:
space:
mode:
authorMark Sargent <99003+sarge@users.noreply.github.com>2020-04-04 16:02:46 +1300
committerGitHub <noreply@github.com>2020-04-03 21:02:46 -0600
commit78717ce5b0a940df0ef91a19e8389b11505a344d (patch)
tree77a21a25534a93dac8011d68f723f750f745427c /caddytest/integration
parent3d6fc1e1b7f41ebbd0c7cb48280ce1a14a56f4d5 (diff)
chore: add adapt tests. fix load failure not failing tests (#3222)
* add adaption tests. fix load failure not failing tests * removed unnecessary assignment
Diffstat (limited to 'caddytest/integration')
-rw-r--r--caddytest/integration/caddyfile_adapt_test.go285
1 files changed, 285 insertions, 0 deletions
diff --git a/caddytest/integration/caddyfile_adapt_test.go b/caddytest/integration/caddyfile_adapt_test.go
new file mode 100644
index 0000000..bff325b
--- /dev/null
+++ b/caddytest/integration/caddyfile_adapt_test.go
@@ -0,0 +1,285 @@
+package integration
+
+import (
+ "testing"
+
+ "github.com/caddyserver/caddy/v2/caddytest"
+)
+
+func TestHttpOnlyOnLocalhost(t *testing.T) {
+ caddytest.AssertAdapt(t, `
+ localhost:80 {
+ respond /version 200 {
+ body "hello from localhost"
+ }
+ }
+ `, "caddyfile", `{
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":80"
+ ],
+ "routes": [
+ {
+ "match": [
+ {
+ "host": [
+ "localhost"
+ ]
+ }
+ ],
+ "handle": [
+ {
+ "handler": "subroute",
+ "routes": [
+ {
+ "handle": [
+ {
+ "body": "hello from localhost",
+ "handler": "static_response",
+ "status_code": 200
+ }
+ ],
+ "match": [
+ {
+ "path": [
+ "/version"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "terminal": true
+ }
+ ]
+ }
+ }
+ }
+ }
+}`)
+}
+
+func TestHttpOnlyOnAnyAddress(t *testing.T) {
+ caddytest.AssertAdapt(t, `
+ :80 {
+ respond /version 200 {
+ body "hello from localhost"
+ }
+ }
+ `, "caddyfile", `{
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":80"
+ ],
+ "routes": [
+ {
+ "match": [
+ {
+ "path": [
+ "/version"
+ ]
+ }
+ ],
+ "handle": [
+ {
+ "body": "hello from localhost",
+ "handler": "static_response",
+ "status_code": 200
+ }
+ ]
+ }
+ ]
+ }
+ }
+ }
+ }
+}`)
+}
+
+func TestHttpsOnDomain(t *testing.T) {
+ caddytest.AssertAdapt(t, `
+ a.caddy.localhost {
+ respond /version 200 {
+ body "hello from localhost"
+ }
+ }
+ `, "caddyfile", `{
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":443"
+ ],
+ "routes": [
+ {
+ "match": [
+ {
+ "host": [
+ "a.caddy.localhost"
+ ]
+ }
+ ],
+ "handle": [
+ {
+ "handler": "subroute",
+ "routes": [
+ {
+ "handle": [
+ {
+ "body": "hello from localhost",
+ "handler": "static_response",
+ "status_code": 200
+ }
+ ],
+ "match": [
+ {
+ "path": [
+ "/version"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "terminal": true
+ }
+ ]
+ }
+ }
+ }
+ }
+}`)
+}
+
+func TestHttpOnlyOnDomain(t *testing.T) {
+ caddytest.AssertAdapt(t, `
+ http://a.caddy.localhost {
+ respond /version 200 {
+ body "hello from localhost"
+ }
+ }
+ `, "caddyfile", `{
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":80"
+ ],
+ "routes": [
+ {
+ "match": [
+ {
+ "host": [
+ "a.caddy.localhost"
+ ]
+ }
+ ],
+ "handle": [
+ {
+ "handler": "subroute",
+ "routes": [
+ {
+ "handle": [
+ {
+ "body": "hello from localhost",
+ "handler": "static_response",
+ "status_code": 200
+ }
+ ],
+ "match": [
+ {
+ "path": [
+ "/version"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "terminal": true
+ }
+ ],
+ "automatic_https": {
+ "skip": [
+ "a.caddy.localhost"
+ ]
+ }
+ }
+ }
+ }
+ }
+}`)
+}
+
+func TestHttpOnlyOnNonStandardPort(t *testing.T) {
+ caddytest.AssertAdapt(t, `
+ http://a.caddy.localhost:81 {
+ respond /version 200 {
+ body "hello from localhost"
+ }
+ }
+ `, "caddyfile", `{
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":81"
+ ],
+ "routes": [
+ {
+ "match": [
+ {
+ "host": [
+ "a.caddy.localhost"
+ ]
+ }
+ ],
+ "handle": [
+ {
+ "handler": "subroute",
+ "routes": [
+ {
+ "handle": [
+ {
+ "body": "hello from localhost",
+ "handler": "static_response",
+ "status_code": 200
+ }
+ ],
+ "match": [
+ {
+ "path": [
+ "/version"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "terminal": true
+ }
+ ],
+ "automatic_https": {
+ "skip": [
+ "a.caddy.localhost"
+ ]
+ }
+ }
+ }
+ }
+ }
+}`)
+}