lemonldap-ng/lemonldap-ng-portal/t/42-Register-Demo.t

112 lines
2.4 KiB
Perl
Raw Normal View History

2017-01-14 09:17:45 +01:00
use Test::More;
use strict;
use IO::String;
2017-01-14 20:31:48 +01:00
BEGIN {
require MIME::Lite;
require 't/test-lib.pm';
}
2017-01-14 09:17:45 +01:00
2017-01-26 22:42:40 +01:00
my ( $res, $user, $pwd );
2017-01-14 20:31:48 +01:00
my $mailSend = 0;
2017-01-14 09:17:45 +01:00
my $client = LLNG::Manager::Test->new(
{
ini => {
2017-01-14 20:31:48 +01:00
logLevel => 'error',
useSafeJail => 1,
portalDisplayRegister => 1,
2017-01-29 10:11:20 +01:00
authentication => 'Demo',
userDB => 'Same',
2017-01-14 20:31:48 +01:00
registerDB => 'Demo',
captcha_register_enabled => 0,
2017-01-14 09:17:45 +01:00
}
}
);
# Test normal first access
# ------------------------
2017-01-14 20:31:48 +01:00
ok(
$res = $client->_get( '/register', accept => 'text/html' ),
2017-01-29 10:11:20 +01:00
'Unauth request',
2017-01-14 20:31:48 +01:00
);
2017-01-14 09:17:45 +01:00
count(1);
2017-01-14 20:31:48 +01:00
my ( $host, $url, $query ) =
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
ok(
$res = $client->_post(
'/register',
IO::String->new('firstname=foo&lastname=bar&mail=foobar%40badwolf.org'),
length => 52,
accept => 'text/html'
),
'Ask to create account'
);
count(1);
expectOK($res);
# $query is set by MIME::Lite::send below
2017-01-26 22:42:40 +01:00
ok( $query =~ /register_token=/, 'Found register_token' );
2017-01-14 20:31:48 +01:00
count(1);
2017-01-26 22:42:40 +01:00
ok(
$res = $client->_get( '/register', query => $query, accept => 'text/html' ),
'Push register_token'
);
2017-01-14 20:31:48 +01:00
expectOK($res);
count(1);
# $user/$pwd are set by MIME::Lite::send below
2017-01-26 22:42:40 +01:00
ok( $user eq 'fbar', 'Get good login' );
2017-01-14 20:31:48 +01:00
count(1);
2017-01-26 22:42:40 +01:00
ok(
$res = $client->_post(
'/', IO::String->new('user=fbar&password=fbar'),
length => 23,
accept => 'text/html'
),
'Try to authenticate'
);
2017-01-14 20:31:48 +01:00
count(1);
expectCookie($res);
2017-01-14 09:17:45 +01:00
clean_sessions();
done_testing( count() );
2017-01-14 20:31:48 +01:00
no warnings 'redefine';
my $mail2 = 0;
2017-01-26 22:42:40 +01:00
2017-01-14 20:31:48 +01:00
sub MIME::Lite::send {
my ($mail) = @_;
pass('Mail sent');
2017-01-26 22:42:40 +01:00
ok( $mail->header_as_string =~ /foobar\@badwolf.org/s, 'Found dest' )
or explain( $mail->header_as_string, 'To: foobar@badwolf.org' );
2017-01-14 20:31:48 +01:00
count(2);
2017-01-26 22:42:40 +01:00
unless ($mail2) {
2017-01-14 20:31:48 +01:00
$mailSend = 1;
2017-01-26 22:42:40 +01:00
ok(
$mail->body_as_string =~
m#a href="http://auth.example.com/register\?(.*?)"#,
'Found link'
);
2017-01-14 20:31:48 +01:00
count(1);
$query = $1;
$mail2++;
}
else {
$mailSend = 2;
2017-01-26 22:42:40 +01:00
ok(
$mail->body_as_string =~
2017-02-19 12:51:58 +01:00
m#Your login is.+?<b>(\w+)</b>.*?Your password is.+?<b>(.*?)</b>#s,
2017-01-26 22:42:40 +01:00
'Get login/pwd'
);
( $user, $pwd ) = ( $1, $2 );
2017-01-14 20:31:48 +01:00
count(1);
}
}