lemonldap-ng/lemonldap-ng-portal/t/43-MailPasswordReset-with-token.t

109 lines
3.0 KiB
Perl
Raw Permalink Normal View History

2017-01-30 06:54:30 +01:00
use Test::More;
use strict;
use IO::String;
BEGIN {
eval {
require 't/test-lib.pm';
require 't/smtp.pm';
};
2017-01-30 06:54:30 +01:00
}
my ( $res, $user, $pwd );
2019-02-02 22:23:56 +01:00
my $maintests = 11;
my $mailSend = 0;
2017-01-30 06:54:30 +01:00
my $mail2 = 0;
SKIP: {
eval
2019-02-05 23:12:17 +01:00
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
if ($@) {
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 => {
2019-05-11 20:18:43 +02:00
logLevel => 'error',
useSafeJail => 1,
portalDisplayRegister => 1,
authentication => 'Demo',
userDB => 'Same',
passwordDB => 'Demo',
captcha_mail_enabled => 0,
requireToken => '$env->{ipAddr} !~ /127\.0\.[1-3]\.1/',
portalDisplayResetPassword => 1,
2019-02-05 23:12:17 +01:00
portalMainLogo => 'common/logos/logo_llng_old.png',
}
}
);
# 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] );
ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ),
'Reset form', );
2019-02-05 23:12:17 +01:00
my ( $host, $url, $query ) =
expectForm( $res, '#', undef, 'mail', 'token' );
$query =~ s/mail=&//;
$query .= '&mail=dwho%40badwolf.org';
# Post email
2019-02-05 23:12:17 +01:00
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html'
),
'Post mail'
);
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] );
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() );
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-21 22:51:41 +02:00
'/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
2019-02-05 23:12:17 +01:00
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html'
),
'Post new password'
);
ok( mail() =~ /Your password was changed/, 'Password was changed' );
#print STDERR Dumper($query);
}
count($maintests);
2017-01-30 06:54:30 +01:00
clean_sessions();
done_testing( count() );