File: 63-Lemonldap-NG-Handler-PSGI-Try.t

package info (click to toggle)
lemonldap-ng 2.21.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (74 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (3)
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
use Test::More;
use JSON;
use MIME::Base64;
use Data::Dumper;

require 't/test-psgi-lib.pm';

my $app;

use_ok('Lemonldap::NG::Handler::PSGI::Try');

ok( $app = module( Lemonldap::NG::Handler::PSGI::Try->new() ), 'New object' );

init();

ok(
    $app->init(
        {
            configStorage       => { type => 'File', dirName => 't' },
            localSessionStorage => '',
            logLevel            => 'warn',
            cookieName          => 'lemonldap',
            securedCookie       => 2,
            https               => 1,
            userLogger          => 'Lemonldap::NG::Common::Logger::Null',
        }
    ),
    'initialization'
);

ok( $app->addAuthRoute( test => sub { [ 200, [], ['Auth'] ] }, ['GET'] ),
    'Set auth route' );

ok( $app->addUnauthRoute( test => sub { [ 200, [], ['Unauth'] ] }, ['GET'] ),
    'Set auth route' );

count(4);

my $res;

# Unauth tests
ok( $res = $client->_get('/test'), 'Get response' );
ok( $res->[0] == 200,              'Response code is 200' )
  or print "Expect 200, got $res->[0]\n";
ok( $res->[2]->[0] eq 'Unauth', 'Get unauth result' )
  or print "Expect Unauth, got $res->[2]->[0]\n";
count(3);

# Auth tests
ok(
    $res = $client->_get(
        '/test',
        undef,
        undef,
'lemonldap=f5eec18ebb9bc96352595e2d8ce962e8ecf7af7c9a98cb9a43f9cd181cf4b545'
    ),
    'Get response'
);
ok( $res->[0] == 200, 'Response code is 200' )
  or print "Expect 200, got $res->[0]\n";
ok( $res->[2]->[0] eq 'Auth', 'Get auth result' )
  or print "Expect Auth, got $res->[2]->[0]\n";
count(3);

# Bad path test

ok( $res = $client->_get('/[]/test'), 'Try a bad path' );
ok( $res->[0] == 400,                 'Response is 400' );
count(2);

clean();

done_testing( count() );