| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use Test::More; |
| 5 |
|
| 6 |
plan tests => 9; |
| 7 |
|
| 8 |
use HTTP::Response; |
| 9 |
use HTTP::Headers::Auth; |
| 10 |
|
| 11 |
my $res = HTTP::Response->new(401); |
| 12 |
$res->push_header(WWW_Authenticate => qq(Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2")); |
| 13 |
$res->push_header(WWW_Authenticate => qq(Basic Realm="WallyWorld", foo=bar, bar=baz)); |
| 14 |
|
| 15 |
note $res->as_string; |
| 16 |
|
| 17 |
my %auth = $res->www_authenticate; |
| 18 |
|
| 19 |
is(keys(%auth), 3); |
| 20 |
|
| 21 |
is($auth{basic}{realm}, "WallyWorld"); |
| 22 |
is($auth{bar}{realm}, "WallyWorld2"); |
| 23 |
|
| 24 |
$a = $res->www_authenticate; |
| 25 |
is($a, 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz'); |
| 26 |
|
| 27 |
$res->www_authenticate("Basic realm=foo1"); |
| 28 |
note $res->as_string; |
| 29 |
|
| 30 |
$res->www_authenticate(Basic => {realm => "foo2"}); |
| 31 |
note $res->as_string; |
| 32 |
|
| 33 |
$res->www_authenticate(Basic => [realm => "foo3", foo=>33], |
| 34 |
Digest => {nonce=>"bar", foo=>'foo'}); |
| 35 |
note $res->as_string; |
| 36 |
|
| 37 |
my $string = $res->as_string; |
| 38 |
|
| 39 |
like($string, qr/WWW-Authenticate: Basic realm="foo3", foo=33/); |
| 40 |
like($string, qr/WWW-Authenticate: Digest (nonce=bar, foo=foo|foo=foo, nonce=bar)/); |
| 41 |
|
| 42 |
$res = HTTP::Response->new(401); |
| 43 |
my @auth = $res->proxy_authenticate('foo'); |
| 44 |
is_deeply(\@auth, []); |
| 45 |
@auth = $res->proxy_authenticate('foo', 'bar'); |
| 46 |
is_deeply(\@auth, ['foo', {}]); |
| 47 |
@auth = $res->proxy_authenticate('foo', {'bar' => '_'}); |
| 48 |
is_deeply(\@auth, ['foo', {}, 'bar', {}]); |