summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/replacer_test.go
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2022-09-05 13:53:41 -0600
committerGitHub <noreply@github.com>2022-09-05 13:53:41 -0600
commitd5ea43fb4b549dda6040b31ce472e7843dfc5077 (patch)
tree9c73b4dfde8fb0f2ee487d1ce0441bb59ab914be /modules/caddyhttp/replacer_test.go
parentca4fae64d99a63291a91e59af5a1e8eef8c8e2d8 (diff)
fileserver: Support glob expansion in file matcher (#4993)
* fileserver: Support glob expansion in file matcher * Fix tests * Fix bugs and tests * Attempt Windows fix, sigh * debug Windows, WIP * Continue debugging Windows * Another attempt at Windows * Plz Windows * Cmon... * Clean up, hope I didn't break anything
Diffstat (limited to 'modules/caddyhttp/replacer_test.go')
-rw-r--r--modules/caddyhttp/replacer_test.go84
1 files changed, 52 insertions, 32 deletions
diff --git a/modules/caddyhttp/replacer_test.go b/modules/caddyhttp/replacer_test.go
index 5026ac8..18253d3 100644
--- a/modules/caddyhttp/replacer_test.go
+++ b/modules/caddyhttp/replacer_test.go
@@ -27,7 +27,7 @@ import (
)
func TestHTTPVarReplacement(t *testing.T) {
- req, _ := http.NewRequest("GET", "/", nil)
+ req, _ := http.NewRequest(http.MethodGet, "/foo/bar.tar.gz", nil)
repl := caddy.NewReplacer()
ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
req = req.WithContext(ctx)
@@ -72,114 +72,134 @@ eqp31wM9il1n+guTNyxJd+FzVAH+hCZE5K+tCgVDdVFUlDEHHbS/wqb2PSIoouLV
addHTTPVarsToReplacer(repl, req, res)
for i, tc := range []struct {
- input string
+ get string
expect string
}{
{
- input: "{http.request.scheme}",
+ get: "http.request.scheme",
expect: "https",
},
{
- input: "{http.request.host}",
+ get: "http.request.method",
+ expect: http.MethodGet,
+ },
+ {
+ get: "http.request.host",
expect: "example.com",
},
{
- input: "{http.request.port}",
+ get: "http.request.port",
expect: "80",
},
{
- input: "{http.request.hostport}",
+ get: "http.request.hostport",
expect: "example.com:80",
},
{
- input: "{http.request.remote.host}",
+ get: "http.request.remote.host",
expect: "localhost",
},
{
- input: "{http.request.remote.port}",
+ get: "http.request.remote.port",
expect: "1234",
},
{
- input: "{http.request.host.labels.0}",
+ get: "http.request.host.labels.0",
expect: "com",
},
{
- input: "{http.request.host.labels.1}",
+ get: "http.request.host.labels.1",
expect: "example",
},
{
- input: "{http.request.host.labels.2}",
- expect: "<empty>",
+ get: "http.request.host.labels.2",
+ expect: "",
},
{
- input: "{http.request.tls.cipher_suite}",
+ get: "http.request.uri.path.file",
+ expect: "bar.tar.gz",
+ },
+ {
+ get: "http.request.uri.path.file.base",
+ expect: "bar.tar",
+ },
+ {
+ // not ideal, but also most correct, given that files can have dots (example: index.<SHA>.html) TODO: maybe this isn't right..
+ get: "http.request.uri.path.file.ext",
+ expect: ".gz",
+ },
+ {
+ get: "http.request.tls.cipher_suite",
expect: "TLS_AES_256_GCM_SHA384",
},
{
- input: "{http.request.tls.proto}",
+ get: "http.request.tls.proto",
expect: "h2",
},
{
- input: "{http.request.tls.proto_mutual}",
+ get: "http.request.tls.proto_mutual",
expect: "true",
},
{
- input: "{http.request.tls.resumed}",
+ get: "http.request.tls.resumed",
expect: "false",
},
{
- input: "{http.request.tls.server_name}",
+ get: "http.request.tls.server_name",
expect: "foo.com",
},
{
- input: "{http.request.tls.version}",
+ get: "http.request.tls.version",
expect: "tls1.3",
},
{
- input: "{http.request.tls.client.fingerprint}",
+ get: "http.request.tls.client.fingerprint",
expect: "9f57b7b497cceacc5459b76ac1c3afedbc12b300e728071f55f84168ff0f7702",
},
{
- input: "{http.request.tls.client.issuer}",
+ get: "http.request.tls.client.issuer",
expect: "CN=Caddy Test CA",
},
{
- input: "{http.request.tls.client.serial}",
+ get: "http.request.tls.client.serial",
expect: "2",
},
{
- input: "{http.request.tls.client.subject}",
+ get: "http.request.tls.client.subject",
expect: "CN=client.localdomain",
},
{
- input: "{http.request.tls.client.san.dns_names}",
+ get: "http.request.tls.client.san.dns_names",
expect: "[localhost]",
},
{
- input: "{http.request.tls.client.san.dns_names.0}",
+ get: "http.request.tls.client.san.dns_names.0",
expect: "localhost",
},
{
- input: "{http.request.tls.client.san.dns_names.1}",
- expect: "<empty>",
+ get: "http.request.tls.client.san.dns_names.1",
+ expect: "",
},
{
- input: "{http.request.tls.client.san.ips}",
+ get: "http.request.tls.client.san.ips",
expect: "[127.0.0.1]",
},
{
- input: "{http.request.tls.client.san.ips.0}",
+ get: "http.request.tls.client.san.ips.0",
expect: "127.0.0.1",
},
{
- input: "{http.request.tls.client.certificate_pem}",
+ get: "http.request.tls.client.certificate_pem",
expect: string(clientCert) + "\n", // returned value comes with a newline appended to it
},
} {
- actual := repl.ReplaceAll(tc.input, "<empty>")
+ actual, got := repl.GetString(tc.get)
+ if !got {
+ t.Errorf("Test %d: Expected to recognize the placeholder name, but didn't", i)
+ }
if actual != tc.expect {
- t.Errorf("Test %d: Expected placeholder %s to be '%s' but got '%s'",
- i, tc.input, tc.expect, actual)
+ t.Errorf("Test %d: Expected %s to be '%s' but got '%s'",
+ i, tc.get, tc.expect, actual)
}
}
}