From e290dc346e861e4e1cc8166cc30d4a193496d796 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 17 Jan 2022 15:30:14 +0000 Subject: [PATCH] Bug 29894: First draft for testing Content-Type: text/plain; charset=utf-8 --- t/db_dependent/Koha/Auth/TwoFactorAuth.t | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 t/db_dependent/Koha/Auth/TwoFactorAuth.t diff --git a/t/db_dependent/Koha/Auth/TwoFactorAuth.t b/t/db_dependent/Koha/Auth/TwoFactorAuth.t new file mode 100644 index 0000000000..2e6912621e --- /dev/null +++ b/t/db_dependent/Koha/Auth/TwoFactorAuth.t @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Test::More tests => 1; +use Test::Exception; + +use t::lib::Mocks; +use t::lib::TestBuilder; + +#use C4::Context; +use Koha::Database; +#use Koha::AuthUtils; +use Koha::Auth::TwoFactorAuth; + +our $schema = Koha::Database->new->schema; +our $builder = t::lib::TestBuilder->new; + +subtest 'new' => sub { + plan tests => 3; + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1); + + # Trivial test: no patron, no object + throws_ok { Koha::Auth::TwoFactorAuth->new; } + 'Koha::Exceptions::MissingParameter', + 'Croaked on missing patron'; + throws_ok { Koha::Auth::TwoFactorAuth->new({ patron => 'Henk', secret => q<> }) } + 'Koha::Exceptions::MissingParameter', + 'Croaked on missing patron object'; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + $patron->auth_method('two-factor'); + $patron->secret(''); + $patron->store; + + + throws_ok { Koha::Auth::TwoFactorAuth->new({ patron => $patron }) } + 'Koha::Exceptions::MissingParameter', + 'Croaked on missing secret'; + + + + + + + + + +# my $cgi = Test::MockObject->new; +# $cgi->mock( 'param', sub { return 2; } ); +# my $auth = Test::MockModule->new( 'C4::Auth' ); +# $auth->mock( 'checkauth', \&MockedCheckauth ); + + + + + $schema->storage->txn_rollback; +}; -- 2.20.1