From 0ecb1ba26279e3438abefc31dedd963920c2c3cc Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Sat, 15 Jun 2024 00:48:08 +0300 Subject: [PATCH] add `basic_auth` test Signed-off-by: Mohammed Al Sahaf --- caddytest/spec/http/basicauth/spec.hurl | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 caddytest/spec/http/basicauth/spec.hurl diff --git a/caddytest/spec/http/basicauth/spec.hurl b/caddytest/spec/http/basicauth/spec.hurl new file mode 100644 index 00000000000..0362d3dbdff --- /dev/null +++ b/caddytest/spec/http/basicauth/spec.hurl @@ -0,0 +1,38 @@ +# Configure Caddy +POST http://localhost:2019/load +Content-Type: text/caddyfile +``` +{ + skip_install_trust + http_port 9080 + https_port 9443 + local_certs + debug +} +localhost { + log + basic_auth { + john $2a$14$x4HlYwA9Zeer4RkMEYbUzug9XxWmncneR.dcMs.UjalR95URnHg5. + } + respond "Hello, World!" +} +``` + +# requests without `Authorization` header are rejected with 401 +GET https://localhost:9443 +[Options] +insecure: true +HTTP 401 +[Asserts] +header "WWW-Authenticate" == "Basic realm=\"restricted\"" + + +# requests with `Authorization` header are accepted with 200 +GET https://localhost:9443 +[BasicAuth] +john:password +[Options] +insecure: true +HTTP 200 +[Asserts] +`Hello, World!`