Commit 5a67fc1b authored by gregor herrmann's avatar gregor herrmann

Imported Upstream version 0.06

parent 20354fb5
0.06 2011-10-29
- Allow : in passwords (Kirill Miazine)
0.05 2011-06-02
- Removed unused reference to Mojo::Client in tests
- Require Mojolicious >= 1.4
......
---
abstract: 'Basic HTTP Auth Helper'
author:
- 'Glen Hinkle <tempire@cpan.org>'
- 'Glen Hinkle'
build_requires: {}
configure_requires:
ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.200006, CPAN::Meta::Converter version 2.110930'
generated_by: 'Dist::Zilla version 4.300002, CPAN::Meta::Converter version 2.112621'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
......@@ -14,4 +14,4 @@ meta-spec:
name: Mojolicious-Plugin-BasicAuth
requires:
Mojolicious: 1.4
version: 0.05
version: 0.06
......@@ -9,22 +9,22 @@ use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
'ABSTRACT' => 'Basic HTTP Auth Helper',
'AUTHOR' => 'Glen Hinkle <tempire@cpan.org>',
'BUILD_REQUIRES' => {},
'CONFIGURE_REQUIRES' => {
'ExtUtils::MakeMaker' => '6.30'
"ABSTRACT" => "Basic HTTP Auth Helper",
"AUTHOR" => "Glen Hinkle",
"BUILD_REQUIRES" => {},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.30"
},
'DISTNAME' => 'Mojolicious-Plugin-BasicAuth',
'EXE_FILES' => [],
'LICENSE' => 'perl',
'NAME' => 'Mojolicious::Plugin::BasicAuth',
'PREREQ_PM' => {
'Mojolicious' => '1.4'
"DISTNAME" => "Mojolicious-Plugin-BasicAuth",
"EXE_FILES" => [],
"LICENSE" => "perl",
"NAME" => "Mojolicious::Plugin::BasicAuth",
"PREREQ_PM" => {
"Mojolicious" => "1.4"
},
'VERSION' => '0.05',
'test' => {
'TESTS' => 't/*.t'
"VERSION" => "0.06",
"test" => {
"TESTS" => "t/*.t"
}
);
......
......@@ -44,22 +44,18 @@ L<http://github.com/tempire/mojolicious-plugin-basicauth>
=head1 VERSION
0.04
0.06
=head1 CREDITS
=over 4
=item Sebastian Riedel (sri) for L<Mojolicious>
=item Viacheslav Tykhanovskyi (vti) for spreading the love over IRC
=item Both of the above for making #mojo a much less abrasive place than #catalyst
=item Kirill Miazine
=back
=head1 AUTHOR
Glen Hinkle tempire@cpan.org
Glen Hinkle <tempire@cpan.org>
=cut
......@@ -2,7 +2,7 @@ name = Mojolicious-Plugin-BasicAuth
auth = Glen Hinkle <tempire@cpan.org>
license = Perl_5
copyright_holder = Glen Hinkle
version = 0.05
version = 0.06
[@Filter]
bundle = @Basic
......
......@@ -4,7 +4,7 @@ use strict;
use warnings;
use Mojo::ByteStream;
our $VERSION = '0.05';
our $VERSION = '0.06';
use base 'Mojolicious::Plugin';
......@@ -28,7 +28,7 @@ sub register {
if !$auth and !$callback;
# Verification within callback
return 1 if $callback and $callback->(split /:/, $auth);
return 1 if $callback and $callback->(split /:/, $auth, 2);
# Verified with realm => username => password syntax
return 1 if $auth eq ($username || '') . ":$password";
......@@ -108,17 +108,13 @@ L<http://github.com/tempire/mojolicious-plugin-basicauth>
=head1 VERSION
0.05
0.06
=head1 CREDITS
=over 4
=item Sebastian Riedel (sri) for L<Mojolicious>
=item Viacheslav Tykhanovskyi (vti) for spreading the love over IRC
=item Both of the above for making #mojo a much less abrasive place than #catalyst
=item Kirill Miazine
=back
......
use Mojo::IOLoop;
use Test::More;
use Test::Mojo;
use Mojo::ByteStream;
use Mojo::ByteStream 'b';
# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port; # Test server
plan tests => 39;
plan tests => 45;
# Lite app
use Mojolicious::Lite;
......@@ -20,10 +20,19 @@ get '/user-pass' => sub {
my $self = shift;
#return $self->render_text('denied')
return $self->render(text => 'denied')
unless $self->basic_auth(realm => username => 'password');
return $self->render(text => 'authorized')
if $self->basic_auth(realm => username => 'password');
$self->render_text('authorized');
$self->render_text('denied');
};
get '/user-pass-with-colon-password' => sub {
my $self = shift;
return $self->render(text => 'authorized')
if $self->basic_auth(realm => username => 'pass:word');
$self->render_text('denied');
};
get '/pass' => sub {
......@@ -39,17 +48,28 @@ get '/pass' => sub {
get '/get-auth-callback' => sub {
my $self = shift;
return $self->render_text('denied')
unless $self->basic_auth(
realm => sub { return 1 if "@_" eq 'username password' });
return $self->render_text('authorized')
if $self->basic_auth(
realm => sub { return "@_" eq 'username password' });
$self->render_text('authorized');
$self->render_text('denied');
};
# Callback with colon in password
get '/get-auth-callback-with-colon-password' => sub {
my $self = shift;
return $self->render_text('authorized')
if $self->basic_auth(
realm => sub { return "@_" eq 'username pass:word' });
return $self->render_text('denied');
};
under sub {
my $self = shift;
return $self->basic_auth(
realm => sub { return 1 if "@_" eq 'username password' });
realm => sub { return "@_" eq 'username password' });
};
get '/under-bridge' => sub {
......@@ -78,7 +98,7 @@ foreach (
->content_is('denied');
# Incorrect user/pass
$encoded = Mojo::ByteStream->new('bad:auth')->b64_encode->to_string;
$encoded = b('bad:auth')->b64_encode->to_string;
chop $encoded;
$t->get_ok($_, {Authorization => "Basic $encoded"})->status_is(401)
->header_is('WWW-Authenticate' => 'Basic realm=realm')
......@@ -87,7 +107,7 @@ foreach (
# Under bridge fail
diag '/under-bridge';
$encoded = Mojo::ByteStream->new("bad:auth")->b64_encode->to_string;
$encoded = b("bad:auth")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/under-bridge', {Authorization => "Basic $encoded"})
->status_is(401)->content_is('');
......@@ -96,29 +116,42 @@ $t->get_ok('/under-bridge', {Authorization => "Basic $encoded"})
# Username, password
diag '/user-pass';
$encoded = Mojo::ByteStream->new("username:password")->b64_encode->to_string;
$encoded = b("username:password")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/user-pass', {Authorization => "Basic $encoded"})->status_is(200)
->content_is('authorized');
# Username, password with colon in password
diag '/user-pass-with-colon-password';
$encoded = b("username:pass:word")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/user-pass-with-colon-password', {Authorization => "Basic $encoded"})->status_is(200)
->content_is('authorized');
# Password only
diag '/pass';
$encoded = Mojo::ByteStream->new(":password")->b64_encode->to_string;
$encoded = b(":password")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/pass', {Authorization => "Basic $encoded"})->status_is(200)
->content_is('authorized');
# With callback
diag '/get-auth-callback';
$encoded = Mojo::ByteStream->new("username:password")->b64_encode->to_string;
$encoded = b("username:password")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/get-auth-callback', {Authorization => "Basic $encoded"})
->status_is(200)->content_is('authorized');
# With callback and colon in password
diag '/get-auth-callback-with-colon-password';
$encoded = b("username:pass:word")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/get-auth-callback-with-colon-password', {Authorization => "Basic $encoded"})
->status_is(200)->content_is('authorized');
# Under bridge
diag '/under-bridge';
$encoded = Mojo::ByteStream->new("username:password")->b64_encode->to_string;
$encoded = b("username:password")->b64_encode->to_string;
chop $encoded;
$t->get_ok('/under-bridge', {Authorization => "Basic $encoded"})
->status_is(200)->content_is('authorized');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment