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;
|
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2016-11-14 13:34:46 +01:00
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
passwordDB => 'Demo',
|
|
|
|
portalRequireOldPassword => 1,
|
2018-11-07 22:27:58 +01:00
|
|
|
showLanguages => 0,
|
2019-02-09 23:05:51 +01:00
|
|
|
error_de_85 => 'From lemonlap-ng.ini',
|
2016-11-14 13:34:46 +01:00
|
|
|
}
|
2016-07-11 23:02:32 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-11-07 22:27:58 +01:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu' );
|
|
|
|
ok( $res->[2]->[0] !~ m%<span id="languages"></span>%,
|
|
|
|
' No language icon found' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-03-07 18:22:16 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%"trOver"%, ' trOver found' )
|
2019-02-09 23:05:51 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-03-07 18:22:16 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%"all":\{\}%, ' all found' )
|
2019-02-09 23:05:51 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-03-07 18:22:16 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%"PE85":"From lemonlap-ng.ini"%, ' PE85 found' )
|
2019-02-09 23:05:51 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-03-19 17:39:13 +01:00
|
|
|
count(5);
|
2019-02-20 23:22:56 +01:00
|
|
|
|
2019-03-19 15:38:36 +01:00
|
|
|
# Try to authenticate
|
2019-03-07 15:23:57 +01:00
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho*&password=dwho'),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => 24
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2019-03-07 18:22:16 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<span trmsg="40"></span>%, ' PE40 found' )
|
2019-03-07 15:23:57 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
|
2019-03-19 15:38:36 +01:00
|
|
|
# Try to authenticate
|
2016-07-11 23:02:32 +02:00
|
|
|
# -------------------
|
|
|
|
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() );
|