File: 68-Lemonldap-NG-Handler-PSGI-Zimbra.t

package info (click to toggle)
lemonldap-ng 2.21.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 28,024 kB
  • sloc: perl: 77,414; javascript: 25,284; xml: 6,473; makefile: 1,303; sh: 453; sql: 159; python: 53; php: 26
file content (82 lines) | stat: -rw-r--r-- 2,452 bytes parent folder | download | duplicates (5)
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
81
82
use Test::More;

BEGIN {
    require 't/test-psgi-lib.pm';
}

my $maintests = 8;

SKIP: {
    eval { require Digest::HMAC_SHA1; };
    if ($@) {
        skip 'Digest::HMAC_SHA1 not found', $maintests;
    }
    init(
        'Lemonldap::NG::Handler::Server',
        {
            logLevel         => 'error',
            zimbraPreAuthKey => '1234567890',
            zimbraUrl        => '/service/preauthtest ',
            zimbraSsoUrl     => '^/testsso  ',             # Bad URLs
            vhostOptions     => {
                'test1.example.com' => {
                    vhostHttps           => 0,
                    vhostPort            => 80,
                    vhostMaintenance     => 0,
                    vhostServiceTokenTTL => -1,
                },
            },
            exportedHeaders => {
                'test1.example.com' => {
                    'Auth-User' => '$uid',
                },
            }
        }
    );

    # Request a non-Zimbra URL
    ok(
        $res = $client->_get(
            '/test',             undef,
            'test1.example.com', "lemonldap=$sessionId",
            VHOSTTYPE => 'ZimbraPreAuth',
        ),
        'Non-Zimbra URL Query'
    );
    ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );

    # Check headers
    %h = @{ $res->[1] };
    ok( !defined $h{'Location'}, 'Location is undefined' )
      or explain( \%h, 'Location => "URL"' );
    ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
      or explain( \%h, 'Auth-User => "dwho"' );

    # Request Zimbra URL
    my $timestamp = time() * 1000;
    my $value =
      Digest::HMAC_SHA1::hmac_sha1_hex( "dwho|id|0|$timestamp", '1234567890' );
    ok(
        $res = $client->_get(
            '/testsso',          undef,
            'test1.example.com', "lemonldap=$sessionId",
            VHOSTTYPE => 'ZimbraPreAuth',
        ),
        'Zimbra URL Query'
    );
    ok( $res->[0] == 302, 'Code is 302' ) or explain( $res->[0], 302 );

    # Check headers
    %h = @{ $res->[1] };
    ok(
        $h{'Location'} =~
m%^/service/preauthtest\?account=dwho&by=id&timestamp=$timestamp&expires=0&preauth=$value$%,
        'Header Location is set to Zimbra URL'
    ) or explain( \%h, 'Location => "Zimbra URL"' );
    ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
      or explain( \%h, 'Auth-User => "dwho"' );
}

count($maintests);
done_testing( count() );
clean();