Fix, test, document
[catagits/Catalyst-Authentication-Credential-HTTP.git] / t / live_app.t
CommitLineData
790f9ddb 1#!/usr/bin/perl
790f9ddb 2use strict;
3use warnings;
bd1101db 4
5use FindBin qw/$Bin/;
6use lib "$Bin/lib";
7
ed61ff6d 8use Test::More;
ed61ff6d 9BEGIN {
3aff571e 10 do {
11 eval { require Test::WWW::Mechanize::Catalyst }
12 and
13 Test::WWW::Mechanize::Catalyst->VERSION('0.51')
14 }
ed61ff6d 15 or plan skip_all =>
16 "Test::WWW::Mechanize::Catalyst is needed for this test";
ed61ff6d 17}
790f9ddb 18use HTTP::Request;
861c2f44 19
20use Test::More;
282361af 21use Test::WWW::Mechanize::Catalyst;
22my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp');
790f9ddb 23$mech->get("http://localhost/moose");
513d8ab6 24is( $mech->status, 401, "status is 401" ) or die $mech->content;
ed61ff6d 25$mech->content_lacks( "foo", "no output" );
790f9ddb 26my $r = HTTP::Request->new( GET => "http://localhost/moose" );
27$r->authorization_basic(qw/foo s3cr3t/);
ed61ff6d 28$mech->request($r);
29is( $mech->status, 200, "status is 200" );
30$mech->content_contains( "foo", "foo output" );
513d8ab6 31
282361af 32AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(1);
33$mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp');
34$mech->get("http://localhost/moose");
35isnt( $mech->status, 401, "status isnt 401" ) or die $mech->content;
36
37AuthTestApp->get_auth_realm('test')->credential->no_unprompted_authorization_required(0);
38AuthTestApp->get_auth_realm('test')->credential->require_ssl(1);
39$mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AuthTestApp');
40$r = HTTP::Request->new( GET => "http://localhost/moose" );
41$r->authorization_basic(qw/foo s3cr3t/);
42$mech->request($r);
43is( $mech->status, 401, "status is 401" );
44
45done_testing;
46