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

54 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");
use_ok("Lemonldap::NG::Portal::_WebForm");
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',
error => 0,
authentication => 'Demo',
userDB => 'Null',
passwordDB => '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
);
## Overload captcha_output and captcha_data
mkdir "./tmp";
$p->{captcha_output} = "./tmp/output";
2012-07-26 04:47:27 +02:00
$p->{captcha_data} = "./tmp/data";
2012-07-05 09:33:15 +02:00
# create dir
2012-07-04 17:18:48 +02:00
mkdir $p->{captcha_output};
mkdir $p->{captcha_data};
2012-07-26 04:47:27 +02:00
ok( ref($p) eq "Lemonldap::NG::Portal::Simple" );
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( "12D3EO", $p->{captcha_code} );
ok( 1 ne $captcha_result, "Verification of captcha" );
2012-07-04 17:18:48 +02:00
END {
2012-07-26 04:47:27 +02:00
system("rm -rf ./tmp");
2012-07-04 17:18:48 +02:00
}