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; |
ed61ff6d |
8 | BEGIN { |
3aff571e |
9 | do { |
10 | eval { require Test::WWW::Mechanize::Catalyst } |
11 | and |
12 | Test::WWW::Mechanize::Catalyst->VERSION('0.51') |
13 | } |
ed61ff6d |
14 | or plan skip_all => |
15 | "Test::WWW::Mechanize::Catalyst is needed for this test"; |
ed61ff6d |
16 | } |
790f9ddb |
17 | use HTTP::Request; |
861c2f44 |
18 | |
19 | use Test::More; |
282361af |
20 | use Test::WWW::Mechanize::Catalyst; |
21 | my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); |
790f9ddb |
22 | $mech->get("http://localhost/moose"); |
513d8ab6 |
23 | is( $mech->status, 401, "status is 401" ) or die $mech->content; |
ed61ff6d |
24 | $mech->content_lacks( "foo", "no output" ); |
790f9ddb |
25 | my $r = HTTP::Request->new( GET => "http://localhost/moose" ); |
26 | $r->authorization_basic(qw/foo s3cr3t/); |
ed61ff6d |
27 | $mech->request($r); |
28 | is( $mech->status, 200, "status is 200" ); |
29 | $mech->content_contains( "foo", "foo output" ); |
513d8ab6 |
30 | |
282361af |
31 | AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(1); |
32 | $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); |
33 | $mech->get("http://localhost/moose"); |
34 | isnt( $mech->status, 401, "status isnt 401" ) or die $mech->content; |
35 | |
36 | AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(0); |
37 | AuthTestApp->get_auth_realm('test')->credential->require_ssl(1); |
38 | $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp'); |
39 | $r = HTTP::Request->new( GET => "http://localhost/moose" ); |
40 | $r->authorization_basic(qw/foo s3cr3t/); |
41 | $mech->request($r); |
42 | is( $mech->status, 401, "status is 401" ); |
43 | |
44 | done_testing; |
45 | |