From 8aef859a5510e883a70fb562d5fb83c7585cc301 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 9 Jan 2020 12:35:53 -0700 Subject: caddyfile: Less strict URL parsing; allows placeholders See https://caddy.community/t/caddy-v2-reusable-snippets/6744/11?u=matt --- caddyconfig/httpcaddyfile/addresses_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'caddyconfig/httpcaddyfile/addresses_test.go') 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 { -- cgit v1.2.3