Commit 0385422d authored by Xavier Guimard's avatar Xavier Guimard

Improve #1700 test

parent 577d4d04
......@@ -530,7 +530,6 @@ t/76-2F-Ext-with-History.t
t/77-2F-Mail.t
t/90-Translations.t
t/99-pod.t
t/auth-basic.pm
t/gpghome/key.asc
t/gpghome/openpgp-revocs.d/9482CEFB055809CBAFE6D71AAB2D5542891D1677.rev
t/gpghome/private-keys-v1.d/A076B0E7DB141A919271EE8B581CDFA8DA42F333.key
......@@ -545,6 +544,7 @@ t/README.md
t/saml-lib.pm
t/sendCode.pl
t/sendOTP.pl
t/separate-handler.pm
t/sessions/lock/.exists
t/sessions/saml/lock/.exists
t/sessions2/6e30af4ffa5689b3e49a104d1b160d316db2b2161a0f45776994eed19dbdc101
......
......@@ -2,13 +2,14 @@ use lib 'inc';
use strict;
use IO::String;
use JSON;
use MIME::Base64;
use Test::More;
our $debug = 'error';
my ( $p, $res, $spId );
$| = 1;
require 't/auth-basic.pm';
require 't/separate-handler.pm';
require "t/test-lib.pm";
......@@ -23,59 +24,70 @@ ok( getHeader( $res, 'WWW-Authenticate' ) eq 'Basic realm="LemonLDAP::NG"',
count(2);
my $subtest = 0;
ok(
$res = handler(
req => [
GET => 'http://test2.example.com/',
[ 'Authorization' => 'Basic ZHdobzpkd2hv' ]
],
sub => sub {
my ($res) = @_;
$subtest++;
subtest 'REST request to Portal' => sub {
plan tests => 3;
ok( $res->[0] eq 'POST', 'Get POST request' );
my ( $url, $query ) = split /\?/, $res->[1];
ok(
$res = $p->_post(
$url, IO::String->new( $res->[3] ),
length => length( $res->[3] ),
query => $query,
),
'Push request to portal'
);
ok( $res->[0] == 200, 'Response is 200' );
foreach my $user (qw(dwho rtyler)) {
ok(
$res = handler(
req => [
GET => 'http://test2.example.com/',
[
'Authorization' => 'Basic '
. encode_base64( "$user:$user", '' )
]
],
sub => sub {
my ($res) = @_;
$subtest++;
subtest 'REST request to Portal' => sub {
plan tests => 3;
ok( $res->[0] eq 'POST', 'Get POST request' );
my ( $url, $query ) = split /\?/, $res->[1];
ok(
$res = $p->_post(
$url, IO::String->new( $res->[3] ),
length => length( $res->[3] ),
query => $query,
),
'Push request to portal'
);
ok( $res->[0] == 200, 'Response is 200' );
return $res;
};
count(1);
return $res;
};
count(1);
return $res;
},
),
'AuthBasic request'
);
ok( $subtest == 1, 'REST request was done by handler' );
count(2);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
},
),
'AuthBasic request'
);
count(1);
expectOK($res);
expectAuthenticatedAs( $res, $user );
}
ok( $subtest == 2, 'REST requests were done by handler' );
count(1);
ok(
$res = handler(
req => [
GET => 'http://test2.example.com/',
[ 'Authorization' => 'Basic ZHdobzpkd2hv' ]
],
sub => sub {
$subtest++;
fail "Cache didn't work";
return [ 500, [], [] ];
},
),
'New AuthBasic request'
);
ok( $subtest == 1, 'Handler used its local cache' );
count(2);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
foreach my $user (qw(dwho rtyler)) {
ok(
$res = handler(
req => [
GET => 'http://test2.example.com/',
[
'Authorization' => 'Basic '
. encode_base64( "$user:$user", '' )
]
],
sub => sub {
$subtest++;
fail "Cache didn't work";
return [ 500, [], [] ];
},
),
'New AuthBasic request'
);
ok( $subtest == 2, 'Handler used its local cache' );
count(2);
expectOK($res);
expectAuthenticatedAs( $res, $user );
}
end_handler();
clean_sessions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment