File: 20-Default-Broker.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 (66 lines) | stat: -rw-r--r-- 1,832 bytes parent folder | download | duplicates (2)
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
use Test::More;
use Time::Fake;

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

init('Lemonldap::NG::Handler::PSGI');

my $res;
unlink 't/lmConf-2.json', 't/lmConf-3.json';

# Check current conf
ok( $res = $client->_get( '/deny', undef, undef, "lemonldap=$sessionId" ),
    'Denied query' );
ok( $res->[0] == 403, ' Code is 403' ) or explain( $res->[0], 403 );

newConf( 1, '/deny', '/deny2' );

Time::Fake->offset('+6s');
ok( $res = $client->_get( '/deny', undef, undef, "lemonldap=$sessionId" ),
    'Denied query' );
ok( $res->[0] == 200, ' Conf was updated' ) or explain( $res->[0], 200 );

newConf( 2, '/deny2', '/deny' );

Time::Fake->offset('+12s');
ok( $res = $client->_get( '/deny', undef, undef, "lemonldap=$sessionId" ),
    'Denied query' );
ok( $res->[0] == 403, ' Conf was updated' ) or explain( $res->[0], 403 );

unlink(
't/sessions/lock/Apache-Session-e5eec18ebb9bc96352595e2d8ce962e8ecf7af7c9a98cb9a43f9cd181cf4b545.lock',
    't/lmConf-2.json', 't/lmConf-3.json',
);

done_testing();

clean();

sub newConf {
    my ( $cfgNum, $src, $dst ) = @_;
    my $next = $cfgNum + 1;
    open my $cur, '<', "t/lmConf-$cfgNum.json";
    open my $new, '>', "t/lmConf-$next.json";

    while ( my $line = <$cur> ) {
        $line =~ s/("cfgNum")\s*:\s*"?$cfgNum"?"?/$1:$next/;
        $line =~ s#$src#$dst#;
        print $new $line;
    }
    $new->close;
    $cur->close;
}

sub Lemonldap::NG::Handler::PSGI::handler {
    my ( $self, $req ) = @_;
    if ($SKIPUSER) {
        ok( !$req->env->{HTTP_AUTH_USER}, 'No HTTP_AUTH_USER' )
          or explain( $req->env->{HTTP_AUTH_USER}, '<empty>' );
    }
    else {
        ok( $req->env->{HTTP_AUTH_USER} eq 'dwho', 'Header is given to app' )
          or explain( $req->env->{HTTP_AUTH_USER}, 'dwho' );
    }
    count(1);
    return [ 200, [ 'Content-Type', 'text/plain' ], ['Hello'] ];
}