unit test for has2f (#2391)
This commit is contained in:
parent
b18350703d
commit
62c0f9a8b7
|
@ -6,7 +6,7 @@
|
||||||
# change 'tests => 1' to 'tests => last_test_to_print';
|
# change 'tests => 1' to 'tests => last_test_to_print';
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Test::More tests => 13;
|
use Test::More tests => 17;
|
||||||
require 't/test.pm';
|
require 't/test.pm';
|
||||||
BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') }
|
BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') }
|
||||||
|
|
||||||
|
@ -60,3 +60,39 @@ ok(
|
||||||
ok( $res = &$code, "Function works" );
|
ok( $res = &$code, "Function works" );
|
||||||
ok( $res == 1, 'Get good result' );
|
ok( $res == 1, 'Get good result' );
|
||||||
|
|
||||||
|
$sub = "sub { return(has2f(\$_[0],\$_[1])) }";
|
||||||
|
$code = $jail->jail_reval($sub);
|
||||||
|
ok(
|
||||||
|
( defined($code) and ref($code) eq 'CODE' ),
|
||||||
|
'checkDate extended function is defined'
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
$code->( {
|
||||||
|
_2fDevices =>
|
||||||
|
"[{\"name\":\"MyTOTP\",\"_secret\":\"g5fsxwf4d34biemlojsbbvhgtskrssos\",\"epoch\":1602173208,\"type\":\"TOTP\"}]"
|
||||||
|
},
|
||||||
|
"TOTP"
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
"Function works"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
$code->( {
|
||||||
|
_2fDevices =>
|
||||||
|
"[{\"name\":\"MyTOTP\",\"_secret\":\"g5fsxwf4d34biemlojsbbvhgtskrssos\",\"epoch\":1602173208,\"type\":\"TOTP\"}]"
|
||||||
|
},
|
||||||
|
"UBK"
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
"Function works"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
$code->( {
|
||||||
|
_2fDevices =>
|
||||||
|
"[{\"name\":\"MyTOTP\",\"_secret\":\"g5fsxwf4d34biemlojsbbvhgtskrssos\",\"epoch\":1602173208,\"type\":\"TOTP\"}]"
|
||||||
|
},
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
"Function works"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
# change 'tests => 1' to 'tests => last_test_to_print';
|
# change 'tests => 1' to 'tests => last_test_to_print';
|
||||||
|
|
||||||
use Test::More tests => 9;
|
use Test::More tests => 13;
|
||||||
require 't/test.pm';
|
require 't/test.pm';
|
||||||
BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') }
|
BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') }
|
||||||
|
|
||||||
|
@ -54,3 +54,40 @@ $listMatch = $jail->jail_reval($sub5);
|
||||||
ok( ( defined($listMatch) and ref($listMatch) eq 'CODE' ),
|
ok( ( defined($listMatch) and ref($listMatch) eq 'CODE' ),
|
||||||
'listMatch function is defined' );
|
'listMatch function is defined' );
|
||||||
ok( &$listMatch eq '0', 'Get good result' );
|
ok( &$listMatch eq '0', 'Get good result' );
|
||||||
|
|
||||||
|
# Test has2f method
|
||||||
|
my $sub6 = "sub { return(has2f(\$_[0],\$_[1])) }";
|
||||||
|
my $has2f = $jail->jail_reval($sub6);
|
||||||
|
ok(
|
||||||
|
( defined($has2f) and ref($has2f) eq 'CODE' ),
|
||||||
|
'checkDate extended function is defined'
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
$has2f->( {
|
||||||
|
_2fDevices =>
|
||||||
|
"[{\"name\":\"MyTOTP\",\"_secret\":\"g5fsxwf4d34biemlojsbbvhgtskrssos\",\"epoch\":1602173208,\"type\":\"TOTP\"}]"
|
||||||
|
},
|
||||||
|
"TOTP"
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
"Function works"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
$has2f->( {
|
||||||
|
_2fDevices =>
|
||||||
|
"[{\"name\":\"MyTOTP\",\"_secret\":\"g5fsxwf4d34biemlojsbbvhgtskrssos\",\"epoch\":1602173208,\"type\":\"TOTP\"}]"
|
||||||
|
},
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
"Function works"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
$has2f->( {
|
||||||
|
_2fDevices =>
|
||||||
|
"[{\"name\":\"MyTOTP\",\"_secret\":\"g5fsxwf4d34biemlojsbbvhgtskrssos\",\"epoch\":1602173208,\"type\":\"TOTP\"}]"
|
||||||
|
},
|
||||||
|
"UBK"
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
"Function works"
|
||||||
|
);
|
||||||
|
|
|
@ -24,8 +24,7 @@ SKIP: {
|
||||||
totp2fSelfRegistration => 1,
|
totp2fSelfRegistration => 1,
|
||||||
u2fSelfRegistration => 1,
|
u2fSelfRegistration => 1,
|
||||||
portalMainLogo => 'common/logos/logo_llng_old.png',
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
||||||
u2fSelfRegistration =>
|
u2fSelfRegistration => 'has2f("TOTP") or has2f("U2F")',
|
||||||
'$_2fDevices =~ /"type":\s*"(?:TOTP|U2F)"/s',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user