Commit | Line | Data |
790f9ddb |
1 | use strict; |
2 | use warnings; |
bd1101db |
3 | |
4 | use FindBin qw/$Bin/; |
5 | use lib "$Bin/lib"; |
6 | |
ed61ff6d |
7 | use Test::More; |
419d9af2 |
8 | use Test::Needs { 'Test::WWW::Mechanize::Catalyst' => '0.51' }; |
790f9ddb |
9 | use HTTP::Request; |
861c2f44 |
10 | |
282361af |
11 | my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); |
790f9ddb |
12 | $mech->get("http://localhost/moose"); |
513d8ab6 |
13 | is( $mech->status, 401, "status is 401" ) or die $mech->content; |
ed61ff6d |
14 | $mech->content_lacks( "foo", "no output" ); |
790f9ddb |
15 | my $r = HTTP::Request->new( GET => "http://localhost/moose" ); |
16 | $r->authorization_basic(qw/foo s3cr3t/); |
ed61ff6d |
17 | $mech->request($r); |
18 | is( $mech->status, 200, "status is 200" ); |
19 | $mech->content_contains( "foo", "foo output" ); |
513d8ab6 |
20 | |
282361af |
21 | AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(1); |
22 | $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); |
23 | $mech->get("http://localhost/moose"); |
24 | isnt( $mech->status, 401, "status isnt 401" ) or die $mech->content; |
25 | |
26 | AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(0); |
27 | AuthTestApp->get_auth_realm('test')->credential->require_ssl(1); |
28 | $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); |
29 | $r = HTTP::Request->new( GET => "http://localhost/moose" ); |
30 | $r->authorization_basic(qw/foo s3cr3t/); |
31 | $mech->request($r); |
32 | is( $mech->status, 401, "status is 401" ); |
33 | |
34 | done_testing; |
35 | |