d95e197113cb91f4b0324eb891435c25ed7e18f4
[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 tests => 4;
7 use HTTP::Request;
8
9 {
10         package AuthTestApp;
11         use Catalyst qw/
12                 Authentication
13                 Authentication::Store::Minimal
14                 Authentication::Credential::HTTP
15         /;
16
17         use Test::More;
18         use Test::Exception;
19
20         use Digest::MD5 qw/md5/;
21
22         our $users;
23
24         sub moose : Local {
25                 my ( $self, $c ) = @_;
26
27         $c->authorization_required;
28
29         $c->res->body("foo");
30         }
31
32         __PACKAGE__->config->{authentication}{users} = $users = {
33                 foo => {
34                         password => "s3cr3t",
35                 },
36                 bar => {
37                         crypted_password => crypt("s3cr3t", "x8"),
38                 },
39                 gorch => {
40                         hashed_password => md5("s3cr3t"),
41                         hash_algorithm => "MD5",
42                 },
43                 baz => {},
44         };
45
46         __PACKAGE__->setup;
47 }
48
49 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
50
51 my $mech = Test::WWW::Mechanize::Catalyst->new;
52
53 $mech->get("http://localhost/moose");
54 is( $mech->status, 401, "status is 401");
55
56 $mech->content_lacks("foo", "no output");
57
58 my $r = HTTP::Request->new( GET => "http://localhost/moose" );
59 $r->authorization_basic(qw/foo s3cr3t/);
60
61 $mech->request( $r );
62 is( $mech->status, 200, "status is 200");
63 $mech->content_contains("foo", "foo output");
64
65