Commit | Line | Data |
790f9ddb |
1 | #!/usr/bin/perl |
790f9ddb |
2 | use strict; |
3 | use warnings; |
ed61ff6d |
4 | use Test::More; |
ed61ff6d |
5 | BEGIN { |
6 | eval { require Test::WWW::Mechanize::Catalyst } |
7 | or plan skip_all => |
8 | "Test::WWW::Mechanize::Catalyst is needed for this test"; |
9 | plan tests => 4; |
10 | } |
790f9ddb |
11 | use HTTP::Request; |
790f9ddb |
12 | { |
ed61ff6d |
13 | package AuthTestApp; |
14 | use Catalyst qw/ |
15 | Authentication |
ed61ff6d |
16 | /; |
ed61ff6d |
17 | use Test::More; |
513d8ab6 |
18 | our %users; |
19 | __PACKAGE__->config(authentication => { |
20 | default_realm => 'test', |
21 | realms => { |
22 | test => { |
23 | store => { |
24 | class => 'Minimal', |
25 | users => \%users, |
26 | }, |
27 | credential => { |
28 | class => 'HTTP', |
29 | type => 'basic', |
490754a8 |
30 | password_type => 'clear', |
31 | password_field => 'password' |
513d8ab6 |
32 | }, |
33 | }, |
34 | }, |
35 | }); |
36 | sub auto : Private { |
37 | my ($self, $c) = @_; |
38 | $c->authenticate(); |
39 | } |
ed61ff6d |
40 | sub moose : Local { |
41 | my ( $self, $c ) = @_; |
513d8ab6 |
42 | $c->res->body( $c->user->id ); |
ed61ff6d |
43 | } |
513d8ab6 |
44 | %users = ( |
ed61ff6d |
45 | foo => { password => "s3cr3t", }, |
513d8ab6 |
46 | ); |
ed61ff6d |
47 | __PACKAGE__->setup; |
790f9ddb |
48 | } |
790f9ddb |
49 | use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; |
790f9ddb |
50 | my $mech = Test::WWW::Mechanize::Catalyst->new; |
790f9ddb |
51 | $mech->get("http://localhost/moose"); |
513d8ab6 |
52 | is( $mech->status, 401, "status is 401" ) or die $mech->content; |
ed61ff6d |
53 | $mech->content_lacks( "foo", "no output" ); |
790f9ddb |
54 | my $r = HTTP::Request->new( GET => "http://localhost/moose" ); |
55 | $r->authorization_basic(qw/foo s3cr3t/); |
ed61ff6d |
56 | $mech->request($r); |
57 | is( $mech->status, 200, "status is 200" ); |
58 | $mech->content_contains( "foo", "foo output" ); |
513d8ab6 |
59 | |