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