funky donkey
[catagits/Catalyst-Authentication-Credential-HTTP.git] / t / live_app.t
CommitLineData
790f9ddb 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 4;
7use 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
0914298e 29 $c->res->body( $c->user->id );
790f9ddb 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
49use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
50
51my $mech = Test::WWW::Mechanize::Catalyst->new;
52
53$mech->get("http://localhost/moose");
54is( $mech->status, 401, "status is 401");
55
56$mech->content_lacks("foo", "no output");
57
58my $r = HTTP::Request->new( GET => "http://localhost/moose" );
59$r->authorization_basic(qw/foo s3cr3t/);
60
61$mech->request( $r );
62is( $mech->status, 200, "status is 200");
63$mech->content_contains("foo", "foo output");
64
65