2016-07-11 23:02:32 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use JSON;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants
|
|
|
|
qw(PE_BADOLDPASSWORD PE_PASSWORD_MISMATCH PE_PP_MUST_SUPPLY_OLD_PASSWORD);
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
my $res;
|
|
|
|
|
2016-11-14 13:34:46 +01:00
|
|
|
my $client = LLNG::Manager::Test->new(
|
2016-07-11 23:02:32 +02:00
|
|
|
{
|
2016-11-14 13:34:46 +01:00
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
passwordDB => 'Demo',
|
|
|
|
portalRequireOldPassword => 1,
|
|
|
|
}
|
2016-07-11 23:02:32 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Try yo authenticate
|
|
|
|
# -------------------
|
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-11 23:02:32 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
|
|
|
my $id = expectCookie($res);
|
2016-07-11 23:02:32 +02:00
|
|
|
|
|
|
|
# Test mismatch pwd
|
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-11 23:02:32 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('oldpassword=dwho&newpassword=test&confirmpassword=t'),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'application/json',
|
|
|
|
length => 51
|
|
|
|
),
|
|
|
|
'Password mismatch'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
expectBadRequest($res);
|
2016-07-11 23:02:32 +02:00
|
|
|
my $json;
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok( $json->{error} == PE_PASSWORD_MISMATCH, 'Response is PE_PASSWORD_MISMATCH' )
|
|
|
|
or explain( $json, "error => 34" );
|
2016-12-23 07:41:03 +01:00
|
|
|
count(3);
|
2016-07-11 23:02:32 +02:00
|
|
|
|
|
|
|
# Test missing old pwd
|
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-11 23:02:32 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('newpassword=test&confirmpassword=test'),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'application/json',
|
|
|
|
length => 37
|
|
|
|
),
|
|
|
|
'Missing old password'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
expectBadRequest($res);
|
2016-07-11 23:02:32 +02:00
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok(
|
|
|
|
$json->{error} == PE_PP_MUST_SUPPLY_OLD_PASSWORD,
|
|
|
|
'Response is PE_PP_MUST_SUPPLY_OLD_PASSWORD'
|
|
|
|
) or explain( $json, "error => 27" );
|
2016-12-23 07:41:03 +01:00
|
|
|
count(3);
|
2016-07-11 23:02:32 +02:00
|
|
|
|
|
|
|
# Test bad old pwd
|
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-11 23:02:32 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('oldpassword=dd&newpassword=test&confirmpassword=test'),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'application/json',
|
|
|
|
length => 52
|
|
|
|
),
|
|
|
|
'Bad old password'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
expectBadRequest($res);
|
2016-07-11 23:02:32 +02:00
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
|
|
|
or print STDERR "$@\n" . Dumper($res);
|
|
|
|
ok( $json->{error} == PE_BADOLDPASSWORD, 'Response is PE_BADOLDPASSWORD' )
|
|
|
|
or explain( $json, "error => 27" );
|
2016-12-23 07:41:03 +01:00
|
|
|
count(3);
|
2016-07-11 23:02:32 +02:00
|
|
|
|
2016-11-14 13:34:46 +01:00
|
|
|
# Test $client->logout
|
|
|
|
$client->logout($id);
|
2016-07-11 23:02:32 +02:00
|
|
|
|
|
|
|
#print STDERR Dumper($res);
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|