Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated tests to not user prepare_ioloop, new 0.06 build

  • Loading branch information...
commit 4ef4d184c43075e04ac969d37e8f324cb195df0a 1 parent 8d36aac
@tempire authored
View
4 Changes
@@ -1,7 +1,9 @@
+0.06 2012-05-25
+ - Adjusted for recent prepare_ioloop removal Test::Mojo changes
+
0.05 2011-06-13
- Bumped Mojolicious & IO::Socket::SSL requirements
0.04 2011-06-08
- Added github urls to metadata
- Added github urls to metadata
-
View
BIN  Mojolicious-Plugin-SslAuth-0.05.tar.gz
Binary file not shown
View
BIN  Mojolicious-Plugin-SslAuth-0.06.tar.gz
Binary file not shown
View
4 dist.ini
@@ -4,7 +4,7 @@ license = Perl_5
copyright_holder = Glen Hinkle
copyright_year = 2011
-version = 0.05
+version = 0.06
[@Filter]
bundle = @Basic
@@ -16,5 +16,5 @@ repository.url = git://github.com/tempire/mojolicious-plugin-sslauth.git
repository.type = git
[Prereqs]
-Mojolicious = 1.43
+Mojolicious = 2.81
IO::Socket::SSL = 1.44
View
39 lib/Mojolicious/Plugin/SslAuth.pm
@@ -4,27 +4,27 @@ use strict;
use warnings;
use Mojo::IOLoop;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
use base 'Mojolicious::Plugin';
sub register {
- my ( $plugin, $app ) = @_;
+ my ($plugin, $app) = @_;
- $app->helper(
- ssl_auth => sub {
- my $self = shift;
- my $callback = shift;
+ $app->helper(
+ ssl_auth => sub {
+ my $self = shift;
+ my $callback = shift;
- my $id = $self->tx->connection;
- my $handle = Mojo::IOLoop->singleton->handle($id);
+ my $id = $self->tx->connection;
+ my $handle = Mojo::IOLoop->stream($id)->handle;
- # Not SSL connection
- return if ref $handle ne 'IO::Socket::SSL';
+ # Not SSL connection
+ return if ref $handle ne 'IO::Socket::SSL';
- return $callback->($handle);
- }
- );
+ return $callback->($handle);
+ }
+ );
}
1;
@@ -38,6 +38,10 @@ Mojolicious::Plugin::SslAuth - SSL client certificate auth helper
L<Mojolicous::Plugin::SslAuth> is a helper for authenticating client ssl certificates against CA's (certificate authorities)
+=head2 If using Mojolicious versions before 2.81
+
+L<0.05|http://backpan.perl.org/authors/id/T/TE/TEMPIRE/Mojolicious-Plugin-SslAuth-0.05.tar.gz>
+
=head1 USAGE
use Mojolicious::Lite;
@@ -49,10 +53,9 @@ L<Mojolicous::Plugin::SslAuth> is a helper for authenticating client ssl certifi
return $self->render_text('ok')
if $self->ssl_auth(
- sub {
- return 1 if shift->peer_certificate('commonName') eq 'client';
- }
- );
+ {return 1 if shift->peer_certificate('commonName') eq 'client'});
+
+ $self->render_text('commonName not matched');
};
app->start;
@@ -82,7 +85,7 @@ L<http://github.com/tempire/mojolicious-plugin-sslauth>
=head1 VERSION
-0.05
+0.06
=head1 AUTHOR
View
61 t/auth.t
@@ -1,3 +1,5 @@
+#use IO::Socket::SSL 'debug4';
+use IO::Socket::SSL;
use Mojo::IOLoop;
use Test::More;
use Test::Mojo;
@@ -6,8 +8,6 @@ use Test::Mojo;
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port; # Test server
-plan tests => 6;
-
# Lite app
use Mojolicious::Lite;
@@ -17,45 +17,44 @@ app->log->level('error');
plugin 'ssl_auth';
get '/' => sub {
- my $self = shift;
+ my $self = shift;
- return $self->render_text('ok')
- if $self->ssl_auth(
- sub {
- return 1 if shift->peer_certificate('cn') eq 'client';
- }
- );
+ return $self->render(text => 'ok')
+ if $self->ssl_auth(
+ sub { return 1 if shift->peer_certificate('cn') eq 'client' });
- $self->render( text => '', status => 401 );
+ $self->render(text => '', status => 401);
};
-my $loop = Mojo::IOLoop->singleton;
-my $server = Mojo::Server::Daemon->new( app => app, ioloop => $loop );
+my $ioloop = Mojo::IOLoop->singleton;
+my $daemon = Mojo::Server::Daemon->new(app => app, ioloop => $ioloop);
my $port = Mojo::IOLoop->generate_port;
-$server->listen( [
- "https://localhost:$port"
- . ':t/certs/server.crt'
- . ':t/certs/server.key'
- . ':t/certs/ca.crt'
- ]
-);
-$server->prepare_ioloop;
+$daemon->listen(
+ [ "https://127.0.0.1:$port"
+ . '?cert=t/certs/server.crt'
+ . '&key=t/certs/server.key'
+ . '&ca=t/certs/ca.crt'
+ ]
+)->start;
# Success - expected common name
my $ua = Mojo::UserAgent->new(
- ioloop => $loop,
- cert => 't/certs/client.crt',
- key => 't/certs/client.key'
+ ioloop => $ioloop,
+ cert => 't/certs/client.crt',
+ key => 't/certs/client.key'
);
-my $t = Test::Mojo->new( app => app, ua => $ua );
-$t->get_ok("https://localhost:$port")->status_is(200)->content_is('ok');
+my $t = Test::Mojo->new;
+$t->ua($ua);
+$t->get_ok("https://127.0.0.1:$port")->status_is(200)->content_is('ok');
# Fail - different common name
$t->ua(
- Mojo::UserAgent->new(
- ioloop => $loop,
- cert => 't/certs/anotherclient.crt',
- key => 't/certs/anotherclient.key'
- )
+ Mojo::UserAgent->new(
+ ioloop => $ioloop,
+ cert => 't/certs/anotherclient.crt',
+ key => 't/certs/anotherclient.key'
+ )
);
-$t->get_ok("https://localhost:$port")->status_is(401)->content_is('');
+$t->get_ok("https://127.0.0.1:$port")->status_is(401)->content_is('');
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.