lemonldap-ng/lemonldap-ng-portal/t/43-MailReset.t

107 lines
2.4 KiB
Perl
Raw Normal View History

2017-01-29 10:11:27 +01:00
use Test::More;
use strict;
use IO::String;
BEGIN {
require MIME::Lite;
require 't/test-lib.pm';
}
my ( $res, $user, $pwd );
my $mailSend = 0;
my $mail2 = 0;
my $client = LLNG::Manager::Test->new(
{
ini => {
2017-01-29 19:08:33 +01:00
logLevel => 'error',
2017-01-29 10:11:27 +01:00
useSafeJail => 1,
portalDisplayRegister => 1,
authentication => 'Demo',
userDB => 'Same',
2017-01-29 10:11:27 +01:00
passwordDB => 'Demo',
captcha_mail_enabled => 0,
portalDisplayResetPassword => 1,
}
}
);
# Test form
# ------------------------
ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ), 'Reset form', );
count(1);
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'mail' );
$query = 'mail=dwho%40badwolf.org';
# Post email
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html'
),
2017-01-29 19:08:33 +01:00
'Post mail'
2017-01-29 10:11:27 +01:00
);
count(1);
# $query has been set by MIME::Lite::send
ok(
$res = $client->_get( '/resetpwd', query => $query, accept => 'text/html' ),
2017-01-29 19:08:33 +01:00
'Post mail token received by mail'
2017-01-29 10:11:27 +01:00
);
count(1);
2017-01-29 14:06:28 +01:00
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password' );
count(1);
$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-01-29 10:11:27 +01:00
count(1);
#print STDERR Dumper($query);
clean_sessions();
done_testing( count() );
no warnings 'redefine';
sub MIME::Lite::send {
my ($mail) = @_;
pass('----- Mail given to MIME::Lite -----');
2017-01-29 19:08:33 +01:00
ok( $mail->header_as_string =~ /dwho\@badwolf.org/s, ' Found dest' )
2017-01-29 10:11:27 +01:00
or explain( $mail->header_as_string, 'To: dwho@badwolf.org' );
count(2);
unless ($mail2) {
$mailSend = 1;
ok(
$mail->body_as_string =~
m#a href="http://auth.example.com/resetpwd\?(.*?)"#,
2017-01-29 19:08:33 +01:00
' Found link'
2017-01-29 10:11:27 +01:00
);
count(1);
$query = $1;
$mail2++;
}
else {
$mailSend = 2;
2017-01-29 19:08:33 +01:00
ok( $mail->body_as_string =~ /pwdChanged/, ' Password was changed' );
2017-01-29 10:11:27 +01:00
( $user, $pwd ) = ( $1, $2 );
count(1);
}
2017-01-29 19:08:33 +01:00
pass('----- Mail sent -----');
count(1);
2017-01-29 10:11:27 +01:00
}