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-05-23 18:55:20 +02:00
|
|
|
init( { logLevel => 'error', useSafeJail => 1 } );
|
2016-04-05 07:23:42 +02:00
|
|
|
|
2016-04-08 06:40:41 +02:00
|
|
|
# Test normal first access
|
|
|
|
# ------------------------
|
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-08 06:40:41 +02:00
|
|
|
# Test "first access" with good url
|
2016-05-30 22:20:50 +02:00
|
|
|
ok(
|
|
|
|
$res =
|
|
|
|
&client->_get( '/', query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==' ),
|
|
|
|
'Unauth ajax request with good url'
|
|
|
|
);
|
2016-04-05 13:12:53 +02:00
|
|
|
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
|
|
|
|
count(2);
|
|
|
|
|
2016-04-08 06:40:41 +02:00
|
|
|
# Try yo authenticate
|
|
|
|
# -------------------
|
2016-04-04 20:05:22 +02:00
|
|
|
ok(
|
2016-04-04 22:39:22 +02:00
|
|
|
$res = &client->_post(
|
2016-05-30 22:20:50 +02:00
|
|
|
'/',
|
2016-04-04 20:05:22 +02:00
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
2016-05-30 22:20:50 +02:00
|
|
|
length => 23
|
2016-04-04 20:05:22 +02:00
|
|
|
),
|
2016-04-04 22:39:22 +02:00
|
|
|
'Auth query'
|
|
|
|
);
|
2016-04-14 13:15:51 +02:00
|
|
|
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
|
2016-04-05 07:23:42 +02:00
|
|
|
my $cookies = getCookies($res);
|
|
|
|
my $id;
|
2016-04-14 13:15:51 +02:00
|
|
|
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
|
|
|
|
or explain( $res, 'Set-Cookie: something' );
|
2016-04-14 20:42:59 +02:00
|
|
|
count(3);
|
2016-04-03 18:27:13 +02:00
|
|
|
|
2016-04-08 06:40:41 +02:00
|
|
|
# Try to get a redirection for an auth user with a valid url
|
|
|
|
# ----------------------------------------------------------
|
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-14 13:15:51 +02:00
|
|
|
ok( $res->[0] == 302, 'Get redirection' )
|
|
|
|
or explain( [ $res->[0], $res->[1] ], 302 );
|
2016-04-05 22:46:11 +02:00
|
|
|
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);
|
|
|
|
|
2016-04-08 06:40:41 +02:00
|
|
|
# Try to get a redirection for an auth user with a bad url (host undeclared
|
|
|
|
# in manager)
|
|
|
|
# -------------------------------------------------------------------------
|
2016-04-06 22:10:03 +02:00
|
|
|
ok(
|
|
|
|
$res = &client->_get(
|
|
|
|
'/',
|
|
|
|
query => 'url=aHR0cHM6Ly90LmV4YW1wbGUuY29tLw==',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Auth request with bad url'
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 200, 'HTTP code is 200' ) or explain( $res, 200 );
|
2016-05-25 21:30:43 +02:00
|
|
|
%hdrs = @{ $res->[1] };
|
2016-04-06 22:10:03 +02:00
|
|
|
ok( $hdrs{'Lm-Remote-User'} eq 'dwho', 'User is set' )
|
|
|
|
or explain( \%hdrs, 'Lm-Remote-User => "dwho"' );
|
|
|
|
ok( $hdrs{'Content-Type'} eq 'text/html', 'Reponse is HTML' )
|
|
|
|
or explain( \%hdrs, 'Content-Type => "text/html"' );
|
|
|
|
count(4);
|
2016-04-06 07:16:47 +02:00
|
|
|
|
2016-05-22 19:06:55 +02:00
|
|
|
# Test logout
|
|
|
|
logout($id);
|
|
|
|
|
2016-04-05 22:46:11 +02:00
|
|
|
#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() );
|