2016-02-01 23:22:33 +01:00
|
|
|
#!/usr/bin/env perl -I pl/lib
|
|
|
|
|
|
|
|
use Test::More;
|
|
|
|
use JSON;
|
|
|
|
use Data::Dumper;
|
|
|
|
use MIME::Base64;
|
|
|
|
|
|
|
|
require 't/test-psgi-lib.pm';
|
|
|
|
|
2017-02-11 08:47:22 +01:00
|
|
|
init('Lemonldap::NG::Handler::Server::Nginx');
|
2016-02-01 23:22:33 +01:00
|
|
|
|
|
|
|
my $res;
|
|
|
|
|
|
|
|
# Unauthentified query
|
|
|
|
ok( $res = $client->_get('/'), 'Unauthentified query' );
|
|
|
|
ok( ref($res) eq 'ARRAY', 'Response is an array' ) or explain( $res, 'array' );
|
|
|
|
ok( $res->[0] == 401, 'Code is 401' ) or explain( $res->[0], 401 );
|
|
|
|
my %h = @{ $res->[1] };
|
|
|
|
ok(
|
|
|
|
$h{Location} eq 'http://auth.example.com/?url='
|
|
|
|
. encode_base64( 'http://test1.example.com/', '' ),
|
|
|
|
'Redirection points to portal'
|
|
|
|
)
|
|
|
|
or explain(
|
|
|
|
\%h,
|
|
|
|
'Location => http://auth.example.com/?url='
|
|
|
|
. encode_base64( 'http://test1.example.com/', '' )
|
|
|
|
);
|
|
|
|
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
# Authentified queries
|
|
|
|
# --------------------
|
|
|
|
|
|
|
|
# Authorizated query
|
2016-06-09 13:45:10 +02:00
|
|
|
ok( $res = $client->_get( '/', undef, undef, "lemonldap=$sessionId" ),
|
|
|
|
'Authentified query' );
|
2016-02-01 23:22:33 +01:00
|
|
|
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
|
|
|
|
|
|
|
|
count(2);
|
|
|
|
|
|
|
|
# Check headers
|
|
|
|
%h = @{ $res->[1] };
|
2016-02-17 11:12:19 +01:00
|
|
|
ok( $h{'Headername1'} eq 'Auth-User', 'Headername1 is set to "Auth-User"' )
|
2016-04-04 22:39:22 +02:00
|
|
|
or explain( \%h, 'Headername1 => "Auth-User"' );
|
2016-02-17 11:12:19 +01:00
|
|
|
ok( $h{'Headervalue1'} eq 'dwho', 'Headervalue1 is set to "dwho"' )
|
2016-04-04 22:39:22 +02:00
|
|
|
or explain( \%h, 'Headervalue1 => "dwho"' );
|
2016-02-01 23:22:33 +01:00
|
|
|
count(2);
|
|
|
|
|
|
|
|
# Denied query
|
2016-06-09 13:45:10 +02:00
|
|
|
ok( $res = $client->_get( '/deny', undef, undef, "lemonldap=$sessionId" ),
|
|
|
|
'Denied query' );
|
2016-02-01 23:22:33 +01:00
|
|
|
ok( $res->[0] == 403, 'Code is 403' ) or explain( $res->[0], 403 );
|
|
|
|
|
|
|
|
count(2);
|
|
|
|
|
|
|
|
# Bad cookie
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/deny',
|
|
|
|
undef,
|
|
|
|
'manager.example.com',
|
|
|
|
'lemonldap=e5eec18ebb9bc96352595e2d8ce962e8ecf7af7c9a98cb9a43f9cd181cf4b545'
|
|
|
|
),
|
|
|
|
'Bad cookie'
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 401, 'Code is 401' ) or explain( $res->[0], 401 );
|
2016-02-17 11:12:19 +01:00
|
|
|
unlink(
|
|
|
|
't/sessions/lock/Apache-Session-e5eec18ebb9bc96352595e2d8ce962e8ecf7af7c9a98cb9a43f9cd181cf4b545.lock'
|
|
|
|
);
|
2016-02-01 23:22:33 +01:00
|
|
|
|
|
|
|
count(2);
|
|
|
|
|
|
|
|
done_testing( count() );
|
|
|
|
|
2016-06-09 13:45:10 +02:00
|
|
|
clean();
|