2017-01-27 06:51:19 +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-27 06:51:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-02 22:23:56 +01:00
|
|
|
my $maintests = 26;
|
2017-04-13 22:08:55 +02:00
|
|
|
my ( $res, $user, $pwd, $host, $url, $query );
|
|
|
|
my $mailSend = 0;
|
2017-01-27 12:14:50 +01:00
|
|
|
|
|
|
|
SKIP: {
|
2017-04-13 22:08:55 +02:00
|
|
|
eval
|
2019-07-02 20:03:40 +02:00
|
|
|
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;use Text::Unidecode';
|
2017-01-27 12:14:50 +01:00
|
|
|
if ($@) {
|
2017-04-13 22:08:55 +02:00
|
|
|
skip 'Missing dependencies', $maintests;
|
2017-01-27 06:51:19 +01:00
|
|
|
}
|
2017-01-27 12:14:50 +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 => {
|
2018-10-21 22:12:56 +02:00
|
|
|
logLevel => 'error',
|
2017-01-27 12:14:50 +01:00
|
|
|
useSafeJail => 1,
|
|
|
|
portalDisplayRegister => 1,
|
|
|
|
registerDB => 'Demo',
|
|
|
|
captcha_register_enabled => 1,
|
2018-10-21 22:12:56 +02:00
|
|
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
2017-01-27 12:14:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-12-18 11:16:34 +01:00
|
|
|
# Try to register with an alredy existing mail address
|
|
|
|
# ------------------------
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get( '/register', accept => 'text/html' ),
|
2018-12-18 11:16:34 +01:00
|
|
|
'Unauth request',
|
|
|
|
);
|
2019-02-05 23:12:17 +01:00
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
|
|
|
|
ok(
|
|
|
|
$query =~
|
|
|
|
s/^.*token=([^&]+).*$/token=$1&firstname=who&lastname=doctor&mail=dwho%40badwolf.org/,
|
2018-12-18 11:16:34 +01:00
|
|
|
'Token found'
|
|
|
|
);
|
|
|
|
my $token;
|
|
|
|
ok( $token = $1, ' Token value is defined' );
|
|
|
|
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
|
|
|
' Captcha image inserted' )
|
2019-02-05 23:12:17 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-12-18 11:16:34 +01:00
|
|
|
|
|
|
|
# Try to get captcha value
|
|
|
|
my ( $ts, $captcha );
|
|
|
|
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-12-18 11:16:34 +01:00
|
|
|
'Found custom Main Logo'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
|
|
|
|
$query .= "&captcha=$captcha";
|
|
|
|
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-12-18 11:16:34 +01:00
|
|
|
'/register',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Ask to create account'
|
|
|
|
);
|
|
|
|
|
|
|
|
ok( $res->[2]->[0] =~ q%<span trmsg="80"></span>%,
|
|
|
|
'Rejected -> Mail already exists' );
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] !~
|
|
|
|
m%<form action="#" method="post" class="login" role="form">%,
|
2018-12-18 11:16:34 +01:00
|
|
|
'No form found'
|
|
|
|
);
|
|
|
|
|
2017-01-27 12:14:50 +01:00
|
|
|
# Test normal first access
|
|
|
|
# ------------------------
|
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/register\?skin=bootstrap">%,
|
2019-02-02 22:23:56 +01:00
|
|
|
'Found Register link & submit button'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get( '/register', accept => 'text/html' ),
|
2017-01-29 10:11:20 +01:00
|
|
|
'Unauth request',
|
2017-01-27 12:14:50 +01:00
|
|
|
);
|
2019-02-05 23:12:17 +01:00
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
|
|
|
|
ok(
|
|
|
|
$query =~
|
|
|
|
s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.org/,
|
2017-01-27 12:14:50 +01:00
|
|
|
'Token found'
|
|
|
|
);
|
|
|
|
ok( $token = $1, ' Token value is defined' );
|
|
|
|
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
2018-10-21 22:12:56 +02:00
|
|
|
' Captcha image inserted' )
|
2019-02-05 23:12:17 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2017-01-27 12:14:50 +01:00
|
|
|
|
|
|
|
# Try to get captcha value
|
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-11-26 14:40:21 +01:00
|
|
|
'Found custom Main Logo'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2017-01-27 12:14:50 +01:00
|
|
|
$query .= "&captcha=$captcha";
|
|
|
|
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-01-27 12:14:50 +01:00
|
|
|
'/register',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Ask to create account'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
|
2017-03-27 07:22:08 +02:00
|
|
|
ok( mail() =~ m#a href="http://auth.example.com/register\?(.*?)"#,
|
|
|
|
'Found register token' );
|
|
|
|
$query = $1;
|
2017-01-27 12:14:50 +01:00
|
|
|
ok( $query =~ /register_token=/, 'Found register_token' );
|
|
|
|
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2018-10-16 21:49:07 +02:00
|
|
|
'/register',
|
|
|
|
query => $query,
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
2017-01-27 12:14:50 +01:00
|
|
|
'Push register_token'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
mail() =~
|
|
|
|
m#Your login is.+?<b>(\w+)</b>.*?Your password is.+?<b>(.*?)</b>#s,
|
2017-03-27 07:22:08 +02:00
|
|
|
'Found user and password'
|
|
|
|
);
|
|
|
|
$user = $1;
|
|
|
|
$pwd = $2;
|
2017-01-27 12:14:50 +01:00
|
|
|
ok( $user eq 'fbar', 'Get good login' );
|
|
|
|
|
|
|
|
# Try to authenticate
|
|
|
|
$query = '&user=fbar&password=fbar';
|
|
|
|
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-01-27 12:14:50 +01:00
|
|
|
'/', IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Try to authenticate'
|
|
|
|
);
|
|
|
|
expectCookie($res);
|
|
|
|
}
|
|
|
|
count($maintests);
|
2017-01-27 06:51:19 +01:00
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|