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