Apache-AuthCookie
view release on metacpan or search on metacpan
# TODO: handle line-endings better. Perhaps we should just look for an
# identifying part of each page rather than trying to do an exact match
# of the entire page. The problem is on win32, some responses come back with
# dos-style line endings (not all of them though). Not sure what MacOS does
# and I don't have a Mac to test with. Currently, we just strip CR's out of
# responses to make the tests pass on Unix and Win32.
use strict;
use warnings FATAL => 'all';
use lib 'lib';
use utf8;
use Apache::Test '-withtestmore';
use Apache::TestUtil;
use Apache::TestRequest qw(GET POST GET_BODY);
use Encode qw(encode);
use URI;
Apache::TestRequest::user_agent( reset => 1, requests_redirectable => 0 );
plan tests => 39, need_lwp;
ok 1, 'Test initialized';
# extract the configured hostname + port from Apache::Test
my $apache_test_config = Apache::Test::config();
my $host_port = Apache::TestRequest::hostport($apache_test_config);
# TODO: the test descriptions should be things other than 'test #' here.
# check that /docs/index.html works. If this fails, the test environment did
# not configure properly.
subtest 'get index.html' => sub {
plan tests => 1;
my $url = '/docs/index.html';
my $data = strip_cr(GET_BODY $url);
like($data, qr/Get the protected document/s,
'/docs/index.html seems to work');
};
# test no_cookie failure
subtest 'no cookie' => sub {
plan tests => 1;
my $url = '/docs/protected/get_me.html';
my $r = GET $url;
like($r->content, qr/Failure reason: 'no_cookie'/s,
'no_cookie works');
};
# should succeed with redirect.
subtest 'login redirects' => sub {
plan tests => 2;
my $r = POST('/LOGIN', [
destination => '/docs/protected/get_me.html',
credential_0 => 'programmer',
credential_1 => 'Hero'
]);
is($r->code, 302, 'login produces redirect');
is($r->header('Location'), '/docs/protected/get_me.html',
'redirect header exists, and contains expected url');
};
subtest 'redirect with bad session key' => sub {
plan tests => 3;
( run in 0.471 second using v1.01-cache-2.11-cpan-39bf76dae61 )