WIP - Append AuthBasic hanlder unit test

This commit is contained in:
Christophe Maudoux 2019-09-29 13:43:35 +02:00
parent 8fbbf89d5c
commit 7534692a87
2 changed files with 69 additions and 0 deletions

View File

@ -78,6 +78,7 @@ t/66-Lemonldap-NG-Handler-PSGI-wildcard.t
t/67-Lemonldap-NG-Handler-PSGI-vhostoptions.t
t/68-Lemonldap-NG-Handler-PSGI-Zimbra.t
t/69-Lemonldap-NG-Handler-PSGI-SecureToken.t
t/70-Lemonldap-NG-Handler-PSGI-AuthBasic.t
t/99-pod.t
t/lmConf-1.json
t/sessions/lock/Apache-Session-f5eec18ebb9bc96352595e2d8ce962e8ecf7af7c9a98cb9a43f9cd181cf4b545.lock

View File

@ -0,0 +1,68 @@
use Test::More;
use MIME::Base64;
BEGIN {
require 't/test-psgi-lib.pm';
}
my $maintests = 3;
init(
'Lemonldap::NG::Handler::Server',
{
# authentication => 'Demo',
# userDB => 'Same',
# restSessionServer => 1,
logLevel => 'error',
vhostOptions => {
'test1.example.com' => {
vhostHttps => 0,
vhostPort => 80,
vhostMaintenance => 0,
vhostServiceTokenTTL => -1,
},
},
exportedHeaders => {
'test1.example.com' => {
'Auth-User' => '$uid',
},
}
}
);
ok(
$res = $client->_get(
'/', undef, 'test1.example.com', undef, VHOSTTYPE => 'AuthBasic',
),
'Query'
);
ok( $res->[0] == 401, 'Code is 401' ) or explain( $res->[0], 302 );
# Check headers
%h = @{ $res->[1] };
ok(
$h{'WWW-Authenticate'} =~ m%^Basic realm="LemonLDAP::NG"$%,
'Header WWW-Authenticate is set to Basic realm="LemonLDAP::NG"'
) or explain( \%h, 'WWW-Authenticate => realm' );
# my $login = encode_base64("dwho:dwho");
# ok(
# $res = $client->_get(
# '/', undef, 'test1.example.com', undef,
# VHOSTTYPE => 'AuthBasic',
# HTTP_X_FORWARDED_FOR => '127.0.0.1',
# HTTP_AUTHORIZATION => "Basic $login"
# ),
# 'AuthBasic query'
# );
#
# print STDERR Data::Dumper::Dumper($res);
#
# # Check headers
# %h = @{ $res->[1] };
# ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
# or explain( \%h, 'Auth-User => "dwho"' );
count($maintests);
done_testing( count() );
clean();