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 );
|
2019-02-02 22:23:56 +01:00
|
|
|
my $maintests = 14;
|
2017-01-30 06:54:30 +01:00
|
|
|
my $mailSend = 0;
|
|
|
|
my $mail2 = 0;
|
|
|
|
|
|
|
|
SKIP: {
|
2017-04-13 22:08:55 +02:00
|
|
|
eval
|
2019-02-05 23:12:17 +01:00
|
|
|
'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
|
|
|
}
|
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2019-02-05 23:12:17 +01:00
|
|
|
ini => {
|
2017-01-30 06:54:30 +01:00
|
|
|
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,
|
2019-02-05 23:12:17 +01:00
|
|
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
2017-01-30 06:54:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Test form
|
|
|
|
# ------------------------
|
2019-02-05 23:12:17 +01:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<a class="btn btn-secondary" href="http://auth.example.com/resetpwd\?skin=bootstrap">%,
|
2019-02-02 22:23:56 +01:00
|
|
|
'Found ResetPassword link & submit button'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2017-01-30 06:54:30 +01:00
|
|
|
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=([^&]+)/ );
|
2019-12-03 11:55:04 +01:00
|
|
|
ok( $res->[2]->[0] =~ m#<img id="captcha" src="data:image/png;base64#,
|
2017-01-30 06:54:30 +01:00
|
|
|
' 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' );
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~ m%<img src="/static/common/logos/logo_llng_old.png"%,
|
2018-10-21 22:51:41 +02:00
|
|
|
'Found custom Main Logo'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2017-01-30 06:54:30 +01:00
|
|
|
|
|
|
|
$query .= "&captcha=$captcha";
|
|
|
|
|
|
|
|
# Post email
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-01-30 06:54:30 +01:00
|
|
|
'/resetpwd', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post mail'
|
|
|
|
);
|
2018-10-21 22:51:41 +02:00
|
|
|
ok( mail() =~ m%Content-Type: image/png; name="logo_llng_old.png"%,
|
|
|
|
'Found custom Main logo in mail' )
|
2019-02-05 23:12:17 +01:00
|
|
|
or print STDERR Dumper( mail() );
|
2017-01-30 06:54:30 +01:00
|
|
|
|
2017-03-27 07:22:08 +02:00
|
|
|
ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#,
|
|
|
|
'Found link in mail' );
|
|
|
|
$query = $1;
|
|
|
|
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2018-10-16 21:49:07 +02:00
|
|
|
'/resetpwd',
|
|
|
|
query => $query,
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
2017-01-30 06:54:30 +01:00
|
|
|
'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
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-01-30 06:54:30 +01:00
|
|
|
'/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() );
|