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

(-)a/Koha/Auth/Client.pm (+25 lines)
Lines 19-24 package Koha::Auth::Client; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use C4::Context;
23
22
use Koha::Exceptions::Auth;
24
use Koha::Exceptions::Auth;
23
use Koha::Auth::Identity::Providers;
25
use Koha::Auth::Identity::Providers;
24
26
Lines 62-67 sub get_user { Link Here
62
64
63
    my ( $mapped_data, $patron ) = $self->_get_data_and_patron({ provider => $provider, data => $data, config => $config });
65
    my ( $mapped_data, $patron ) = $self->_get_data_and_patron({ provider => $provider, data => $data, config => $config });
64
66
67
    # Call the plugin hook "auth_client_get_user" of all plugins in
68
    # ascending priority.
69
    if ( C4::Context->config('enable_plugins') ) {
70
        my @plugins = Koha::Plugins->new()->GetPlugins(
71
            {
72
                method => 'auth_client_get_user',
73
            }
74
        );
75
        @plugins = sort { $a->retrieve_data('priority') <=> $b->retrieve_data('priority') } @plugins;
76
        my $args = {
77
            provider    => $provider,
78
            data        => $data,
79
            config      => $config,
80
            mapped_data => $mapped_data,
81
            patron      => $patron,
82
        };
83
        foreach my $plugin (@plugins) {
84
            $plugin->auth_client_get_user($args);
85
        }
86
        $mapped_data = $args->{'mapped_data'};
87
        $patron      = $args->{'patron'};
88
    }
89
65
    $mapped_data //= {};
90
    $mapped_data //= {};
66
91
67
    my $domain = $self->has_valid_domain_config({ provider => $provider, email => $mapped_data->{email}, interface => $interface});
92
    my $domain = $self->has_valid_domain_config({ provider => $provider, email => $mapped_data->{email}, interface => $interface});
(-)a/t/db_dependent/Koha/Auth/Client.t (-2 / +42 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Test::More tests => 4;
22
use Test::More tests => 4;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::MockObject;
25
use Test::Exception;
26
use Test::Exception;
26
27
27
use JSON qw(encode_json);
28
use JSON qw(encode_json);
Lines 38-44 my $schema = Koha::Database->new->schema; Link Here
38
my $builder = t::lib::TestBuilder->new;
39
my $builder = t::lib::TestBuilder->new;
39
40
40
subtest 'get_user() tests' => sub {
41
subtest 'get_user() tests' => sub {
41
    plan tests => 4;
42
    plan tests => 5;
42
43
43
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
44
45
Lines 77-82 subtest 'get_user() tests' => sub { Link Here
77
    is( $mapped_data->{surname},              undef,                                         'No surname mapped' );
78
    is( $mapped_data->{surname},              undef,                                         'No surname mapped' );
78
    is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' );
79
    is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' );
79
80
81
    # Test the plugin hook "auth_client_get_user".
82
    t::lib::Mocks::mock_config( 'enable_plugins', 1 );
83
    my $get_plugins = sub {
84
        my $methods = [
85
            {
86
                auth_client_get_user => sub {
87
                    $_[1]->{mapped_data}->{firstname} = 'test name modified 1';
88
                    return;
89
                },
90
                retrieve_data => sub { return $_[1] eq 'priority' ? 2 : undef; }
91
            },
92
            {
93
                auth_client_get_user => sub {
94
                    $_[1]->{mapped_data}->{firstname} = 'test name modified 2';
95
                    return;
96
                },
97
                retrieve_data => sub { return $_[1] eq 'priority' ? 1 : undef; }
98
            }
99
        ];
100
        my @plugins;
101
        foreach my $method ( @{$methods} ) {
102
            my $plugin = Test::MockObject->new;
103
            foreach my $name ( keys %{$method} ) {
104
                $plugin->mock( $name, $method->{$name} );
105
            }
106
            push @plugins, $plugin;
107
        }
108
        return @plugins;
109
    };
110
    my $plugins_module = Test::MockModule->new('Koha::Plugins');
111
    $plugins_module->mock( 'GetPlugins',          $get_plugins );
112
    $plugins_module->mock( 'get_enabled_plugins', $get_plugins );
113
    ( $resolved_patron, $mapped_data, $resolved_domain ) =
114
        $client->get_user( { provider => $provider->code, data => $data, interface => 'opac' } );
115
    is(
116
        $mapped_data->{firstname},
117
        'test name modified 1',
118
        'Data modified correctly by plugins'
119
    );
120
80
    $schema->storage->txn_rollback;
121
    $schema->storage->txn_rollback;
81
122
82
};
123
};
83
- 

Return to bug 36503