2018-01-24 22:32:08 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
eval {
|
2018-10-03 22:01:32 +02:00
|
|
|
unlink 't/userdb.db';
|
2018-01-24 22:32:08 +01:00
|
|
|
require 't/test-lib.pm';
|
|
|
|
require 't/smtp.pm';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
my ( $res, $user, $pwd );
|
2018-11-16 22:02:43 +01:00
|
|
|
my $maintests = 17;
|
2018-01-24 22:32:08 +01:00
|
|
|
my $mailSend = 0;
|
|
|
|
|
|
|
|
my $mail2 = 0;
|
|
|
|
|
|
|
|
SKIP: {
|
|
|
|
eval
|
2018-11-26 14:40:21 +01:00
|
|
|
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
|
2018-01-24 22:32:08 +01:00
|
|
|
if ($@) {
|
|
|
|
skip 'Missing dependencies', $maintests;
|
|
|
|
}
|
|
|
|
eval { require DBI; require DBD::SQLite; };
|
|
|
|
if ($@) {
|
|
|
|
skip 'DBD::SQLite not found', $maintests;
|
|
|
|
}
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db");
|
|
|
|
$dbh->do(
|
|
|
|
'CREATE TABLE users (user text,password text,name text, mail text)');
|
|
|
|
$dbh->do(
|
2018-11-26 14:40:21 +01:00
|
|
|
"INSERT INTO users VALUES ('dwho','dwho','Doctor who','dwho\@badwolf.org')"
|
2018-01-24 22:32:08 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
my $client = LLNG::Manager::Test->new(
|
2018-11-26 14:40:21 +01:00
|
|
|
{
|
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
portalDisplayRegister => 1,
|
|
|
|
authentication => 'DBI',
|
|
|
|
userDB => 'Same',
|
|
|
|
passwordDB => 'DBI',
|
|
|
|
captcha_mail_enabled => 0,
|
|
|
|
portalDisplayResetPassword => 1,
|
|
|
|
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
|
|
|
|
dbiAuthUser => '',
|
|
|
|
dbiAuthPassword => '',
|
|
|
|
dbiAuthTable => 'users',
|
|
|
|
dbiAuthLoginCol => 'user',
|
|
|
|
dbiAuthPasswordCol => 'password',
|
|
|
|
dbiAuthPasswordHash => '',
|
|
|
|
dbiDynamicHashEnabled => 0,
|
|
|
|
dbiMailCol => 'mail',
|
2018-11-16 22:02:43 +01:00
|
|
|
passwordResetAllowedRetries => 4,
|
2018-01-24 22:32:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Test form
|
|
|
|
# ------------------------
|
|
|
|
ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ),
|
|
|
|
'Reset form', );
|
|
|
|
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'mail' );
|
|
|
|
|
|
|
|
$query = 'mail=dwho%40badwolf.org';
|
|
|
|
|
|
|
|
# Post email
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-01-24 22:32:08 +01:00
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post mail'
|
|
|
|
);
|
|
|
|
|
|
|
|
ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#,
|
|
|
|
'Found link in mail' );
|
|
|
|
$query = $1;
|
|
|
|
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2018-11-16 22:02:43 +01:00
|
|
|
'/resetpwd',
|
|
|
|
query => $query,
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
2018-01-24 22:32:08 +01:00
|
|
|
'Post mail token received by mail'
|
|
|
|
);
|
2018-11-16 22:02:43 +01:00
|
|
|
|
|
|
|
# Post mismatched passwords
|
2018-01-24 22:32:08 +01:00
|
|
|
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
2018-11-16 22:02:43 +01:00
|
|
|
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password #1' );
|
2018-01-24 22:32:08 +01:00
|
|
|
|
2018-11-16 22:02:43 +01:00
|
|
|
$query .= '&newpassword=zz&confirmpassword=z';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-11-16 22:02:43 +01:00
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post mismatched passwords'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trmsg="34"></span>%, 'PE_34 found' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-11-16 22:02:43 +01:00
|
|
|
|
|
|
|
# Post empty password 1
|
|
|
|
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
|
|
|
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password #2' );
|
|
|
|
|
|
|
|
$query .= '&newpassword=&confirmpassword=zz';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-11-16 22:02:43 +01:00
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post empty newpassword'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trmsg="67"></span>%, 'PE_67 found' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-11-16 22:02:43 +01:00
|
|
|
|
|
|
|
# Post empty password 2
|
|
|
|
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
|
|
|
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password #3' );
|
|
|
|
|
|
|
|
$query .= '&newpassword=zz&confirmpassword=';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-11-16 22:02:43 +01:00
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post empty confirmpassword'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trmsg="67"></span>%, 'PE_67 found' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-01-24 22:32:08 +01:00
|
|
|
|
|
|
|
# Post new password
|
2018-11-16 22:02:43 +01:00
|
|
|
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
|
|
|
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password #4' );
|
|
|
|
|
|
|
|
$query .= '&newpassword=zz&confirmpassword=zz';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-01-24 22:32:08 +01:00
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post new password'
|
|
|
|
);
|
|
|
|
|
|
|
|
ok( mail() =~ /Your password was changed/, 'Password was changed' );
|
|
|
|
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-11-13 11:30:45 +01:00
|
|
|
'/',
|
2018-11-15 21:16:58 +01:00
|
|
|
IO::String->new('user=dwho&password=zz'),
|
|
|
|
length => 21
|
2018-11-13 11:30:45 +01:00
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
|
|
|
|
$client->logout($id);
|
|
|
|
|
2018-01-24 22:32:08 +01:00
|
|
|
#print STDERR Dumper($query);
|
|
|
|
}
|
|
|
|
|
2018-01-25 15:53:52 +01:00
|
|
|
eval { unlink 't/userdb.db' };
|
|
|
|
count($maintests);
|
2018-01-24 22:32:08 +01:00
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|