Bugzilla – Attachment 91304 Details for
Bug 20340
Ability to use authentication plugin
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20340 - Ability to add and use authentication plugins
Bug-20340---Ability-to-add-and-use-authentication-.patch (text/plain), 7.05 KB, created by
Mark Tompsett
on 2019-07-05 02:26:27 UTC
(
hide
)
Description:
Bug 20340 - Ability to add and use authentication plugins
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2019-07-05 02:26:27 UTC
Size:
7.05 KB
patch
obsolete
>From 7f5cae553b3a836fbea0ead17cdd41f00639b546 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Thu, 1 Mar 2018 08:43:41 +0000 >Subject: [PATCH] Bug 20340 - Ability to add and use authentication plugins > >Plugins must be placed in <pluginsdir> and enabled with >AuthenticationModule system preference. > >Test plan: > > - Apply this patch, > - set UseKohaPlugins to enabled, > - define a pluginsdir in your koha-conf.xml, > - put a plugin in this directory. > - I.e, take the one provided in tests directory: > - t/Koha/Plugin/TestAuth.pm, > - login/pass is test/test > - You should have: > /your/plugins/dir/Koha/Plugin/TestAuth.pm, > - test authentication with and without the plugin. >--- > C4/Auth.pm | 14 +++++++++ > t/Koha/Plugin/TestAuth.pm | 75 +++++++++++++++++++++++++++++++++++++++++++++++ > t/db_dependent/Auth.t | 32 +++++++++++++++----- > 3 files changed, 113 insertions(+), 8 deletions(-) > create mode 100644 t/Koha/Plugin/TestAuth.pm > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index d79ce466e0..01caf8bf91 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -40,6 +40,7 @@ use Koha::Library::Groups; > use Koha::Libraries; > use Koha::Patrons; > use Koha::Patron::Consents; >+use Koha::Plugins; > use POSIX qw/strftime/; > use List::MoreUtils qw/ any /; > use Encode qw( encode is_utf8); >@@ -1781,6 +1782,19 @@ sub checkpw { > my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_; > $type = 'opac' unless $type; > >+ if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) { >+ my @plugins = Koha::Plugins->new()->GetPlugins({ >+ method => 'checkpw', >+ }); >+ >+ @plugins = sort { $a->retrieve_data('priority') <=> $b->retrieve_data('priority') } @plugins; >+ foreach my $plugin ( @plugins ) { >+ my ( $retval, $retcard, $retuserid ) = $plugin->checkpw(@_); >+ if ( $retval == 1 ) { >+ return ( $retval, $retcard, $retuserid ); >+ } >+ } >+ } > # Get shibboleth login attribute > my $shib = C4::Context->config('useshibboleth') && shib_ok(); > my $shib_login = $shib ? get_login_shib() : undef; >diff --git a/t/Koha/Plugin/TestAuth.pm b/t/Koha/Plugin/TestAuth.pm >new file mode 100644 >index 0000000000..438213b4fa >--- /dev/null >+++ b/t/Koha/Plugin/TestAuth.pm >@@ -0,0 +1,75 @@ >+package Koha::Plugin::TestAuth; >+ >+use Modern::Perl; >+ >+use base 'Koha::Plugins::Base'; >+ >+our $VERSION = '1.0'; >+our $metadata = { >+ name => 'Authentication test plugin', >+ author => 'Alex Arnaud <alex.arnaud@biblibre.com>', >+ description => 'Plugin for testing authentication plugin API', >+ date_authored => '2018-02-28', >+ date_updated => '2018-02-28', >+ minimum_version => '17.05', >+ maximum_version => undef, >+ type => 'authentication', >+ version => $VERSION, >+}; >+ >+=head1 METHODS >+ >+=head2 new >+ >+ Koha::Plugin::TestAuth->new(); >+ >+ Create new object >+ >+=cut >+ >+sub new { >+ my ($class, $args) = @_; >+ >+ $args->{metadata} = $metadata; >+ $args->{metadata}->{class} = $class; >+ >+ my $self = $class->SUPER::new($args); >+ >+ return $self; >+} >+ >+=head2 retrieve_data >+ >+Just return priority. It overrides the one in Koha::Plugin::Base for the test. >+ >+=cut >+ >+sub retrieve_data { >+ my ( $self, $key ) = @_; >+ >+ if ( $key eq 'priority' ) { >+ return 1; >+ } >+ >+} >+ >+=head2 checkpw >+ >+ ($result, cardnumber, $userid) = >+ checkpw($self, $dbh, $userid, $password, $query, $type, $no_set_userenv); >+ >+ Authenticate a patron using login/password. >+ >+=cut >+ >+sub checkpw { >+ my ( $self, $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_; >+ >+ if ( $userid = 'test' && $password eq 'test' ) { >+ return (1, 'test', 'test'); >+ } >+ >+ return (0, '', ''); >+} >+ >+1; >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index 25a77d3d65..91c7bc3b48 100644 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -10,7 +10,7 @@ use CGI qw ( -utf8 ); > use Test::MockObject; > use Test::MockModule; > use List::MoreUtils qw/all any none/; >-use Test::More tests => 22; >+use Test::More; > use Test::Warn; > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -20,8 +20,11 @@ use C4::Members; > use Koha::AuthUtils qw/hash_password/; > use Koha::Database; > use Koha::Patrons; >+use File::Basename; > > BEGIN { >+ push( @INC, dirname(__FILE__) . '/..' ); >+ > use_ok('C4::Auth'); > } > >@@ -33,6 +36,7 @@ my $dbh = C4::Context->dbh; > # handling > t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); > t::lib::Mocks::mock_preference( 'GDPR_Policy', '' ); # Disabled >+t::lib::Mocks::mock_preference( 'UseKohaPlugins', 0 ); > > $schema->storage->txn_begin; > >@@ -130,13 +134,24 @@ subtest 'no_set_userenv parameter tests' => sub { > ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); > is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); > C4::Context->_new_userenv('DUMMY SESSION'); >- C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); >- is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); >- ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); >- is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); >- ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); >- isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); >-}; >+ >+ C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', ''); >+ is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' ); >+ ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' ); >+ is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' ); >+ ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' ); >+ isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' ); >+ >+ t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 ); >+ my @result = checkpw( $dbh, $patron->{userid}, 'wrong_password', undef, undef, 1 ); >+ is( $result[0], 0, 'With TestAuth plugin, checkpw returns 0' ); >+ is( $result[1], undef, 'With TestAuth plugin, checkpw returns empty cardnumber' ); >+ is( $result[2], undef, 'With TestAuth plugin, checkpw returns empty userid' ); >+ @result = checkpw( $dbh, 'test', 'test', undef, undef, 1 ); >+ is( $result[0], 1, 'With TestAuth plugin, checkpw returns 1' ); >+ is( $result[1], 'test', 'With TestAuth plugin, checkpw returns test cardnumber' ); >+ is( $result[2], 'test', 'With TestAuth plugin, checkpw returns test userid' ); >+} > > subtest 'checkpw lockout tests' => sub { > >@@ -386,3 +401,4 @@ subtest 'Check value of login_attempts in checkpw' => sub { > }; > > $schema->storage->txn_rollback; >+done_testing(); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20340
:
72469
|
73089
|
73098
|
73106
|
88470
|
88472
|
88473
|
88474
|
88475
|
88476
|
88477
|
88478
|
88487
|
88488
|
88511
|
88512
|
88518
|
88519
|
88520
|
88521
|
88522
|
88523
|
88526
|
88527
| 91304 |
91305
|
91306
|
91307