Skip to content

Commit

Permalink
Makes sure that user callbacks are called
Browse files Browse the repository at this point in the history
Even for dumb mechanisms like LOGIN and PLAIN
  • Loading branch information
yannk authored and gbarr committed Jun 2, 2010
1 parent 7ead99c commit c6462fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/Authen/SASL/Perl/LOGIN.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ sub server_step {
my $result = shift; my $result = shift;
unless ($result) { unless ($result) {
$self->set_error($error); $self->set_error($error);
$user_cb->();
} }
else { else {
$self->set_success; $self->set_success;
} }
$user_cb->();
}; };
$checkpass->($self => $answers => $cb ); $checkpass->($self => $answers => $cb );
return; return;
Expand Down
2 changes: 1 addition & 1 deletion lib/Authen/SASL/Perl/PLAIN.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ sub server_start {
my $result = shift; my $result = shift;
unless ($result) { unless ($result) {
$self->set_error($error); $self->set_error($error);
$user_cb->();
} }
else { else {
$self->set_success; $self->set_success;
} }
$user_cb->();
}; };
$checkpass->($self => { %parts } => $cb ); $checkpass->($self => { %parts } => $cb );
return; return;
Expand Down
20 changes: 14 additions & 6 deletions t/server/login.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use strict; use strict;
use warnings; use warnings;


use Test::More tests => 20; use Test::More tests => 32;


use Authen::SASL qw(Perl); use Authen::SASL qw(Perl);
use_ok('Authen::SASL::Perl::LOGIN'); use_ok('Authen::SASL::Perl::LOGIN');
Expand Down Expand Up @@ -40,9 +40,13 @@ sub is_failure {
my $creds = shift; my $creds = shift;
my @steps = @_; my @steps = @_;
## wouldn't really work in an async environemnt ## wouldn't really work in an async environemnt
$server->server_start(""); my $cb;
$server->server_start("", sub { $cb = 1 });
ok $cb, "callback called";
for (@steps) { for (@steps) {
$server->server_step($_); $cb = 0;
$server->server_step($_, sub { $cb = 1 });
ok $cb, "callback called";
} }
ok !$server->is_success, "failure"; ok !$server->is_success, "failure";
ok ($server->need_step or $server->error), "no success means that"; ok ($server->need_step or $server->error), "no success means that";
Expand All @@ -68,7 +72,11 @@ sub is_failure {


ok($ssasl = Authen::SASL->new( %params ), "new"); ok($ssasl = Authen::SASL->new( %params ), "new");
$server = $ssasl->server_new("ldap","localhost"); $server = $ssasl->server_new("ldap","localhost");
$server->server_start(""); my $cb;
$server->server_step("foo"); $server->server_start("", sub { $cb = 1 });
$server->server_step("bar"); ok $cb, "callback called"; $cb = 0;
$server->server_step("foo", sub { $cb = 1 });
ok $cb, "callback called"; $cb = 0;
$server->server_step("bar", sub { $cb = 1 });
ok $cb, "callback called";
ok $server->is_success, "success"; ok $server->is_success, "success";
10 changes: 7 additions & 3 deletions t/server/plain.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use strict; use strict;
use warnings; use warnings;


use Test::More tests => 47; use Test::More tests => 67;


use Authen::SASL qw(Perl); use Authen::SASL qw(Perl);
use_ok('Authen::SASL::Perl::PLAIN'); use_ok('Authen::SASL::Perl::PLAIN');
Expand Down Expand Up @@ -67,7 +67,9 @@ for my $authname ('', 'none') {
is_failure("$authname\0yann\0\0maelys", "double null"); is_failure("$authname\0yann\0\0maelys", "double null");
is_failure("$authname\0yann\0maelys\0trailing", "trailing"); is_failure("$authname\0yann\0maelys\0trailing", "trailing");


$server->server_start("$authname\0yann\0maelys"); my $cb;
$server->server_start("$authname\0yann\0maelys", sub { $cb = 1 });
ok $cb, "callback called";
ok $server->is_success, "success finally"; ok $server->is_success, "success finally";
} }


Expand Down Expand Up @@ -97,7 +99,9 @@ ok $server->is_success, "success";
sub is_failure { sub is_failure {
my $creds = shift; my $creds = shift;
my $msg = shift; my $msg = shift;
$server->server_start($creds); my $cb;
$server->server_start($creds, sub { $cb = 1 });
ok $cb, 'callback called';
ok !$server->is_success, $msg || "failure"; ok !$server->is_success, $msg || "failure";
my $error = $server->error || ""; my $error = $server->error || "";
like $error, qr/match/i, "failure"; like $error, qr/match/i, "failure";
Expand Down

0 comments on commit c6462fd

Please sign in to comment.