File: digest_md5.t

package info (click to toggle)
libauthen-sasl-perl 2.1900-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: perl: 2,249; makefile: 7
file content (80 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download | duplicates (6)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!perl
use strict;
use warnings;
use Test::More tests => 11;
use FindBin qw($Bin);
require "$Bin/../lib/common.pl";

## base conf
my $cconf = {
    sasl => {
        mechanism => 'DIGEST-MD5',
        callback => {
            user => 'yann',
            pass => 'maelys',
        },
    },
    host => 'localhost',
    security => 'noanonymous',
    service => 'xmpp',
};

my $sconf = {
    sasl => {
        mechanism => 'DIGEST-MD5',
        callback => {
            getsecret => sub { $_[2]->('maelys') },
        },
    },
    host => 'localhost',
    service => 'xmpp',
};

## base negotiation should work
negotiate($cconf, $sconf, sub {
    my ($clt, $srv) = @_;
    ok $clt->is_success, "client success" or diag $clt->error;
    ok $srv->is_success, "server success" or diag $srv->error;
});

## invalid password
{
    local $cconf->{sasl}{callback}{pass} = "YANN";

    negotiate($cconf, $sconf, sub {
        my ($clt, $srv) = @_;
        ok !$srv->is_success, "failure";
        like $srv->error, qr/response/;
    });
}

## arguments passed to server pass callback
{
    local $cconf->{sasl}{callback}{authname} = "some authzid";
    local $sconf->{sasl}{callback}{getsecret} = sub {
        my $server = shift;
        my ($args, $cb) = @_;
        is $args->{user},     "yann",         "username";
        is $args->{realm},    "localhost",    "realm";
        is $args->{authzid},  "some authzid", "authzid";
        $cb->("incorrect");
    };

    negotiate($cconf, $sconf, sub {
        my ($clt, $srv) = @_;
        ok !$srv->is_success, "failure";
        like $srv->error, qr/response/, "incorrect response";
    });
}

## digest-uri checking
{
    local $cconf->{host}    = "elsewhere";
    local $cconf->{service} = "pop3";
    negotiate($cconf, $sconf, sub {
        my ($clt, $srv) = @_;
        ok !$srv->is_success, "failure";
        my $error = $srv->error || "";
        like $error, qr/incorrect.*digest.*uri/i, "incorrect digest uri";
    });
}