Apache-AuthCookie
view release on metacpan or search on metacpan
t/lib/Sample/Apache/AuthCookieHandler.pm view on Meta::CPAN
package Sample::Apache::AuthCookieHandler;
use strict;
use utf8;
use base 'Apache::AuthCookie';
use Apache;
use Apache::Constants qw(:common);
use Apache::AuthCookie;
use Apache::Util;
use URI::Escape qw(uri_escape_utf8 uri_unescape);
use Encode;
sub authen_cred ($$\@) {
my $self = shift;
my $r = shift;
my @creds = @_;
return if $creds[0] eq 'fail'; # simulate bad_credentials
# This would really authenticate the credentials
# and return the session key.
# Here I'm just using setting the session
# key to the escaped credentials and delaying authentication.
return join ':', map { uri_escape_utf8($_) } @creds;
}
sub authen_ses_key ($$$) {
my ($self, $r, $ses_key) = @_;
# NOTE: uri_escape_utf8() was used to encode this so we have to decode
# using UTF-8. We don't rely on $self->encoding($r) here because if an
# encoding other than UTF-8 is configured in t/conf/extra.conf.in, then the
# wrong encoding gets used here.
my($user, $password) =
map { decode('UTF-8', uri_unescape($_)) }
split /:/, $ses_key, 2;
if ($user eq 'programmer' && $password eq 'Hero') {
return $user;
}
t/lib/Sample/Apache2/AuthCookieHandler.pm view on Meta::CPAN
package Sample::Apache2::AuthCookieHandler;
use strict;
use utf8;
use Class::Load 'load_class';
use Apache2::Const qw(:common HTTP_FORBIDDEN);
use Apache2::AuthCookie;
use Apache2::RequestRec;
use Apache2::RequestIO;
use Apache2::Util;
use URI::Escape qw(uri_escape_utf8 uri_unescape);
use Encode qw(decode);
use vars qw(@ISA);
use Apache::Test;
use Apache::TestUtil;
if (have_min_apache_version('2.4.0')) {
load_class('Apache2_4::AuthCookie');
@ISA = qw(Apache2_4::AuthCookie);
}
t/lib/Sample/Apache2/AuthCookieHandler.pm view on Meta::CPAN
my @creds = @_;
$r->server->log_error("authen_cred entry");
return if $creds[0] eq 'fail'; # simulate bad_credentials
# This would really authenticate the credentials
# and return the session key.
# Here I'm just using setting the session
# key to the escaped credentials and delaying authentication.
return join ':', map { uri_escape_utf8($_) } @creds;
}
sub authen_ses_key ($$$) {
my ($self, $r, $cookie) = @_;
my ($user, $password) =
map { decode('UTF-8', uri_unescape($_)) }
split /:/, $cookie, 2;
$r->server->log_error("authen_ses_key entry");
# 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;
is($r->code, '200', 'get protected document');
like($r->content, qr/Congratulations, you got past AuthCookie/s,
'check protected document content');
};
subtest 'POST to GET conversion' => sub {
plan tests => 1;
my $r = POST('/docs/protected/get_me.html', [
utf8 => 'programmør'
]);
like($r->content, qr#"/docs/protected/get_me\.html\?utf8=programm%c3%b8r"#,
'POST -> GET conversion works');
};
subtest 'QUERY_STRING is preserved' => sub {
plan tests => 1;
my $data = GET_BODY('/docs/protected/get_me.html?foo=bar');
like($data, qr#"/docs/protected/get_me\.html\?foo=bar"#,
'input query string exists in desintation');
( run in 0.641 second using v1.01-cache-2.11-cpan-49f99fa48dc )