2019-02-09 09:49:21 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
use lib 't/lib';
|
|
|
|
|
|
|
|
my $res;
|
2020-11-08 13:14:41 +01:00
|
|
|
my $maintests = 42;
|
2019-02-09 09:49:21 +01:00
|
|
|
|
|
|
|
SKIP: {
|
2019-02-11 16:19:35 +01:00
|
|
|
skip( 'LLNGTESTLDAP is not set', $maintests ) unless ( $ENV{LLNGTESTLDAP} );
|
2019-02-09 09:49:21 +01:00
|
|
|
require 't/test-ldap.pm';
|
|
|
|
|
2019-03-07 18:22:16 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2019-02-09 09:49:21 +01:00
|
|
|
ini => {
|
2019-02-12 12:00:49 +01:00
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
authentication => 'LDAP',
|
|
|
|
portal => 'http://auth.example.com/',
|
|
|
|
userDB => 'Same',
|
|
|
|
passwordDB => 'LDAP',
|
|
|
|
portalRequireOldPassword => 1,
|
|
|
|
ldapServer => 'ldap://127.0.0.1:19389/',
|
|
|
|
ldapBase => 'ou=users,dc=example,dc=com',
|
|
|
|
managerDn => 'cn=lemonldapng,ou=dsa,dc=example,dc=com',
|
|
|
|
managerPassword => 'lemonldapng',
|
2019-02-09 18:16:52 +01:00
|
|
|
ldapAllowResetExpiredPassword => 1,
|
2019-02-11 14:26:41 +01:00
|
|
|
ldapPpolicyControl => 1,
|
2020-08-29 18:02:19 +02:00
|
|
|
passwordPolicyMinSize => 4,
|
|
|
|
passwordPolicyMinLower => 1,
|
|
|
|
passwordPolicyMinUpper => 1,
|
|
|
|
passwordPolicyMinDigit => 1,
|
|
|
|
passwordPolicyMinSpeChar => 1,
|
2020-08-30 14:22:49 +02:00
|
|
|
passwordPolicySpecialChar => '__ALL__',
|
2020-11-08 13:14:41 +01:00
|
|
|
portalDisplayPasswordPolicy => 1,
|
|
|
|
whatToTrace => 'uid',
|
|
|
|
macros => {
|
|
|
|
_whatToTrace => '' # Test 2377
|
|
|
|
},
|
2019-02-09 09:49:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2020-11-08 13:14:41 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_PASSWORD_OK
|
|
|
|
PE_PP_ACCOUNT_LOCKED
|
|
|
|
PE_PP_PASSWORD_EXPIRED
|
|
|
|
PE_PP_CHANGE_AFTER_RESET
|
|
|
|
PE_PP_PASSWORD_TOO_SHORT PE_PP_GRACE
|
|
|
|
);
|
2019-02-12 08:59:29 +01:00
|
|
|
|
2019-04-11 11:58:21 +02:00
|
|
|
my ( $user, $code, $postString, $match );
|
|
|
|
|
2019-02-12 08:59:29 +01:00
|
|
|
# 1 - TEST PE_PP_CHANGE_AFTER_RESET AND PE_PP_PASSWORD_EXPIRED
|
|
|
|
# ------------------------------------------------------------
|
2019-02-11 16:03:37 +01:00
|
|
|
foreach my $tpl (
|
|
|
|
[ 'reset', PE_PP_CHANGE_AFTER_RESET ],
|
|
|
|
[ 'expire', PE_PP_PASSWORD_EXPIRED ]
|
|
|
|
)
|
|
|
|
{
|
2019-04-11 11:58:21 +02:00
|
|
|
$user = $tpl->[0];
|
|
|
|
$code = $tpl->[1];
|
|
|
|
$postString = "user=$user&password=$user";
|
2019-02-09 09:49:21 +01:00
|
|
|
|
2019-04-01 09:58:56 +02:00
|
|
|
# Try to authenticate
|
2019-02-11 16:03:37 +01:00
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($postString),
|
|
|
|
length => length($postString),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2019-04-11 11:58:21 +02:00
|
|
|
$match = 'trmsg="' . $code . '"';
|
2019-02-11 16:12:49 +01:00
|
|
|
ok( $res->[2]->[0] =~ /$match/, "Code is $code" );
|
2019-02-09 09:49:21 +01:00
|
|
|
|
2019-02-11 16:03:37 +01:00
|
|
|
#open F, '>../e2e-tests/conf/portal/result.html' or die $!;
|
|
|
|
#print F $res->[2]->[0];
|
|
|
|
#close F;
|
|
|
|
my ( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'user', 'oldpassword', 'newpassword',
|
|
|
|
'confirmpassword' );
|
2020-11-08 13:14:41 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input name="user" type="hidden" value="$user" />%,
|
|
|
|
' Hidden user input found'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0], 'Hidden user input' );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input id="oldpassword" name="oldpassword" type="password" value="$user"%,
|
|
|
|
' oldpassword input found'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0], 'oldpassword input' );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input id="staticUser" type="text" readonly class="form-control" value="$user" />%,
|
|
|
|
' staticUser found'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0], 'staticUser' );
|
2020-08-29 18:02:19 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyMinSize">%,
|
|
|
|
' passwordPolicyMinSize' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0], 'passwordPolicyMinSize' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyMinLower">%,
|
|
|
|
' passwordPolicyMinLower' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0], 'passwordPolicyMinLower' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyMinUpper">%,
|
|
|
|
' passwordPolicyMinUpper' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0], 'passwordPolicyMinUpper' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyMinDigit">%,
|
|
|
|
' passwordPolicyMinDigit' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0], 'passwordPolicyMinDigit' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyMinSpeChar">%,
|
|
|
|
' passwordPolicyMinSpeChar' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0], 'passwordPolicyMinSpeChar' );
|
2020-08-30 14:22:49 +02:00
|
|
|
ok( $res->[2]->[0] !~ m%<span trspan="passwordPolicySpecialChar">%,
|
2020-08-29 18:02:19 +02:00
|
|
|
' passwordPolicySpecialChar' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0], 'passwordPolicySpecialChar' );
|
2019-02-11 16:03:37 +01:00
|
|
|
ok( $query =~ /user=$user/, "User is $user" )
|
|
|
|
or explain( $query, "user=$user" );
|
2020-11-08 13:14:41 +01:00
|
|
|
|
|
|
|
#$query =~ s/(oldpassword)=/$1=$user/g; -> Now old password is defined #2377
|
2020-08-29 18:02:19 +02:00
|
|
|
$query =~ s/((?:confirm|new)password)=/$1=Newp1@/g;
|
2020-11-08 13:14:41 +01:00
|
|
|
|
2019-02-11 16:03:37 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Post new password'
|
|
|
|
);
|
2019-02-11 16:19:35 +01:00
|
|
|
$match = 'trmsg="' . PE_PASSWORD_OK . '"';
|
2019-02-11 16:03:37 +01:00
|
|
|
ok( $res->[2]->[0] =~ /$match/, 'Password is changed' );
|
2019-02-09 09:49:21 +01:00
|
|
|
|
2020-08-29 18:02:19 +02:00
|
|
|
$postString = "user=$user&password=Newp1@";
|
2019-02-11 16:03:37 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($postString),
|
|
|
|
length => length($postString),
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
expectCookie($res) or print STDERR Dumper($res);
|
|
|
|
}
|
2019-02-12 08:59:29 +01:00
|
|
|
|
2019-04-01 09:58:56 +02:00
|
|
|
# 2 - TEST PE_PP_GRACE
|
|
|
|
# -------------------------
|
2019-04-11 11:58:21 +02:00
|
|
|
$user = 'grace';
|
|
|
|
$code = "ppGrace";
|
|
|
|
$postString = "user=$user&password=$user";
|
2019-04-01 09:58:56 +02:00
|
|
|
|
|
|
|
# Try to authenticate
|
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($postString),
|
|
|
|
length => length($postString),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2020-03-10 10:34:19 +01:00
|
|
|
$match = 'trspan="' . $code . '"';
|
2019-04-01 09:58:56 +02:00
|
|
|
ok( $res->[2]->[0] =~ /$match/, 'Grace remaining' );
|
|
|
|
|
|
|
|
# 3 - TEST PE_PP_ACCOUNT_LOCKED
|
2019-02-12 08:59:29 +01:00
|
|
|
# -------------------------
|
2019-04-11 11:58:21 +02:00
|
|
|
$user = 'lock';
|
|
|
|
$code = PE_PP_ACCOUNT_LOCKED;
|
|
|
|
$postString = "user=$user&password=$user";
|
2019-02-11 16:12:49 +01:00
|
|
|
|
2019-04-01 09:58:56 +02:00
|
|
|
# Try to authenticate
|
2019-02-11 16:12:49 +01:00
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($postString),
|
|
|
|
length => length($postString),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2019-04-11 11:58:21 +02:00
|
|
|
$match = 'trmsg="' . $code . '"';
|
2019-02-11 16:12:49 +01:00
|
|
|
ok( $res->[2]->[0] =~ /$match/, 'Account is locked' );
|
|
|
|
|
|
|
|
# Try to change anyway
|
|
|
|
my $query =
|
|
|
|
'user=lock&oldpassword=lock&newpassword=newp&confirmpassword=newp';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Post new password'
|
|
|
|
);
|
2019-02-11 16:19:35 +01:00
|
|
|
$match = 'trmsg="' . PE_PASSWORD_OK . '"';
|
2019-02-11 16:12:49 +01:00
|
|
|
ok( $res->[2]->[0] !~ /$match/s, 'Password is not changed' );
|
|
|
|
|
2019-04-01 09:58:56 +02:00
|
|
|
# 4 - TEST PE_PP_PASSWORD_TOO_SHORT
|
2019-02-12 08:59:29 +01:00
|
|
|
# ---------------------------------
|
2019-02-12 12:00:49 +01:00
|
|
|
$user = 'short';
|
|
|
|
$code = PE_PP_PASSWORD_TOO_SHORT;
|
2019-02-12 08:59:29 +01:00
|
|
|
$postString = "user=$user&password=passwordnottooshort";
|
|
|
|
|
2019-04-01 09:58:56 +02:00
|
|
|
# Try to authenticate
|
2019-02-12 08:59:29 +01:00
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($postString),
|
|
|
|
length => length($postString),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
my $id = expectCookie($res);
|
2019-02-12 12:00:49 +01:00
|
|
|
$query =
|
2020-08-29 18:02:19 +02:00
|
|
|
'oldpassword=passwordnottooshort&newpassword=Te1@&confirmpassword=Te1@';
|
2019-02-12 08:59:29 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
2019-02-12 12:00:49 +01:00
|
|
|
IO::String->new($query),
|
2019-02-12 08:59:29 +01:00
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
2019-02-12 12:00:49 +01:00
|
|
|
length => length($query),
|
2019-02-12 08:59:29 +01:00
|
|
|
),
|
|
|
|
'Change password'
|
|
|
|
);
|
|
|
|
$match = 'trmsg="' . PE_PP_PASSWORD_TOO_SHORT . '"';
|
|
|
|
ok( $res->[2]->[0] =~ /$match/s, 'Password is not changed' );
|
2019-02-12 12:00:49 +01:00
|
|
|
|
2019-02-12 08:59:29 +01:00
|
|
|
# Verify that password isn't changed
|
|
|
|
$client->logout($id);
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/', IO::String->new($postString),
|
|
|
|
length => length($postString),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2019-02-12 12:00:49 +01:00
|
|
|
$id = expectCookie($res);
|
|
|
|
$query =
|
2020-08-29 18:02:19 +02:00
|
|
|
'oldpassword=passwordnottooshort&newpassword=Testmore1@&confirmpassword=Testmore1@';
|
2019-02-12 08:59:29 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
2019-02-12 12:00:49 +01:00
|
|
|
IO::String->new($query),
|
2019-02-12 08:59:29 +01:00
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
2019-02-12 12:00:49 +01:00
|
|
|
length => length($query),
|
2019-02-12 08:59:29 +01:00
|
|
|
),
|
|
|
|
'Change password'
|
|
|
|
);
|
|
|
|
$match = 'trmsg="' . PE_PASSWORD_OK . '"';
|
2019-02-12 12:00:49 +01:00
|
|
|
ok( $res->[2]->[0] =~ /$match/s, 'Password is changed' );
|
2019-02-09 09:49:21 +01:00
|
|
|
}
|
2019-02-11 16:19:35 +01:00
|
|
|
count($maintests);
|
2019-02-09 09:49:21 +01:00
|
|
|
clean_sessions();
|
|
|
|
stopLdapServer() if $ENV{LLNGTESTLDAP};
|
|
|
|
done_testing( count() );
|