switch to Module::Install. add pod/podcoverage tests. fix coverage. add README. fix...
[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       Authentication::Store::Minimal
17       Authentication::Credential::HTTP
18       /;
19     use Test::More;
20     our $users;
21     sub moose : Local {
22         my ( $self, $c ) = @_;
23         $c->authorization_required;
24         $c->res->body( $c->user->id );
25     }
26     __PACKAGE__->config->{authentication}{http}{type} = 'basic';
27     __PACKAGE__->config->{authentication}{users} = $users = {
28         foo => { password         => "s3cr3t", },
29     };
30     __PACKAGE__->setup;
31 }
32 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
33 my $mech = Test::WWW::Mechanize::Catalyst->new;
34 $mech->get("http://localhost/moose");
35 is( $mech->status, 401, "status is 401" );
36 $mech->content_lacks( "foo", "no output" );
37 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
38 $r->authorization_basic(qw/foo s3cr3t/);
39 $mech->request($r);
40 is( $mech->status, 200, "status is 200" );
41 $mech->content_contains( "foo", "foo output" );