forked from gbarr/perl-authen-sasl
/
plain.t
66 lines (56 loc) · 1.43 KB
/
plain.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!perl
use Test::More tests => 9;
use FindBin qw($Bin);
require "$Bin/../lib/common.pl";
use Authen::SASL qw(Perl);
use_ok('Authen::SASL::Perl::PLAIN');
## base conf
my $cconf = {
sasl => {
mechanism => 'PLAIN',
callback => {
user => 'yann',
pass => 'maelys',
},
},
host => 'localhost',
service => 'xmpp',
};
my $sconf = {
sasl => {
mechanism => 'PLAIN',
callback => {
pass => 'maelys',
},
},
host => 'localhost',
service => 'xmpp',
};
## base negotiation should work
negotiate($cconf, $sconf, sub {
my ($clt, $srv) = @_;
is $clt->mechanism, "PLAIN";
is $srv->mechanism, "PLAIN";
ok $clt->is_success, "client success" or diag $clt->error;
ok $srv->is_success, "server success" or diag $srv->error;
});
## invalid password
{
# hey callback could just be a subref that returns a localvar
local $sconf->{sasl}{callback}{pass} = "x";
negotiate($cconf, $sconf, sub {
my ($clt, $srv) = @_;
ok ! $srv->is_success, "wrong pass";
like $srv->error, qr/match/, "error set";
});
}
## invalid password
{
# hey callback could just be a subref that returns a localvar
local $sconf->{sasl}{callback}{pass} = "x";
negotiate($cconf, $sconf, sub {
my ($clt, $srv) = @_;
ok ! $srv->is_success, "wrong pass";
like $srv->error, qr/match/, "error set";
});
}