lemonldap-ng/lemonldap-ng-portal/t/66-Lemonldap-NG-Portal-Captcha.t

51 lines
1.4 KiB
Perl
Raw Normal View History

use Test::More tests => 5;
2012-07-04 17:18:48 +02:00
BEGIN {
2012-07-26 04:47:27 +02:00
use_ok("Lemonldap::NG::Portal::Simple");
2012-07-04 17:18:48 +02:00
}
2012-07-26 04:47:27 +02:00
# build Lemonldap::NG::Portal::Simple object
2012-07-04 17:18:48 +02:00
my $p = Lemonldap::NG::Portal::Simple->new(
2012-07-26 04:47:27 +02:00
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
portal => 'http://auth.example.com',
2012-07-26 04:47:27 +02:00
error => 0,
authentication => 'Demo',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
2012-07-26 04:47:27 +02:00
applicationList => {},
locationRules => {
'test.example.com' => {
'default' => "deny",
'^/ok' => '$uid eq "kharec"',
'^/nok' => '$uid eq "toto"',
},
},
cfgNum => 42,
sessionInfo => { uid => "kharec" },
captcha_size => 6,
2012-07-26 04:47:27 +02:00
}
2012-07-04 17:18:48 +02:00
);
ok(
ref($p) eq "Lemonldap::NG::Portal::Simple",
"Portal object with captcha configuration"
);
2012-07-04 17:18:48 +02:00
# try to init a captcha
$p->initCaptcha;
ok( $p->{captcha_img}, "Generation of captcha image" );
2012-07-26 04:47:27 +02:00
2012-07-05 09:33:15 +02:00
# 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" );
2012-07-04 17:18:48 +02:00