forked from Nexenta/h2o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path50mruby-htpasswd.t
48 lines (42 loc) · 1.58 KB
/
50mruby-htpasswd.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();