View | Details | Raw Unified | Return to bug 20340
Collapse All | Expand All

(-)a/C4/Auth.pm (-4 / +16 lines)
Lines 39-45 use Koha::DateUtils qw(dt_from_string); Link Here
39
use Koha::Library::Groups;
39
use Koha::Library::Groups;
40
use Koha::Libraries;
40
use Koha::Libraries;
41
use Koha::Patrons;
41
use Koha::Patrons;
42
use Koha::Patron::Consents;
42
use Koha::Plugins;
43
use POSIX qw/strftime/;
43
use POSIX qw/strftime/;
44
use List::MoreUtils qw/ any /;
44
use List::MoreUtils qw/ any /;
45
use Encode qw( encode is_utf8);
45
use Encode qw( encode is_utf8);
Lines 1774-1787 sub checkpw { Link Here
1774
    my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
1774
    my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
1775
    $type = 'opac' unless $type;
1775
    $type = 'opac' unless $type;
1776
1776
1777
    # Get shibboleth login attribute
1777
    if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
1778
    my $shib = C4::Context->config('useshibboleth') && shib_ok();
1778
        my @plugins = Koha::Plugins->new()->GetPlugins({
1779
    my $shib_login = $shib ? get_login_shib() : undef;
1779
            method => 'checkpw',
1780
        });
1781
1782
        @plugins = sort { $a->retrieve_data('priority') <=> $b->retrieve_data('priority') } @plugins;
1783
        foreach my $plugin ( @plugins ) {
1784
            my ( $retval, $retcard, $retuserid ) = $plugin->checkpw(@_);
1785
            if ( $retval == 1 ) {
1786
                return ( $retval, $retcard, $retuserid );
1787
            }
1788
        }
1789
    }
1780
1790
1781
    my @return;
1791
    my @return;
1782
    my $patron = Koha::Patrons->find({ userid => $userid });
1792
    my $patron = Koha::Patrons->find({ userid => $userid });
1783
    my $check_internal_as_fallback = 0;
1793
    my $check_internal_as_fallback = 0;
1784
    my $passwd_ok = 0;
1794
    my $passwd_ok = 0;
1795
    my $shib = C4::Context->config('useshibboleth') && shib_ok();
1796
    my $shib_login = $shib ? get_login_shib() : undef;
1785
    # Note: checkpw_* routines returns:
1797
    # Note: checkpw_* routines returns:
1786
    # 1 if auth is ok
1798
    # 1 if auth is ok
1787
    # 0 if auth is nok
1799
    # 0 if auth is nok
