lemonldap-ng/lemonldap-ng-portal/t/66-Lemonldap-NG-Portal-Captcha.t
Clément Oudot b72d79a30b Better connection management (#663, #LEMONLDAP-664):
- Create userDBFinish, passwordDBFinish and registerDBFinish methods
- Call finish methods for each backend in process
- Call LDAP unbind only when necessary
- Unbind if error in RegisterDBLDAP
2014-06-25 11:53:09 +00:00

51 lines
1.4 KiB
Perl

use Test::More tests => 5;
BEGIN {
use_ok("Lemonldap::NG::Portal::Simple");
}
# build Lemonldap::NG::Portal::Simple object
my $p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
portal => 'http://auth.example.com',
error => 0,
authentication => 'Demo',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
applicationList => {},
locationRules => {
'test.example.com' => {
'default' => "deny",
'^/ok' => '$uid eq "kharec"',
'^/nok' => '$uid eq "toto"',
},
},
cfgNum => 42,
sessionInfo => { uid => "kharec" },
captcha_size => 6,
}
);
ok(
ref($p) eq "Lemonldap::NG::Portal::Simple",
"Portal object with captcha configuration"
);
# try to init a captcha
$p->initCaptcha;
ok( $p->{captcha_img}, "Generation of captcha image" );
# try a wrong values to check checkCaptcha method
my $captcha_result =
$p->checkCaptcha( $p->{captcha_secret}, $p->{captcha_code} );
ok( 1 == $captcha_result, "Verification of good captcha" );
# New captcha
$p->initCaptcha;
my $captcha_result_2 = $p->checkCaptcha( "wrongcode", $p->{captcha_code} );
ok( 1 != $captcha_result_2, "Reject of bad captcha" );