lemonldap-ng/lemonldap-ng-handler/t/65-Lemonldap-NG-Handler-PSGI-ServiceToken.t

126 lines
2.9 KiB
Perl
Raw Normal View History

2017-03-04 13:24:56 +01:00
use Test::More;
BEGIN {
require 't/test-psgi-lib.pm';
}
2019-05-26 18:29:18 +02:00
init(
'Lemonldap::NG::Handler::Server',
{
2019-05-26 20:42:43 +02:00
logLevel => 'error',
2019-05-26 18:29:18 +02:00
handlerServiceTokenTTL => 2,
2019-05-26 21:43:25 +02:00
vhostOptions => {
'test1.example.com' => {
vhostHttps => 0,
vhostPort => 80,
vhostMaintenance => 0,
vhostServiceTokenTTL => 3,
2019-05-26 22:15:24 +02:00
},
'test2.example.com' => {
vhostHttps => 0,
vhostPort => 80,
vhostMaintenance => 0,
vhostServiceTokenTTL => 5,
2019-05-26 21:43:25 +02:00
}
},
2019-05-26 18:29:18 +02:00
}
);
2017-03-04 13:24:56 +01:00
my $res;
my $crypt = Lemonldap::NG::Common::Crypto->new('qwertyui');
2019-05-27 19:58:54 +02:00
my $token = $crypt->encrypt( join ':', time, $sessionId, 'test1.example.com', 'test2.example.com', '*.example.com' );
2017-03-04 13:24:56 +01:00
ok(
$res = $client->_get(
'/', undef, 'test1.example.com', undef,
VHOSTTYPE => 'ServiceToken',
2017-03-04 13:24:56 +01:00
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
count(2);
2019-05-29 00:09:23 +02:00
diag 'Waiting';
2019-05-26 21:43:25 +02:00
sleep 2;
2019-05-26 18:29:18 +02:00
ok(
$res = $client->_get(
'/', undef, 'test1.example.com', undef,
VHOSTTYPE => 'ServiceToken',
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
2019-05-26 21:43:25 +02:00
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
count(2);
2019-05-29 00:09:23 +02:00
diag 'Waiting';
2019-05-26 21:43:25 +02:00
sleep 1;
ok(
$res = $client->_get(
'/', undef, 'test1.example.com', undef,
VHOSTTYPE => 'ServiceToken',
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
ok( $res->[0] == 302, 'Code is 200' ) or explain( $res->[0], 302 );
count(2);
2019-05-29 00:09:23 +02:00
diag 'Waiting';
2019-05-26 22:15:24 +02:00
sleep 1;
ok(
$res = $client->_get(
'/', undef, 'test2.example.com', undef,
VHOSTTYPE => 'ServiceToken',
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
count(2);
2019-05-29 00:09:23 +02:00
diag 'Waiting';
2019-05-26 22:15:24 +02:00
sleep 1;
2019-05-26 21:43:25 +02:00
ok(
$res = $client->_get(
'/', undef, 'test2.example.com', undef,
VHOSTTYPE => 'ServiceToken',
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
2019-05-26 18:29:18 +02:00
ok( $res->[0] == 302, 'Code is 302' ) or explain( $res->[0], 302 );
count(2);
2019-05-26 22:15:24 +02:00
ok(
$res = $client->_get(
'/', undef, 'test3.example.com', undef,
VHOSTTYPE => 'ServiceToken',
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
ok( $res->[0] == 302, 'Code is 302' ) or explain( $res->[0], 302 );
count(2);
2019-05-26 21:43:25 +02:00
$token = $crypt->encrypt( join ':', time, $sessionId, '' );
2019-05-26 18:36:45 +02:00
ok(
$res = $client->_get(
'/', undef, 'test2.example.com', undef,
VHOSTTYPE => 'ServiceToken',
'HTTP_X_LLNG_TOKEN' => $token,
),
'Query with token'
);
ok( $res->[0] == 302, 'Code is 302' ) or explain( $res->[0], 302 );
count(2);
2017-03-04 13:24:56 +01:00
done_testing( count() );
clean();