Add test (#1391)
This commit is contained in:
parent
05c77feebc
commit
8e1d55aaa9
|
@ -157,6 +157,7 @@ site/htdocs/static/bootstrap/js/skin.js
|
|||
site/htdocs/static/bootstrap/js/skin.min.js
|
||||
site/htdocs/static/bootstrap/totp.png
|
||||
site/htdocs/static/bootstrap/u2f.png
|
||||
site/htdocs/static/bootstrap/utotp.png
|
||||
site/htdocs/static/bwr/bootstrap/dist/css/bootstrap-theme.css
|
||||
site/htdocs/static/bwr/bootstrap/dist/css/bootstrap-theme.css.map
|
||||
site/htdocs/static/bwr/bootstrap/dist/css/bootstrap-theme.min.css
|
||||
|
@ -420,6 +421,7 @@ t/63-History.t
|
|||
t/64-StayConnected.t
|
||||
t/65-AutoSignin.t
|
||||
t/70-2F-TOTP.t
|
||||
t/71-2F-UTOTP-TOTP-only.t
|
||||
t/90-Translations.t
|
||||
t/99-pod.t
|
||||
t/lmConf-1.json
|
||||
|
|
|
@ -27,8 +27,13 @@ use Lemonldap::NG::Portal::Main::Constants qw(
|
|||
|
||||
sub init {
|
||||
my ($self) = @_;
|
||||
if ( $self->conf->{utotp2fSelfRegistration}
|
||||
and $self->conf->{utotp2fActivation} eq '1' )
|
||||
if (
|
||||
(
|
||||
$self->conf->{totp2fSelfRegistration}
|
||||
or $self->conf->{u2fSelfRegistration}
|
||||
)
|
||||
and $self->conf->{utotp2fActivation} eq '1'
|
||||
)
|
||||
{
|
||||
$self->conf->{utotp2fActivation} =
|
||||
'$_totp2fSecret or $_u2fKeyHandle and $_u2fUserKey';
|
||||
|
|
126
lemonldap-ng-portal/t/71-2F-UTOTP-TOTP-only.t
Normal file
126
lemonldap-ng-portal/t/71-2F-UTOTP-TOTP-only.t
Normal file
|
@ -0,0 +1,126 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use IO::String;
|
||||
|
||||
require 't/test-lib.pm';
|
||||
my $maintests = 16;
|
||||
|
||||
SKIP: {
|
||||
eval { require Convert::Base32 };
|
||||
if ($@) {
|
||||
skip 'Convert::Base32 is missing', $maintests;
|
||||
}
|
||||
require Lemonldap::NG::Common::TOTP;
|
||||
|
||||
my $client = LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
utotp2fActivation => 1,
|
||||
totp2fSelfRegistration => 1,
|
||||
}
|
||||
}
|
||||
);
|
||||
my $res;
|
||||
|
||||
# Try to authenticate
|
||||
# -------------------
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23
|
||||
),
|
||||
'Auth query'
|
||||
);
|
||||
my $id = expectCookie($res);
|
||||
|
||||
# TOTP form
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/2fregisters',
|
||||
cookie => "lemonldap=$id",
|
||||
accept => 'text/html',
|
||||
),
|
||||
'Form registration'
|
||||
);
|
||||
expectRedirection( $res, qr#/2fregisters/totp$# );
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/2fregisters/totp',
|
||||
cookie => "lemonldap=$id",
|
||||
accept => 'text/html',
|
||||
),
|
||||
'Form registration'
|
||||
);
|
||||
ok( $res->[2]->[0] =~ /totpregistration\.(?:min\.)?js/, 'Found TOTP js' );
|
||||
|
||||
# JS query
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/2fregisters/totp/getkey', IO::String->new(''),
|
||||
cookie => "lemonldap=$id",
|
||||
length => 0,
|
||||
),
|
||||
'Get new key'
|
||||
);
|
||||
eval { $res = JSON::from_json( $res->[2]->[0] ) };
|
||||
ok( not($@), 'Content is JSON' )
|
||||
or explain( $res->[2]->[0], 'JSON content' );
|
||||
my ( $key, $token );
|
||||
ok( $key = $res->{secret}, 'Found secret' );
|
||||
ok( $token = $res->{token}, 'Found token' );
|
||||
$key = Convert::Base32::decode_base32($key);
|
||||
|
||||
# Post code
|
||||
my $code;
|
||||
ok( $code = Lemonldap::NG::Common::TOTP::_code( undef, $key, 0, 30, 6 ),
|
||||
'Code' );
|
||||
ok( $code =~ /^\d{6}$/, 'Code contains 6 digits' );
|
||||
my $s = "code=$code&token=$token";
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/2fregisters/totp/verify',
|
||||
IO::String->new($s),
|
||||
length => length($s),
|
||||
cookie => "lemonldap=$id",
|
||||
),
|
||||
'Post code'
|
||||
);
|
||||
eval { $res = JSON::from_json( $res->[2]->[0] ) };
|
||||
ok( not($@), 'Content is JSON' )
|
||||
or explain( $res->[2]->[0], 'JSON content' );
|
||||
ok( $res->{result} = 1, 'Key is registered' );
|
||||
|
||||
# Try to sing-in
|
||||
$client->logout($id);
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'Auth query'
|
||||
);
|
||||
my ( $host, $url, $query ) =
|
||||
expectForm( $res, undef, '/utotp2fcheck', 'token' );
|
||||
ok( $code = Lemonldap::NG::Common::TOTP::_code( undef, $key, 0, 30, 6 ),
|
||||
'Code' );
|
||||
$query =~ s/code=/code=$code/;
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/utotp2fcheck', IO::String->new($query),
|
||||
length => length($query),
|
||||
),
|
||||
'Post code'
|
||||
);
|
||||
$id = expectCookie($res);
|
||||
$client->logout($id);
|
||||
}
|
||||
count($maintests);
|
||||
|
||||
clean_sessions();
|
||||
|
||||
done_testing( count() );
|
||||
|
Loading…
Reference in New Issue
Block a user