From 7534692a874d9ee3da6fdfcd113ddc70f1b48804 Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Sun, 29 Sep 2019 13:43:35 +0200 Subject: [PATCH] WIP - Append AuthBasic hanlder unit test --- lemonldap-ng-handler/MANIFEST | 1 + .../70-Lemonldap-NG-Handler-PSGI-AuthBasic.t | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 lemonldap-ng-handler/t/70-Lemonldap-NG-Handler-PSGI-AuthBasic.t diff --git a/lemonldap-ng-handler/MANIFEST b/lemonldap-ng-handler/MANIFEST index 2b22803ce..76fd69c62 100644 --- a/lemonldap-ng-handler/MANIFEST +++ b/lemonldap-ng-handler/MANIFEST @@ -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 diff --git a/lemonldap-ng-handler/t/70-Lemonldap-NG-Handler-PSGI-AuthBasic.t b/lemonldap-ng-handler/t/70-Lemonldap-NG-Handler-PSGI-AuthBasic.t new file mode 100644 index 000000000..eee772101 --- /dev/null +++ b/lemonldap-ng-handler/t/70-Lemonldap-NG-Handler-PSGI-AuthBasic.t @@ -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();