summaryrefslogtreecommitdiff
path: root/caddyconfig/httpcaddyfile/addresses_test.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-01-09 12:35:53 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2020-01-09 12:35:53 -0700
commit8aef859a5510e883a70fb562d5fb83c7585cc301 (patch)
tree58ee9021344145c7433f8e8b497aef07d38f4e3c /caddyconfig/httpcaddyfile/addresses_test.go
parenta5ebec00419f77bb408f67c360b4a09c5884109d (diff)
caddyfile: Less strict URL parsing; allows placeholders
See https://caddy.community/t/caddy-v2-reusable-snippets/6744/11?u=matt
Diffstat (limited to 'caddyconfig/httpcaddyfile/addresses_test.go')
-rw-r--r--caddyconfig/httpcaddyfile/addresses_test.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/caddyconfig/httpcaddyfile/addresses_test.go b/caddyconfig/httpcaddyfile/addresses_test.go
index d6aa6f6..70577f1 100644
--- a/caddyconfig/httpcaddyfile/addresses_test.go
+++ b/caddyconfig/httpcaddyfile/addresses_test.go
@@ -11,6 +11,7 @@ func TestParseAddress(t *testing.T) {
scheme, host, port, path string
shouldErr bool
}{
+ {``, "", "", "", "", false},
{`localhost`, "", "localhost", "", "", false},
{`localhost:1234`, "", "localhost", "1234", "", false},
{`localhost:`, "", "localhost", "", "", false},
@@ -31,6 +32,10 @@ func TestParseAddress(t *testing.T) {
{`https://localhost:80`, "", "", "", "", true}, // not conventional
{`http://localhost`, "http", "localhost", "80", "", false},
{`https://localhost`, "https", "localhost", "443", "", false},
+ {`http://{env.APP_DOMAIN}`, "http", "{env.APP_DOMAIN}", "80", "", false},
+ {`{env.APP_DOMAIN}:80`, "", "{env.APP_DOMAIN}", "80", "", false},
+ {`{env.APP_DOMAIN}/path`, "", "{env.APP_DOMAIN}", "", "/path", false},
+ {`example.com/{env.APP_PATH}`, "", "example.com", "", "/{env.APP_PATH}", false},
{`http://127.0.0.1`, "http", "127.0.0.1", "80", "", false},
{`https://127.0.0.1`, "https", "127.0.0.1", "443", "", false},
{`http://[::1]`, "http", "::1", "80", "", false},
@@ -38,12 +43,12 @@ func TestParseAddress(t *testing.T) {
{`https://127.0.0.1:1234`, "https", "127.0.0.1", "1234", "", false},
{`http://[::1]:1234`, "http", "::1", "1234", "", false},
{``, "", "", "", "", false},
- {`::1`, "", "::1", "", "", true},
- {`localhost::`, "", "localhost::", "", "", true},
- {`#$%@`, "", "", "", "", true},
+ {`::1`, "", "::1", "", "", false},
+ {`localhost::`, "", "localhost::", "", "", false},
+ {`#$%@`, "", "#$%@", "", "", false}, // don't want to presume what the hostname could be
{`host/path`, "", "host", "", "/path", false},
{`http://host/`, "http", "host", "80", "/", false},
- {`//asdf`, "", "asdf", "", "", false},
+ {`//asdf`, "", "", "", "//asdf", false},
{`:1234/asdf`, "", "", "1234", "/asdf", false},
{`http://host/path`, "http", "host", "80", "/path", false},
{`https://host:443/path/foo`, "https", "host", "443", "/path/foo", false},
@@ -56,7 +61,7 @@ func TestParseAddress(t *testing.T) {
t.Errorf("Test %d (%s): Expected no error, but had error: %v", i, test.input, err)
}
if err == nil && test.shouldErr {
- t.Errorf("Test %d (%s): Expected error, but had none", i, test.input)
+ t.Errorf("Test %d (%s): Expected error, but had none (%#v)", i, test.input, actual)
}
if !test.shouldErr && actual.Original != test.input {