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