2016-05-25 21:30:43 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
2019-09-13 23:23:21 +02:00
|
|
|
use JSON;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_FORBIDDENIP PE_USERNOTFOUND);
|
2016-05-25 21:30:43 +02:00
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
my $res;
|
2019-09-13 23:23:21 +02:00
|
|
|
my $json;
|
2016-05-25 21:30:43 +02:00
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2016-11-14 13:34:46 +01:00
|
|
|
ini => {
|
2019-09-13 23:23:21 +02:00
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
2019-09-14 22:59:44 +02:00
|
|
|
securedCookie => 3,
|
2019-09-13 23:23:21 +02:00
|
|
|
authentication => 'Slave',
|
|
|
|
userDB => 'Same',
|
|
|
|
slaveUserHeader => 'My-Test',
|
|
|
|
slaveHeaderName => 'Check-Slave',
|
|
|
|
slaveHeaderContent => 'Password',
|
|
|
|
slaveMasterIP => '127.0.0.1',
|
|
|
|
slaveExportedVars => {
|
2016-11-14 13:34:46 +01:00
|
|
|
name => 'Name',
|
|
|
|
}
|
2016-05-25 21:30:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-09-13 23:23:21 +02:00
|
|
|
# Bad password
|
2016-05-25 21:30:43 +02:00
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_get(
|
2019-09-13 23:23:21 +02:00
|
|
|
'/',
|
2019-09-14 22:59:44 +02:00
|
|
|
ip => '127.0.0.1',
|
|
|
|
custom => {
|
|
|
|
HTTP_MY_TEST => 'dwho',
|
|
|
|
HTTP_NAME => 'Dr Who',
|
|
|
|
HTTP_CHECK_SLAVE => 'Passwor',
|
2019-09-13 23:23:21 +02:00
|
|
|
}
|
2019-09-14 22:59:44 +02:00
|
|
|
|
2019-09-13 23:23:21 +02:00
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 401, 'Get 401' ) or explain( $res->[0], 401 );
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok( $json->{error} == PE_FORBIDDENIP, 'Response is PE_FORBIDDENIP' )
|
|
|
|
or explain( $json, "error => 75" );
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
# Good credentials with forbidden IP
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
ip => '127.0.0.2',
|
|
|
|
custom => {
|
|
|
|
HTTP_MY_TEST => 'dwho',
|
|
|
|
HTTP_NAME => 'Dr Who',
|
|
|
|
HTTP_CHECK_SLAVE => 'Password',
|
|
|
|
}
|
|
|
|
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 401, 'Get 401' ) or explain( $res->[0], 401 );
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok( $json->{error} == PE_FORBIDDENIP, 'Response is PE_FORBIDDENIP' )
|
|
|
|
or explain( $json, "error => 75" );
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
# Good credentials without slaveUserHeader
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
ip => '127.0.0.1',
|
|
|
|
custom => {
|
|
|
|
HTTP_MY_TES => 'dwho',
|
|
|
|
HTTP_NAME => 'Dr Who',
|
|
|
|
HTTP_CHECK_SLAVE => 'Password',
|
|
|
|
}
|
|
|
|
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 401, 'Get 401' ) or explain( $res->[0], 401 );
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok( $json->{error} == PE_USERNOTFOUND, 'Response is PE_USERNOTFOUND' )
|
|
|
|
or explain( $json, "error => 4" );
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
# Good credentials with acredited IP
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
ip => '127.0.0.1',
|
|
|
|
custom => {
|
|
|
|
HTTP_MY_TEST => 'dwho',
|
|
|
|
HTTP_NAME => 'Dr Who',
|
|
|
|
HTTP_CHECK_SLAVE => 'Password',
|
|
|
|
}
|
|
|
|
|
2016-05-25 21:30:43 +02:00
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
2019-09-14 22:59:44 +02:00
|
|
|
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
my $id_http = expectCookie( $res, 'lemonldaphttp' );
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok( $json->{id} eq "$id", 'Session id found' )
|
|
|
|
or explain( $json, "id => session_id" );
|
|
|
|
ok( $json->{id_http} eq "$id_http", 'httpSession id found' )
|
|
|
|
or explain( $json, "id_http => http_session_id" );
|
|
|
|
count(3);
|
|
|
|
|
2016-05-25 21:30:43 +02:00
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|