(no commit message)
[catagits/Catalyst-Authentication-Credential-HTTP.git] / t / live_app.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9     eval { require Test::WWW::Mechanize::Catalyst }
10       or plan skip_all =>
11       "Test::WWW::Mechanize::Catalyst is needed for this test";
12     plan tests => 4;
13 }
14
15 use HTTP::Request;
16
17 {
18
19     package AuthTestApp;
20     use Catalyst qw/
21       Authentication
22       Authentication::Store::Minimal
23       Authentication::Credential::HTTP
24       /;
25
26     use Test::More;
27
28     our $users;
29
30     sub moose : Local {
31         my ( $self, $c ) = @_;
32
33         $c->authorization_required;
34
35         $c->res->body( $c->user->id );
36     }
37     __PACKAGE__->config->{authentication}{http}{type} = 'basic';
38     __PACKAGE__->config->{authentication}{users} = $users = {
39         foo => { password         => "s3cr3t", },
40     };
41
42     __PACKAGE__->setup;
43 }
44
45 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
46
47 my $mech = Test::WWW::Mechanize::Catalyst->new;
48
49 $mech->get("http://localhost/moose");
50 is( $mech->status, 401, "status is 401" );
51
52 $mech->content_lacks( "foo", "no output" );
53
54 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
55 $r->authorization_basic(qw/foo s3cr3t/);
56
57 $mech->request($r);
58 is( $mech->status, 200, "status is 200" );
59 $mech->content_contains( "foo", "foo output" );
60