2016-04-03 18:27:13 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
2016-04-04 07:08:26 +02:00
|
|
|
use IO::String;
|
2016-04-03 18:27:13 +02:00
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
2016-04-04 07:08:26 +02:00
|
|
|
my $res;
|
|
|
|
|
2016-04-05 22:46:11 +02:00
|
|
|
init( { logLevel => 'debug', useSafeJail => 1 } );
|
2016-04-05 07:23:42 +02:00
|
|
|
|
2016-04-04 07:08:26 +02:00
|
|
|
ok( $res = &client->_get('/'), 'Unauth JSON request' );
|
|
|
|
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
|
|
|
|
count(2);
|
|
|
|
|
2016-04-05 13:12:53 +02:00
|
|
|
ok( $res = &client->_get('/?url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
|
|
|
|
'Unauth ajax request with good url' );
|
|
|
|
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
|
|
|
|
count(2);
|
|
|
|
|
2016-04-04 20:05:22 +02:00
|
|
|
ok(
|
2016-04-04 22:39:22 +02:00
|
|
|
$res = &client->_post(
|
2016-04-04 20:05:22 +02:00
|
|
|
'/', '',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
'application/x-www-form-urlencoded', 23
|
|
|
|
),
|
2016-04-04 22:39:22 +02:00
|
|
|
'Auth query'
|
|
|
|
);
|
2016-04-05 07:23:42 +02:00
|
|
|
|
|
|
|
my $cookies = getCookies($res);
|
|
|
|
my $id;
|
|
|
|
ok( $id = $cookies->{lemonldap}, 'Get cookie' );
|
|
|
|
count(2);
|
2016-04-03 18:27:13 +02:00
|
|
|
|
2016-04-05 13:12:53 +02:00
|
|
|
ok(
|
|
|
|
$res = &client->_get(
|
|
|
|
'/',
|
|
|
|
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Auth ajax request with good url'
|
|
|
|
);
|
2016-04-05 22:46:11 +02:00
|
|
|
ok( $res->[0] == 302, 'Get redirection' ) or explain( $res, 302 );
|
|
|
|
my %hdrs = @{ $res->[1] };
|
|
|
|
ok(
|
|
|
|
$hdrs{Location} eq 'http://test1.example.com/',
|
|
|
|
'Location is http://test1.example.com/'
|
|
|
|
) or explain( \%hdrs, 'Location => "http://test1.example.com/"' );
|
|
|
|
ok( $hdrs{'Lm-Remote-User'} eq 'dwho', 'User is set' )
|
|
|
|
or explain( \%hdrs, 'Lm-Remote-User => "dwho"' );
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
#print STDERR Dumper($res);
|
2016-04-05 13:12:53 +02:00
|
|
|
|
2016-04-05 22:46:11 +02:00
|
|
|
clean_sessions();
|
2016-04-04 22:39:22 +02:00
|
|
|
|
2016-04-03 18:27:13 +02:00
|
|
|
done_testing( count() );
|