(-)a/Koha/Plugins.pm (+1 lines)
Lines 82-87 sub GetPlugins { Link Here
82
            # Limit results by method or metadata
82
            # Limit results by method or metadata
83
            next if $method && !$plugin->can($method);
83
            next if $method && !$plugin->can($method);
84
            my $plugin_metadata = $plugin->get_metadata;
84
            my $plugin_metadata = $plugin->get_metadata;
85
85
            next if $plugin_metadata
86
            next if $plugin_metadata
86
                and %$req_metadata
87
                and %$req_metadata
87
                and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
88
                and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
(-)a/t/Koha/Plugin/TestAuth.pm (+80 lines)
Line 0 Link Here
1
package Koha::Plugin::Authentication::TestAuth;
2
3
use Modern::Perl;
4
5
use base 'Koha::Plugins::Base';
6
7
our $VERSION = '1.0';
8
our $metadata = {
9
    name => 'Authentication test plugin',
10
    author => 'Alex Arnaud <alex.arnaud@biblibre.com>',
11
    description => 'Plugin for testing authentication plugin API',
12
    date_authored => '2018-02-28',
13
    date_updated => '2018-02-28',
14
    minimum_version => '17.05',
15
    maximum_version => undef,
16
    type => 'authentication',
17
    version => $VERSION,
18
};
19
20
=head1 METHODS
21
22
=head2 new
23
24
    Koha::Plugin::TestAuth->new();
25
26
    Create new object
27
28
=cut
29
30
sub new {
31
    my ($class, $args) = @_;
32
33
    $args->{metadata} = $metadata;
34
    $args->{metadata}->{class} = $class;
35
36
    my $self = $class->SUPER::new($args);
37
38
    return $self;
39
}
40
41
sub configure {
42
    my ($self, $args) = @_; 
43
    $self->go_home();
44
}
45
46
=head2 retrieve_data
47
48
Just return priority. It overrides the one in Koha::Plugin::Base for the test.
49
50
=cut
51
52
sub retrieve_data {
53
    my ( $self, $key ) = @_;
54
55
    if ( $key eq 'priority' ) {
56
        return 1;
57
    }
58
59
}
60
61
=head2 checkpw
62
63
  ($result, cardnumber, $userid) =
64
    checkpw($self, $dbh, $userid, $password, $query, $type, $no_set_userenv);
65
66
  Authenticate a patron using login/password.
67
68
=cut
69
70
sub checkpw {
71
    my ( $self, $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
72
73
    if ( $userid = 'test' && $password eq 'test' ) {
74
        return (1, 'test', 'test');
75
    }
76
77
    return (0, '', '');
78
}
79
80
1;
(-)a/t/db_dependent/Auth.t (-9 / +23 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use Test::MockObject;
10
use Test::MockObject;
11
use Test::MockModule;
11
use Test::MockModule;
12
use List::MoreUtils qw/all any none/;
12
use List::MoreUtils qw/all any none/;
13
use Test::More tests => 20;
13
use Test::More tests => 27;
14
use Test::Warn;
14
use Test::Warn;
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
Lines 20-27 use C4::Members; Link Here
20
use Koha::AuthUtils qw/hash_password/;
20
use Koha::AuthUtils qw/hash_password/;
21
use Koha::Database;
21
use Koha::Database;
22
use Koha::Patrons;
22
use Koha::Patrons;
23
use File::Basename;
23
24
24
BEGIN {
25
BEGIN {
26
    push( @INC, dirname(__FILE__) . '/..' );
27
25
    use_ok('C4::Auth');
28
    use_ok('C4::Auth');
26
}
29
}
27
30
Lines 32-37 my $dbh = C4::Context->dbh; Link Here
32
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction
35
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction
33
# handling
36
# handling
34
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
37
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
38
t::lib::Mocks::mock_preference( 'UseKohaPlugins', 0 );
35
39
36
$schema->storage->txn_begin;
40
$schema->storage->txn_begin;
37
41
Lines 129-141 subtest 'no_set_userenv parameter tests' => sub { Link Here
129
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
133
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
130
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
134
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
131
    C4::Context->_new_userenv('DUMMY SESSION');
135
    C4::Context->_new_userenv('DUMMY SESSION');
132
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', '');
136
133
    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' );
137
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', '');
134
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
138
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' );
135
    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' );
139
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
136
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' );
140
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
137
    isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' );
141
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
138
};
142
    isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
143
144
    t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
145
    my @result = checkpw( $dbh, $patron->{userid}, 'wrong_password', undef, undef, 1 );
146
    is( $result[0], 0, 'With TestAuth plugin, checkpw returns 0' );
147
    is( $result[1], undef, 'With TestAuth plugin, checkpw returns empty cardnumber' );
148
    is( $result[2], undef, 'With TestAuth plugin, checkpw returns empty userid' );
149
    @result = checkpw( $dbh, 'test', 'test', undef, undef, 1 );
150
    is( $result[0], 1, 'With TestAuth plugin, checkpw returns 1' );
151
    is( $result[1], 'test', 'With TestAuth plugin, checkpw returns test cardnumber' );
152
    is( $result[2], 'test', 'With TestAuth plugin, checkpw returns test userid' );
153
}
139
154
140
# get_template_and_user tests
155
# get_template_and_user tests
141
156
142
- 

Return to bug 20340