2017-01-30 06:54:30 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
BEGIN {
|
2017-04-13 22:08:55 +02:00
|
|
|
eval {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
require 't/smtp.pm';
|
|
|
|
};
|
2017-01-30 06:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my ( $res, $host, $url, $query );
|
2017-03-27 07:22:08 +02:00
|
|
|
my $maintests = 10;
|
2017-01-30 06:54:30 +01:00
|
|
|
my $mailSend = 0;
|
|
|
|
my $mail2 = 0;
|
|
|
|
|
|
|
|
SKIP: {
|
2017-04-13 22:08:55 +02:00
|
|
|
eval
|
|
|
|
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
|
2017-01-30 06:54:30 +01:00
|
|
|
if ($@) {
|
2017-04-13 22:08:55 +02:00
|
|
|
skip 'Missing dependencies', $maintests;
|
2017-01-30 06:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my $client = LLNG::Manager::Test->new(
|
|
|
|
{
|
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
portalDisplayRegister => 1,
|
|
|
|
authentication => 'Demo',
|
2017-02-05 10:13:20 +01:00
|
|
|
userDB => 'Same',
|
2017-01-30 06:54:30 +01:00
|
|
|
passwordDB => 'Demo',
|
|
|
|
captcha_mail_enabled => 1,
|
|
|
|
requireToken => 1,
|
|
|
|
portalDisplayResetPassword => 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Test form
|
|
|
|
# ------------------------
|
|
|
|
ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ),
|
|
|
|
'Reset form', );
|
|
|
|
( $host, $url, $query ) = expectForm( $res, '#', undef, 'mail', 'token' );
|
|
|
|
|
|
|
|
$query =~ s/mail=&//;
|
|
|
|
$query .= '&mail=dwho%40badwolf.org';
|
|
|
|
|
|
|
|
# Check captcha
|
|
|
|
my ($token) = ( $query =~ /token=([^&]+)/ );
|
|
|
|
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
|
|
|
' Captcha image inserted' );
|
|
|
|
|
|
|
|
# Try to get captcha value
|
|
|
|
|
|
|
|
my ( $ts, $captcha );
|
2017-03-11 19:11:57 +01:00
|
|
|
ok( $ts = getCache()->get($token), ' Found token session' );
|
|
|
|
$ts = eval { JSON::from_json($ts) };
|
|
|
|
ok( $captcha = $ts->{captcha}, ' Found captcha value' );
|
2017-01-30 06:54:30 +01:00
|
|
|
|
|
|
|
$query .= "&captcha=$captcha";
|
|
|
|
|
|
|
|
# Post email
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post mail'
|
|
|
|
);
|
|
|
|
|
2017-03-27 07:22:08 +02:00
|
|
|
ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#,
|
|
|
|
'Found link in mail' );
|
|
|
|
$query = $1;
|
|
|
|
|
2017-01-30 06:54:30 +01:00
|
|
|
ok(
|
|
|
|
$res =
|
|
|
|
$client->_get( '/resetpwd', query => $query, accept => 'text/html' ),
|
|
|
|
'Post mail token received by mail'
|
|
|
|
);
|
|
|
|
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
|
|
|
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password' );
|
|
|
|
|
|
|
|
$query .= '&newpassword=zz&confirmpassword=zz';
|
|
|
|
|
|
|
|
# Post new password
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post new password'
|
|
|
|
);
|
2017-03-27 07:22:08 +02:00
|
|
|
ok( mail() =~ /Your password was changed/, 'Password was changed' );
|
2017-01-30 06:54:30 +01:00
|
|
|
|
|
|
|
#print STDERR Dumper($query);
|
|
|
|
}
|
|
|
|
count($maintests);
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|