File: order.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 (49 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (8)
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
#!perl

use Test::More tests => 75;

use Authen::SASL qw(Perl);

my %order = qw(
  ANONYMOUS	0
  LOGIN		1
  PLAIN		1
  CRAM-MD5	2
  EXTERNAL	2
  DIGEST-MD5	3
);
my $skip3 = !eval { require Digest::MD5 and $Digest::MD5::VERSION || $Digest::MD5::VERSION };

foreach my $level (reverse 0..3) {
  my @mech = grep { $order{$_} <= $level } keys %order;
  foreach my $n (1..@mech) {
    push @mech, shift @mech; # rotate
    my $mech = join(" ",@mech);
    print "# $level $mech\n";
    if ($level == 3 and $skip3) {
      SKIP: {
	skip "requires Digest::MD5", 5;
      }
      next;
    }
    my $sasl = Authen::SASL->new(
      mechanism => $mech,
      callback => {
	user => 'gbarr',
	pass => 'fred',
	authname => 'none'
      },
    );
    ok($sasl, "new");

    is($sasl->mechanism, $mech, "sasl mechanism");

    my $conn = $sasl->client_new("ldap","localhost");
    ok($conn, 'client_new');

    my $chosen = $conn->mechanism;
    ok($chosen, 'conn mechanism ' . ($chosen || '?'));

    is($order{$chosen}, $level, 'mechanism level');
  }
}