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', |
30 | }, |
31 | }, |
32 | }, |
33 | }); |
34 | sub auto : Private { |
35 | my ($self, $c) = @_; |
36 | $c->authenticate(); |
37 | } |
ed61ff6d |
38 | sub moose : Local { |
39 | my ( $self, $c ) = @_; |
513d8ab6 |
40 | $c->res->body( $c->user->id ); |
ed61ff6d |
41 | } |
513d8ab6 |
42 | %users = ( |
ed61ff6d |
43 | foo => { password => "s3cr3t", }, |
513d8ab6 |
44 | ); |
ed61ff6d |
45 | __PACKAGE__->setup; |
790f9ddb |
46 | } |
790f9ddb |
47 | use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; |
790f9ddb |
48 | my $mech = Test::WWW::Mechanize::Catalyst->new; |
790f9ddb |
49 | $mech->get("http://localhost/moose"); |
513d8ab6 |
50 | is( $mech->status, 401, "status is 401" ) or die $mech->content; |
ed61ff6d |
51 | $mech->content_lacks( "foo", "no output" ); |
790f9ddb |
52 | my $r = HTTP::Request->new( GET => "http://localhost/moose" ); |
53 | $r->authorization_basic(qw/foo s3cr3t/); |
ed61ff6d |
54 | $mech->request($r); |
55 | is( $mech->status, 200, "status is 200" ); |
56 | $mech->content_contains( "foo", "foo output" ); |
513d8ab6 |
57 | |