Commit a0b71fe0 authored by Christophe Maudoux's avatar Christophe Maudoux

Improve unit tests (#1515)

parent 92b383eb
......@@ -6,7 +6,7 @@ require 't/test-lib.pm';
my $res;
my $maintests = 13;
my $maintests = 14;
SKIP: {
eval 'use GD::SecurityImage;use Image::Magick;';
if ($@) {
......@@ -14,11 +14,11 @@ SKIP: {
}
my $client = LLNG::Manager::Test->new(
{
ini => {
{ ini => {
logLevel => 'error',
useSafeJail => 1,
captcha_login_enabled => 1,
portalMainLogo => 'common/logos/test.png',
}
}
);
......@@ -28,7 +28,8 @@ SKIP: {
ok( $res = $client->_get('/'), 'Unauth JSON request' );
expectReject($res);
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Unauth request' );
ok( $res = $client->_get( '/', accept => 'text/html' ),
'Unauth request' );
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
$query =~ s/.*\btoken=([^&]+).*/token=$1/;
my $token;
......@@ -42,11 +43,13 @@ SKIP: {
ok( $ts = getCache()->get($token), ' Found token session' );
$ts = eval { JSON::from_json($ts) };
ok( $captcha = $ts->{captcha}, ' Found captcha value' );
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/test.png"%,
'Found custom Main Logo' )
or print STDERR Dumper( $res->[2]->[0] );
# Try to authenticate
$query .= "&user=dwho&password=dwho&captcha=$captcha";
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/',
IO::String->new($query),
length => length($query)
......@@ -57,7 +60,8 @@ SKIP: {
my $id = expectCookie($res);
# Verify auth
ok( $res = $client->_get( '/', cookie => "lemonldap=$id" ), 'Verify auth' );
ok( $res = $client->_get( '/', cookie => "lemonldap=$id" ),
'Verify auth' );
expectOK($res);
# New try (with bad captcha)
......@@ -69,8 +73,7 @@ SKIP: {
# Try to auth with bad captcha
$query .= '&user=dwho&password=dwho&captcha=00000';
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/',
IO::String->new($query),
length => length($query)
......@@ -78,8 +81,7 @@ SKIP: {
'Try to auth with bad captcha value'
);
expectReject($res);
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/', IO::String->new($query),
length => length($query),
accept => 'text/html',
......
......@@ -9,40 +9,38 @@ BEGIN {
};
}
my $maintests = 13;
my $maintests = 14;
my ( $res, $user, $pwd, $host, $url, $query );
my $mailSend = 0;
SKIP: {
eval
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
if ($@) {
skip 'Missing dependencies', $maintests;
}
my $client = LLNG::Manager::Test->new(
{
ini => {
{ ini => {
logLevel => 'error',
useSafeJail => 1,
portalDisplayRegister => 1,
registerDB => 'Demo',
captcha_register_enabled => 1,
portalMainLogo => 'common/logos/test.png',
}
}
);
# Test normal first access
# ------------------------
ok(
$res = $client->_get( '/register', accept => 'text/html' ),
ok( $res = $client->_get( '/register', accept => 'text/html' ),
'Unauth request',
);
( $host, $url, $query ) =
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
ok(
$query =~
s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.org/,
( $host, $url, $query )
= expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
ok( $query
=~ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.org/,
'Token found'
);
my $token;
......@@ -56,11 +54,13 @@ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.
ok( $ts = getCache()->get($token), ' Found token session' );
$ts = eval { JSON::from_json($ts) };
ok( $captcha = $ts->{captcha}, ' Found captcha value' );
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/test.png"%,
'Found custom Main Logo' )
or print STDERR Dumper( $res->[2]->[0] );
$query .= "&captcha=$captcha";
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/register',
IO::String->new($query),
length => length($query),
......@@ -75,16 +75,17 @@ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.
$query = $1;
ok( $query =~ /register_token=/, 'Found register_token' );
ok(
$res =
$client->_get( '/register', query => $query, accept => 'text/html' ),
ok( $res = $client->_get(
'/register',
query => $query,
accept => 'text/html'
),
'Push register_token'
);
expectOK($res);
ok(
mail() =~
m#Your login is.+?<b>(\w+)</b>.*?Your password is.+?<b>(.*?)</b>#s,
ok( mail()
=~ m#Your login is.+?<b>(\w+)</b>.*?Your password is.+?<b>(.*?)</b>#s,
'Found user and password'
);
$user = $1;
......@@ -94,8 +95,7 @@ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.
# Try to authenticate
$query = '&user=fbar&password=fbar';
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/', IO::String->new($query),
length => length($query),
accept => 'text/html'
......
......@@ -10,20 +10,19 @@ BEGIN {
}
my ( $res, $host, $url, $query );
my $maintests = 10;
my $maintests = 11;
my $mailSend = 0;
my $mail2 = 0;
SKIP: {
eval
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
if ($@) {
skip 'Missing dependencies', $maintests;
}
my $client = LLNG::Manager::Test->new(
{
ini => {
{ ini => {
logLevel => 'error',
useSafeJail => 1,
portalDisplayRegister => 1,
......@@ -33,6 +32,7 @@ SKIP: {
captcha_mail_enabled => 1,
requireToken => 1,
portalDisplayResetPassword => 1,
portalMainLogo => 'common/logos/test.png',
}
}
);
......@@ -57,12 +57,14 @@ SKIP: {
ok( $ts = getCache()->get($token), ' Found token session' );
$ts = eval { JSON::from_json($ts) };
ok( $captcha = $ts->{captcha}, ' Found captcha value' );
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/test.png"%,
'Found custom Main Logo' )
or print STDERR Dumper( $res->[2]->[0] );
$query .= "&captcha=$captcha";
# Post email
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html'
......@@ -74,9 +76,11 @@ SKIP: {
'Found link in mail' );
$query = $1;
ok(
$res =
$client->_get( '/resetpwd', query => $query, accept => 'text/html' ),
ok( $res = $client->_get(
'/resetpwd',
query => $query,
accept => 'text/html'
),
'Post mail token received by mail'
);
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
......@@ -85,8 +89,7 @@ SKIP: {
$query .= '&newpassword=zz&confirmpassword=zz';
# Post new password
ok(
$res = $client->_post(
ok( $res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html'
......
......@@ -3,7 +3,7 @@ use strict;
use IO::String;
require 't/test-lib.pm';
my $maintests = 17;
my $maintests = 18;
SKIP: {
eval { require Crypt::U2F::Server; require Authen::U2F::Tester };
......@@ -55,7 +55,7 @@ SKIP: {
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/test.png"%,
'Found custom Main Logo' )
or print STDERR Dumper( $res->[2]->[0] );
count(1);
# Ajax registration request
ok( $res = $client->_post(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment