Commit changes that were in 1.002
[catagits/Catalyst-Authentication-Credential-HTTP.git] / t / live_app.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Test::More;
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 }
11 use HTTP::Request;
12 {
13     package AuthTestApp;
14     use Catalyst qw/
15       Authentication
16       /;
17     use Test::More;
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                     password_type => 'clear', 
31                     password_field => 'password'
32                 },
33             },
34         },
35     });
36     sub auto : Private {
37         my ($self, $c) = @_;
38         $c->authenticate();
39     }
40     sub moose : Local {
41         my ( $self, $c ) = @_;
42             $c->res->body( $c->user->id );
43     }
44     %users = (
45         foo => { password         => "s3cr3t", },
46     );
47     __PACKAGE__->setup;
48 }
49 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
50 my $mech = Test::WWW::Mechanize::Catalyst->new;
51 $mech->get("http://localhost/moose");
52 is( $mech->status, 401, "status is 401" ) or die $mech->content;
53 $mech->content_lacks( "foo", "no output" );
54 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
55 $r->authorization_basic(qw/foo s3cr3t/);
56 $mech->request($r);
57 is( $mech->status, 200, "status is 200" );
58 $mech->content_contains( "foo", "foo output" );
59