summaryrefslogtreecommitdiff
path: root/t/headers-auth.t
blob: 330d33c901b9e69ae387041470e90636cd9e45a3 (plain)
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
use strict;
use warnings;

use Test::More;

plan tests => 6;

use HTTP::Response;
use HTTP::Headers::Auth;

my $res = HTTP::Response->new(401);
$res->push_header(WWW_Authenticate => qq(Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2"));
$res->push_header(WWW_Authenticate => qq(Basic Realm="WallyWorld", foo=bar, bar=baz));

note $res->as_string;

my %auth = $res->www_authenticate;

is(keys(%auth), 3);

is($auth{basic}{realm}, "WallyWorld");
is($auth{bar}{realm}, "WallyWorld2");

$a = $res->www_authenticate;
is($a, 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz');

$res->www_authenticate("Basic realm=foo1");
note $res->as_string;

$res->www_authenticate(Basic => {realm => "foo2"});
print $res->as_string;

$res->www_authenticate(Basic => [realm => "foo3", foo=>33],
                       Digest => {nonce=>"bar", foo=>'foo'});
note $res->as_string;

my $string = $res->as_string;

like($string, qr/WWW-Authenticate: Basic realm="foo3", foo=33/);
like($string, qr/WWW-Authenticate: Digest (nonce=bar, foo=foo|foo=foo, nonce=bar)/);