diff --git a/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t b/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t index cc83c5408..3f9363484 100644 --- a/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t +++ b/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t @@ -6,7 +6,7 @@ # change 'tests => 1' to 'tests => last_test_to_print'; use strict; -use Test::More tests => 13; +use Test::More tests => 17; require 't/test.pm'; BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') } @@ -60,3 +60,39 @@ ok( ok( $res = &$code, "Function works" ); 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" +); + diff --git a/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t b/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t index 2027ac4fb..2b2efcde9 100644 --- a/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t +++ b/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t @@ -5,7 +5,7 @@ # change 'tests => 1' to 'tests => last_test_to_print'; -use Test::More tests => 9; +use Test::More tests => 13; require 't/test.pm'; 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' ), 'listMatch function is defined' ); 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" +); diff --git a/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F.t b/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F.t index 4c5f32841..3502c0e8d 100644 --- a/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F.t +++ b/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F.t @@ -24,8 +24,7 @@ SKIP: { totp2fSelfRegistration => 1, u2fSelfRegistration => 1, portalMainLogo => 'common/logos/logo_llng_old.png', - u2fSelfRegistration => - '$_2fDevices =~ /"type":\s*"(?:TOTP|U2F)"/s', + u2fSelfRegistration => 'has2f("TOTP") or has2f("U2F")', } } );