Skip to content

Commit

Permalink
Made Authen::SASL really optional
Browse files Browse the repository at this point in the history
git-svn-id: http://code.sixapart.com/svn/djabberd/trunk@854 43dd9337-660f-0410-bd32-e7601923a1a1
  • Loading branch information
yannk committed Feb 11, 2009
1 parent ec48128 commit 11f062a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
1 change: 0 additions & 1 deletion Makefile.PL
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ WriteMakefile(
'Net::SSLeay' => 0, 'Net::SSLeay' => 0,
'Log::Log4perl' => 0, 'Log::Log4perl' => 0,
'Digest::HMAC_SHA1' => 0, 'Digest::HMAC_SHA1' => 0,
'Authen::SASL' => 2.13
}, },
clean => { FILES => 't/log/*' }, clean => { FILES => 't/log/*' },
AUTHOR => 'Brad Fitzpatrick <brad@danga.com>', AUTHOR => 'Brad Fitzpatrick <brad@danga.com>',
Expand Down
40 changes: 23 additions & 17 deletions t/features-hook.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use Test::More tests => 11;
use lib 't/lib'; use lib 't/lib';
require 'djabberd-test.pl'; require 'djabberd-test.pl';


my $HAS_SASL;
eval "use Authen::SASL 2.13";
$HAS_SASL = 1 unless $@;


sub connect_and_get_features{ sub connect_and_get_features{
my $client = shift; my $client = shift;
Expand Down Expand Up @@ -53,23 +56,26 @@ sub connect_and_get_features{
} }
$server->kill; $server->kill;


$server = Test::DJabberd::Server->new(id => 1); SKIP: {
$server->start( ); # by default we have SASL plugin enabled skip "These tests require SASL", 8 unless $HAS_SASL;
my $client = Test::DJabberd::Client->new(server => $server, name => "client"); $server = Test::DJabberd::Server->new(id => 1);
{ $server->start( ); # by default we have SASL plugin enabled
my $features = connect_and_get_features($client); my $client = Test::DJabberd::Client->new(server => $server, name => "client");

{
like($features, qr{^<features xmlns='http://etherx.jabber.org/streams'>.*</features>$}); my $features = connect_and_get_features($client);
like($features, qr{<auth xmlns='http://jabber.org/features/iq-auth'/>});
like($features, qr{<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>.*</mechanisms>}); like($features, qr{^<features xmlns='http://etherx.jabber.org/streams'>.*</features>$});
like($features, qr{<optional/>}, "our test setup makes sasl optional, bc of history of djabberd"); like($features, qr{<auth xmlns='http://jabber.org/features/iq-auth'/>});
for my $mech (qw/PLAIN DIGEST-MD5 LOGIN/) { like($features, qr{<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>.*</mechanisms>});
like($features, qr{<mechanism>$mech</mechanism>}, "supports $mech"); like($features, qr{<optional/>}, "our test setup makes sasl optional, bc of history of djabberd");
} for my $mech (qw/PLAIN DIGEST-MD5 LOGIN/) {

like($features, qr{<mechanism>$mech</mechanism>}, "supports $mech");
like($features, qr{<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>.*</mechanisms>}); }
}
$server->kill; like($features, qr{<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>.*</mechanisms>});
}
$server->kill;
};
} }




Expand Down
18 changes: 13 additions & 5 deletions t/lib/djabberd-test.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ BEGIN
use DJabberd::TestSAXHandler; use DJabberd::TestSAXHandler;
use DJabberd::RosterStorage::InMemoryOnly; use DJabberd::RosterStorage::InMemoryOnly;
use DJabberd::Util; use DJabberd::Util;
use DJabberd::SASL::AuthenSASL;
use IO::Socket::UNIX; use IO::Socket::UNIX;


my $HAS_SASL;
eval "use Authen::SASL 2.13";
unless ($@) {
require DJabberd::SASL::AuthenSASL;
$HAS_SASL = 1;
}

sub once_logged_in { sub once_logged_in {
my $cb = shift; my $cb = shift;
my $sasl = shift; my $sasl = shift;
Expand Down Expand Up @@ -249,6 +255,11 @@ sub roster {


sub standard_plugins { sub standard_plugins {
my $self = shift; my $self = shift;
my @sasl;
@sasl = ( DJabberd::SASL::AuthenSASL->new(
mechanisms => "LOGIN PLAIN DIGEST-MD5",
optional => "yes",
)) if $HAS_SASL;
return [ return [
DJabberd::Authen::AllowedUsers->new(policy => "deny", DJabberd::Authen::AllowedUsers->new(policy => "deny",
allowedusers => [qw(partya partyb)]), allowedusers => [qw(partya partyb)]),
Expand All @@ -257,10 +268,7 @@ sub standard_plugins {
($ENV{T_MUC_ENABLE} ? (DJabberd::Plugin::MUC->new(subdomain => 'conference')) : ()), ($ENV{T_MUC_ENABLE} ? (DJabberd::Plugin::MUC->new(subdomain => 'conference')) : ()),
DJabberd::Delivery::Local->new, DJabberd::Delivery::Local->new,
DJabberd::Delivery::S2S->new, DJabberd::Delivery::S2S->new,
DJabberd::SASL::AuthenSASL->new( @sasl
mechanisms => "LOGIN PLAIN DIGEST-MD5",
optional => "yes",
),
]; ];
} }


Expand Down
13 changes: 11 additions & 2 deletions t/sasl-login.t
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 46; use Test::More;
use lib 't/lib'; use lib 't/lib';


require 'djabberd-test.pl'; require 'djabberd-test.pl';


use Authen::SASL 'Perl'; BEGIN {
eval "use Authen::SASL 2.13";
if ($@) {
plan skip_all => 'Tests require Authen::SASL 2.13+';
}
else {
plan tests => 46;
eval "use Authen::SASL 'Perl';";
}
}


my $login_and_be = sub { my $login_and_be = sub {
my ($pa, $pb, $sasl, $res) = @_; my ($pa, $pb, $sasl, $res) = @_;
Expand Down

0 comments on commit 11f062a

Please sign in to comment.