From a28310956ef896ac27b91cee62dc2d6a68198bd4 Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Sat, 16 Feb 2019 22:00:25 +0100 Subject: [PATCH] Append unit test (#1632) --- ...th-HISTORY.t => 70-2F-TOTP-with-History.t} | 0 ...ith-HISTORY.t => 71-2F-U2F-with-History.t} | 0 ...> 73-2F-UTOTP-TOTP-and-U2F-with-History.t} | 0 ...t => 73-2F-UTOTP-TOTP-only-with-History.t} | 0 .../t/76-2F-Ext-with-CodeActivation.t | 66 +++++++++++++++++++ .../t/76-2F-Ext-with-GrantSession.t | 2 +- ...ith-HISTORY.t => 76-2F-Ext-with-History.t} | 0 lemonldap-ng-portal/t/sendCode.pl | 7 ++ 8 files changed, 74 insertions(+), 1 deletion(-) rename lemonldap-ng-portal/t/{70-2F-TOTP-with-HISTORY.t => 70-2F-TOTP-with-History.t} (100%) rename lemonldap-ng-portal/t/{71-2F-U2F-with-HISTORY.t => 71-2F-U2F-with-History.t} (100%) rename lemonldap-ng-portal/t/{73-2F-UTOTP-TOTP-and-U2F-with-HISTORY.t => 73-2F-UTOTP-TOTP-and-U2F-with-History.t} (100%) rename lemonldap-ng-portal/t/{73-2F-UTOTP-TOTP-only-with-HISTORY.t => 73-2F-UTOTP-TOTP-only-with-History.t} (100%) create mode 100644 lemonldap-ng-portal/t/76-2F-Ext-with-CodeActivation.t rename lemonldap-ng-portal/t/{76-2F-Ext-with-HISTORY.t => 76-2F-Ext-with-History.t} (100%) create mode 100755 lemonldap-ng-portal/t/sendCode.pl diff --git a/lemonldap-ng-portal/t/70-2F-TOTP-with-HISTORY.t b/lemonldap-ng-portal/t/70-2F-TOTP-with-History.t similarity index 100% rename from lemonldap-ng-portal/t/70-2F-TOTP-with-HISTORY.t rename to lemonldap-ng-portal/t/70-2F-TOTP-with-History.t diff --git a/lemonldap-ng-portal/t/71-2F-U2F-with-HISTORY.t b/lemonldap-ng-portal/t/71-2F-U2F-with-History.t similarity index 100% rename from lemonldap-ng-portal/t/71-2F-U2F-with-HISTORY.t rename to lemonldap-ng-portal/t/71-2F-U2F-with-History.t diff --git a/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F-with-HISTORY.t b/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F-with-History.t similarity index 100% rename from lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F-with-HISTORY.t rename to lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-and-U2F-with-History.t diff --git a/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-only-with-HISTORY.t b/lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-only-with-History.t similarity index 100% rename from lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-only-with-HISTORY.t rename to lemonldap-ng-portal/t/73-2F-UTOTP-TOTP-only-with-History.t diff --git a/lemonldap-ng-portal/t/76-2F-Ext-with-CodeActivation.t b/lemonldap-ng-portal/t/76-2F-Ext-with-CodeActivation.t new file mode 100644 index 000000000..72d39f356 --- /dev/null +++ b/lemonldap-ng-portal/t/76-2F-Ext-with-CodeActivation.t @@ -0,0 +1,66 @@ +use Test::More; +use strict; +use IO::String; +use Data::Dumper; + +require 't/test-lib.pm'; + +use_ok('Lemonldap::NG::Common::FormEncode'); +count(1); + +my $client = LLNG::Manager::Test->new( { + ini => { + logLevel => 'error', + ext2fActivation => 1, + ext2fCodeActivation => 'A1b2C0', + ext2FSendCommand => 't/sendCode.pl -uid $uid -code $code', + authentication => 'Demo', + userDB => 'Same', + } + } +); + +my $res; + +# Try to authenticate +# ------------------- +ok( + $res = $client->_post( + '/', + IO::String->new('user=dwho&password=dwho'), + length => 23, + accept => 'text/html', + ), + 'Auth query' +); +count(1); + +my ( $host, $url, $query ) = + expectForm( $res, undef, '/ext2fcheck', 'token', 'code' ); + +ok( + $res->[2]->[0] =~ +qr%%, + 'Found EXTCODE input' +) or print STDERR Dumper( $res->[2]->[0] ); +count(1); + +$query =~ s/code=/code=A1b2C0/; +ok( + $res = $client->_post( + '/ext2fcheck', + IO::String->new($query), + length => length($query), + accept => 'text/html', + ), + 'Post code' +); +count(1); + +my $id = expectCookie($res); +$client->logout($id); + +clean_sessions(); + +done_testing( count() ); + diff --git a/lemonldap-ng-portal/t/76-2F-Ext-with-GrantSession.t b/lemonldap-ng-portal/t/76-2F-Ext-with-GrantSession.t index 55f138e3a..149465620 100644 --- a/lemonldap-ng-portal/t/76-2F-Ext-with-GrantSession.t +++ b/lemonldap-ng-portal/t/76-2F-Ext-with-GrantSession.t @@ -10,7 +10,7 @@ count(1); my $client = LLNG::Manager::Test->new( { ini => { - logLevel => 'debug', + logLevel => 'error', ext2fActivation => 1, ext2fCodeActivation => 0, ext2FSendCommand => 't/sendOTP.pl -uid $uid', diff --git a/lemonldap-ng-portal/t/76-2F-Ext-with-HISTORY.t b/lemonldap-ng-portal/t/76-2F-Ext-with-History.t similarity index 100% rename from lemonldap-ng-portal/t/76-2F-Ext-with-HISTORY.t rename to lemonldap-ng-portal/t/76-2F-Ext-with-History.t diff --git a/lemonldap-ng-portal/t/sendCode.pl b/lemonldap-ng-portal/t/sendCode.pl new file mode 100755 index 000000000..cde4307fd --- /dev/null +++ b/lemonldap-ng-portal/t/sendCode.pl @@ -0,0 +1,7 @@ +#!/usr/bin/perl +use strict; +use warnings; + +my ( $swt1, $user, $swt2, $code ) = @ARGV; + +exit !( $swt1 eq '-uid' && $user eq 'dwho' && $swt2 eq '-code' && defined $code );