Add LDAP test for register (#1338)

This commit is contained in:
Xavier Guimard 2017-12-18 11:20:21 +01:00
parent fab1eaf815
commit 3cca027a40
2 changed files with 102 additions and 0 deletions

View File

@ -323,6 +323,7 @@ t/01-AuthDemo.t
t/02-Password-Demo.t
t/03-XSS-protection.t
t/19-Auth-Null.t
t/20-Auth-and-password-DBI-dynamic-hash.t
t/20-Auth-and-password-DBI.t
t/20-Auth-DBI-utf8.t
t/21-Auth-and-password-LDAP.t
@ -384,6 +385,7 @@ t/41-Token.t
t/42-Register-Demo-with-captcha.t
t/42-Register-Demo-with-token.t
t/42-Register-Demo.t
t/42-Register-LDAP.t
t/43-MailReset-with-captcha.t
t/43-MailReset-with-token.t
t/43-MailReset.t

View File

@ -0,0 +1,100 @@
use Test::More;
use strict;
use IO::String;
BEGIN {
eval {
require 't/test-lib.pm';
require 't/smtp.pm';
};
}
my $maintests = 9;
my ( $res, $user, $pwd );
SKIP: {
skip 'LLNGTESTLDAP is not set', $maintests unless ( $ENV{LLNGTESTLDAP} );
require 't/test-ldap.pm';
eval 'require Email::Sender::Simple';
if ($@) {
skip 'Missing dependencies', $maintests;
}
my $client = LLNG::Manager::Test->new(
{
ini => {
logLevel => 'debug',
useSafeJail => 1,
portalDisplayRegister => 1,
authentication => 'LDAP',
userDB => 'Same',
registerDB => 'LDAP',
captcha_register_enabled => 0,
ldapServer => 'ldap://127.0.0.1:19389/',
ldapBase => 'ou=users,dc=example,dc=com',
managerDn => 'cn=admin,dc=example,dc=com',
managerPassword => 'admin',
}
}
);
# Test normal first access
# ------------------------
ok(
$res = $client->_get( '/register', accept => 'text/html' ),
'Unauth request',
);
my ( $host, $url, $query ) =
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
ok(
$res = $client->_post(
'/register',
IO::String->new(
'firstname=fôo&lastname=bar&mail=foobar%40badwolf.org'),
length => 53,
accept => 'text/html'
),
'Ask to create account'
);
expectOK($res);
my $mail = mail();
ok( $mail =~ m#a href="http://auth.example.com/register\?(.*?)"#,
'Found register token' );
$query = $1;
ok( $query =~ /register_token=/, 'Found register_token' );
ok( $mail =~ /fôo/, 'UTF-8 works' ) or explain( $mail, 'fôo' );
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,
'Found user and password'
);
$user = $1;
$pwd = $2;
ok( $user eq 'fbar', 'Get good login' );
ok(
$res = $client->_post(
'/', IO::String->new('user=fbar&password=fbar'),
length => 23,
accept => 'text/html'
),
'Try to authenticate'
);
expectCookie($res);
}
count($maintests);
stopLdapServer() if $ENV{LLNGTESTLDAP};
done_testing( count() );