summaryrefslogtreecommitdiffstats
path: root/debian/vendor-h2o/t/50mruby-htpasswd.t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:12:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:12:02 +0000
commit77e50caaf2ef81cd91075cf836fed0e75718ffb4 (patch)
tree53b7b411290b63192fc9e924a3b6b65cdf67e9d0 /debian/vendor-h2o/t/50mruby-htpasswd.t
parentAdding upstream version 1.8.3. (diff)
downloaddnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.tar.xz
dnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.zip
Adding debian version 1.8.3-2.debian/1.8.3-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--debian/vendor-h2o/t/50mruby-htpasswd.t48
1 files changed, 48 insertions, 0 deletions
diff --git a/debian/vendor-h2o/t/50mruby-htpasswd.t b/debian/vendor-h2o/t/50mruby-htpasswd.t
new file mode 100644
index 0000000..31cbf59
--- /dev/null
+++ b/debian/vendor-h2o/t/50mruby-htpasswd.t
@@ -0,0 +1,48 @@
+use strict;
+use warnings;
+use Digest::MD5 qw(md5_hex);
+use Test::More;
+use t::Util;
+
+plan skip_all => 'mruby support is off'
+ unless server_features()->{mruby};
+
+plan skip_all => 'curl not found'
+ unless prog_exists('curl');
+
+subtest "basic" => sub {
+ my $server = spawn_h2o(<< 'EOT');
+hosts:
+ default:
+ paths:
+ /:
+ mruby.handler: |
+ require "share/h2o/mruby/htpasswd.rb"
+ Htpasswd.new("t/assets/.htpasswd", "protected space")
+ mruby.handler:
+ Proc.new do |env|
+ [200, {}, ["hello ", env["REMOTE_USER"], "\n"]]
+ end
+EOT
+ subtest "no-auth" => sub {
+ my ($headers, $body) = run_prog("curl --silent --dump-header /dev/stderr http://127.0.0.1:$server->{port}/");
+ like $headers, qr{^HTTP/1\.1 401 }s, "status";
+ like $headers, qr{\r\nwww-authenticate: basic realm="protected space"\r}is, "www-authenticate header";
+ unlike $body, qr/hello/;
+ };
+
+ subtest "fail" => sub {
+ my ($headers, $body) = run_prog("curl --silent --dump-header /dev/stderr http://aaa:aaa\@127.0.0.1:$server->{port}/");
+ like $headers, qr{^HTTP/1\.1 401 }s, "status";
+ like $headers, qr{\r\nwww-authenticate: basic realm="protected space"\r}is, "www-authenticate header";
+ unlike $body, qr/hello/;
+ };
+
+ subtest "success" => sub {
+ my ($headers, $body) = run_prog("curl --silent --dump-header /dev/stderr http://dankogai:kogaidan\@127.0.0.1:$server->{port}/");
+ like $headers, qr{^HTTP/1\.1 200 }s, "status";
+ is $body, "hello dankogai\n", "content";
+ };
+};
+
+done_testing();