From 6d4992e11749eb988e713d389ba4a2d32a2fb8d3 Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Sat, 15 Jun 2024 00:48:18 +0300 Subject: [PATCH] add `file_server` test Signed-off-by: Mohammed Al Sahaf --- .github/workflows/ci.yml | 2 +- .../file_server/assets/indexed/index.html | 9 ++ .../http/file_server/assets/indexed/index.txt | 1 + .../file_server/assets/unindexed/.gitkeep | 0 caddytest/spec/http/file_server/spec.hurl | 119 ++++++++++++++++++ caddytest/spec/hurl_vars.properties | 2 + 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 caddytest/spec/http/file_server/assets/indexed/index.html create mode 100644 caddytest/spec/http/file_server/assets/indexed/index.txt create mode 100644 caddytest/spec/http/file_server/assets/unindexed/.gitkeep create mode 100644 caddytest/spec/http/file_server/spec.hurl create mode 100644 caddytest/spec/hurl_vars.properties diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31c9f1b9c04a..ed8793d3b6b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,7 +145,7 @@ jobs: if: matrix.os == 'linux' && matrix.go == '1.22' run: | mkdir hurl-report - find . -name *.hurl -exec hurl --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \; + find . -name *.hurl -exec hurl --variables-file caddytest/spec/hurl_vars.properties --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \; - name: Publish Test Results if: matrix.os == 'linux' && matrix.go == '1.22' diff --git a/caddytest/spec/http/file_server/assets/indexed/index.html b/caddytest/spec/http/file_server/assets/indexed/index.html new file mode 100644 index 000000000000..da5de44a0902 --- /dev/null +++ b/caddytest/spec/http/file_server/assets/indexed/index.html @@ -0,0 +1,9 @@ + + + + Index.html Title + + + Index.html + + \ No newline at end of file diff --git a/caddytest/spec/http/file_server/assets/indexed/index.txt b/caddytest/spec/http/file_server/assets/indexed/index.txt new file mode 100644 index 000000000000..21fc0c67e886 --- /dev/null +++ b/caddytest/spec/http/file_server/assets/indexed/index.txt @@ -0,0 +1 @@ +index.txt \ No newline at end of file diff --git a/caddytest/spec/http/file_server/assets/unindexed/.gitkeep b/caddytest/spec/http/file_server/assets/unindexed/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/caddytest/spec/http/file_server/spec.hurl b/caddytest/spec/http/file_server/spec.hurl new file mode 100644 index 000000000000..be9504e15137 --- /dev/null +++ b/caddytest/spec/http/file_server/spec.hurl @@ -0,0 +1,119 @@ +# Configure Caddy with default configuration +POST http://localhost:2019/load +Content-Type: text/caddyfile +``` +{ + skip_install_trust + http_port 9080 + https_port 9443 + local_certs + debug +} +localhost { + root {{indexed_root}} + file_server +} +``` + +# requests without specific file receive index file per +# the default index list: index.html, index.txt +GET https://localhost:9443 +[Options] +insecure: true +HTTP 200 +[Asserts] +``` + + + + Index.html Title + + + Index.html + +``` + + +# if index.txt is specifically requested, we expect index.txt +GET https://localhost:9443/index.txt +[Options] +insecure: true +HTTP 200 +[Asserts] +body == "index.txt" + +# requests for sub-folder followed by .. result in sanitized path +GET https://localhost:9443/non-existent/../index.txt +[Options] +insecure: true +HTTP 200 +[Asserts] +body == "index.txt" + +# results out of root folder are sanitized, +# and conform to default index list sequence. +GET https://localhost:9443/../ +[Options] +insecure: true +HTTP 200 +[Asserts] +``` + + + + Index.html Title + + + Index.html + +``` + + +# Configure Caddy with custsom index "index.txt" +POST http://localhost:2019/load +Content-Type: text/caddyfile +``` +{ + skip_install_trust + http_port 9080 + https_port 9443 + local_certs + debug +} +localhost { + root {{indexed_root}} + file_server { + index index.txt + } +} +``` + +GET https://localhost:9443 +[Options] +insecure: true +HTTP 200 +[Asserts] +body == "index.txt" + + +# Configure with a root not containing index files +POST http://localhost:2019/load +Content-Type: text/caddyfile +``` +{ + skip_install_trust + http_port 9080 + https_port 9443 + local_certs + debug +} +localhost { + root {{unindexed_root}} + file_server +} +``` + +GET https://localhost:9443 +[Options] +insecure: true +HTTP 404 \ No newline at end of file diff --git a/caddytest/spec/hurl_vars.properties b/caddytest/spec/hurl_vars.properties new file mode 100644 index 000000000000..c9a8889cdfe5 --- /dev/null +++ b/caddytest/spec/hurl_vars.properties @@ -0,0 +1,2 @@ +indexed_root=./caddytest/spec/http/file_server/assets/indexed +unindexed_root=./caddytest/spec/http/file_server/assets/unindexed \ No newline at end of file