Improve unit tests & Fix regex (#2509)
This commit is contained in:
parent
8695a633a7
commit
b54c95ccd2
|
@ -176,7 +176,7 @@ sub checkPasswordQuality {
|
||||||
## Min special characters
|
## Min special characters
|
||||||
# Just number of special characters must be checked
|
# Just number of special characters must be checked
|
||||||
if ( $self->conf->{passwordPolicyMinSpeChar} && $speChars eq '__ALL__' ) {
|
if ( $self->conf->{passwordPolicyMinSpeChar} && $speChars eq '__ALL__' ) {
|
||||||
my $spe = $password =~ s/\w//g;
|
my $spe = $password =~ s/\W//g;
|
||||||
if ( $spe < $self->conf->{passwordPolicyMinSpeChar} ) {
|
if ( $spe < $self->conf->{passwordPolicyMinSpeChar} ) {
|
||||||
$self->logger->error("Password has not enough special characters");
|
$self->logger->error("Password has not enough special characters");
|
||||||
return PE_PP_INSUFFICIENT_PASSWORD_QUALITY;
|
return PE_PP_INSUFFICIENT_PASSWORD_QUALITY;
|
||||||
|
|
|
@ -9,7 +9,7 @@ use Lemonldap::NG::Portal::Main::Constants qw(
|
||||||
|
|
||||||
require 't/test-lib.pm';
|
require 't/test-lib.pm';
|
||||||
|
|
||||||
my $res;
|
my ($res, $json);
|
||||||
|
|
||||||
my $client = LLNG::Manager::Test->new( {
|
my $client = LLNG::Manager::Test->new( {
|
||||||
ini => {
|
ini => {
|
||||||
|
@ -56,7 +56,7 @@ ok(
|
||||||
'Password min size not respected'
|
'Password min size not respected'
|
||||||
);
|
);
|
||||||
expectBadRequest($res);
|
expectBadRequest($res);
|
||||||
my $json;
|
|
||||||
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
||||||
or print STDERR "$@\n" . Dumper($res);
|
or print STDERR "$@\n" . Dumper($res);
|
||||||
ok(
|
ok(
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
use IO::String;
|
||||||
|
use JSON;
|
||||||
|
use Lemonldap::NG::Portal::Main::Constants
|
||||||
|
'PE_PP_INSUFFICIENT_PASSWORD_QUALITY';
|
||||||
|
|
||||||
|
require 't/test-lib.pm';
|
||||||
|
|
||||||
|
my ( $res, $json );
|
||||||
|
|
||||||
|
my $client = LLNG::Manager::Test->new( {
|
||||||
|
ini => {
|
||||||
|
logLevel => 'error',
|
||||||
|
passwordDB => 'Demo',
|
||||||
|
portalRequireOldPassword => 1,
|
||||||
|
passwordPolicyMinSize => 0,
|
||||||
|
passwordPolicyMinLower => 0,
|
||||||
|
passwordPolicyMinUpper => 0,
|
||||||
|
passwordPolicyMinDigit => 0,
|
||||||
|
passwordPolicyMinSpeChar => 2,
|
||||||
|
passwordPolicySpecialChar => '__ALL__',
|
||||||
|
portalDisplayPasswordPolicy => 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
# Try to authenticate
|
||||||
|
# -------------------
|
||||||
|
ok(
|
||||||
|
$res = $client->_post(
|
||||||
|
'/',
|
||||||
|
IO::String->new('user=dwho&password=dwho'),
|
||||||
|
length => 23
|
||||||
|
),
|
||||||
|
'Auth query'
|
||||||
|
);
|
||||||
|
count(1);
|
||||||
|
expectOK($res);
|
||||||
|
my $id = expectCookie($res);
|
||||||
|
|
||||||
|
ok(
|
||||||
|
$res =
|
||||||
|
$client->_get( '/', cookie => "lemonldap=$id", accept => 'text/html' ),
|
||||||
|
'Get Menu'
|
||||||
|
);
|
||||||
|
ok( $res->[2]->[0] =~ m%<input id="oldpassword" name="oldpassword"%,
|
||||||
|
' Old password input' )
|
||||||
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
|
ok(
|
||||||
|
$res->[2]->[0] =~
|
||||||
|
m%<span trspan="passwordPolicyMinSpeChar">Minimal special characters:</span> 2%,
|
||||||
|
' passwordPolicyMinSpeChar'
|
||||||
|
) or print STDERR Dumper( $res->[2]->[0] );
|
||||||
|
count(3);
|
||||||
|
|
||||||
|
my $query = 'oldpassword=dwho&newpassword=@test&confirmpassword=@test';
|
||||||
|
ok(
|
||||||
|
$res = $client->_post(
|
||||||
|
'/',
|
||||||
|
IO::String->new($query),
|
||||||
|
cookie => "lemonldap=$id",
|
||||||
|
accept => 'application/json',
|
||||||
|
length => length($query)
|
||||||
|
),
|
||||||
|
'Password min special char policy not respected'
|
||||||
|
);
|
||||||
|
expectBadRequest($res);
|
||||||
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
||||||
|
or print STDERR "$@\n" . Dumper($res);
|
||||||
|
ok(
|
||||||
|
$json->{error} == PE_PP_INSUFFICIENT_PASSWORD_QUALITY,
|
||||||
|
'Response is PE_PP_INSUFFICIENT_PASSWORD_QUALITY'
|
||||||
|
) or explain( $json, "error => 28" );
|
||||||
|
count(3);
|
||||||
|
|
||||||
|
$query = 'oldpassword=dwho&newpassword=@%&confirmpassword=@%';
|
||||||
|
ok(
|
||||||
|
$res = $client->_post(
|
||||||
|
'/',
|
||||||
|
IO::String->new($query),
|
||||||
|
cookie => "lemonldap=$id",
|
||||||
|
accept => 'application/json',
|
||||||
|
length => length($query)
|
||||||
|
),
|
||||||
|
'Password min special char respected'
|
||||||
|
);
|
||||||
|
expectOK($res);
|
||||||
|
count(1);
|
||||||
|
|
||||||
|
# Test $client->logout
|
||||||
|
$client->logout($id);
|
||||||
|
|
||||||
|
clean_sessions();
|
||||||
|
|
||||||
|
done_testing( count() );
|
|
@ -19,8 +19,8 @@ my $client = LLNG::Manager::Test->new( {
|
||||||
passwordPolicyMinLower => 0,
|
passwordPolicyMinLower => 0,
|
||||||
passwordPolicyMinUpper => 0,
|
passwordPolicyMinUpper => 0,
|
||||||
passwordPolicyMinDigit => 0,
|
passwordPolicyMinDigit => 0,
|
||||||
passwordPolicyMinSpeChar => 2,
|
passwordPolicyMinSpeChar => 0,
|
||||||
passwordPolicySpecialChar => '',
|
passwordPolicySpecialChar => '__ALL__',
|
||||||
portalDisplayPasswordPolicy => 1
|
portalDisplayPasswordPolicy => 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ ok(
|
||||||
ok( $res->[2]->[0] =~ m%<input id="oldpassword" name="oldpassword"%,
|
ok( $res->[2]->[0] =~ m%<input id="oldpassword" name="oldpassword"%,
|
||||||
' Old password input' )
|
' Old password input' )
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyMinSpeChar">Minimal special characters:</span> 2%,
|
ok( $res->[2]->[0] =~ m%<span trspan="passwordPolicyNone">%,
|
||||||
' passwordPolicyMinSpeChar' )
|
' passwordPolicyNone' )
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
count(3);
|
count(3);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user