lemonldap-ng/lemonldap-ng-portal/t/01-AuthDemo.t

93 lines
2.1 KiB
Perl
Raw Normal View History

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-11-14 13:34:46 +01:00
my $client = LLNG::Manager::Test->new(
{ ini => { 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-11-14 13:34:46 +01:00
ok( $res = $client->_get('/'), 'Unauth JSON request' );
2016-12-23 07:41:03 +01:00
count(1);
expectReject($res);
2016-04-04 07:08:26 +02:00
2016-04-08 06:40:41 +02:00
# Test "first access" with good url
2016-05-30 22:20:50 +02:00
ok(
$res =
2016-11-14 13:34:46 +01:00
$client->_get( '/', query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==' ),
2016-05-30 22:20:50 +02:00
'Unauth ajax request with good url'
);
2016-12-23 07:41:03 +01:00
count(1);
expectReject($res);
2018-11-07 22:27:58 +01:00
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu' );
ok( $res->[2]->[0] =~ m%<span id="languages"></span>%,
' Language icons found' )
or print STDERR Dumper( $res->[2]->[0] );
count(2);
2016-12-14 09:49:30 +01:00
# Try to authenticate
2016-04-08 06:40:41 +02:00
# -------------------
2016-04-04 20:05:22 +02:00
ok(
2016-11-14 13:34:46 +01: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'),
2018-11-07 22:27:58 +01:00
length => 23,
2016-04-04 20:05:22 +02:00
),
2016-04-04 22:39:22 +02:00
'Auth query'
);
2016-12-23 07:41:03 +01:00
count(1);
expectOK($res);
my $id = expectCookie($res);
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
# ----------------------------------------------------------
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
accept => 'text/html'
),
'Auth ajax request with good url'
);
2016-12-23 07:41:03 +01:00
count(1);
expectRedirection( $res, 'http://test1.example.com/' );
expectAuthenticatedAs( $res, 'dwho' );
2016-04-05 22:46:11 +02:00
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(
2016-11-14 13:34:46 +01:00
$res = $client->_get(
2016-04-06 22:10:03 +02:00
'/',
query => 'url=aHR0cHM6Ly90LmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
accept => 'text/html'
),
'Auth request with bad url'
);
2016-12-23 07:41:03 +01:00
count(1);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
2016-04-06 07:16:47 +02:00
2017-03-04 09:07:41 +01:00
require 't/test-psgi.pm';
ok( $res = mirror( cookie => "lemonldap=$id" ), 'PSGI test' );
count(1);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
2016-05-22 19:06:55 +02:00
# Test logout
2016-11-14 13:34:46 +01:00
$client->logout($id);
2016-05-22 19:06:55 +02:00
2016-04-05 22:46:11 +02:00
#print STDERR Dumper($res);
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() );