3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Test::More tests => 6;
23 use JSON qw(encode_json);
24 use MIME::Base64 qw{ encode_base64url };
27 use t::lib::TestBuilder;
30 # Mock pluginsdir before loading Plugins module
31 my $path = dirname(__FILE__) . '/../../../../lib/plugins';
32 t::lib::Mocks::mock_config( 'pluginsdir', $path );
34 use_ok('Koha::Plugins');
35 use_ok('Koha::Plugins::Handler');
36 use_ok('Koha::Plugin::Test');
37 use_ok('Koha::Auth::Client');
38 use_ok('Koha::Auth::Client::OAuth');
41 my $schema = Koha::Database->new->schema;
42 my $builder = t::lib::TestBuilder->new;
44 t::lib::Mocks::mock_config( 'enable_plugins', 1 );
46 subtest 'auth_client_get_user hook tests' => sub {
50 $schema->storage->txn_begin;
52 my $plugins = Koha::Plugins->new;
53 $plugins->InstallPlugins;
55 # Test Plugin manipulates mapped_data
56 my $plugin = Koha::Plugin::Test->new->enable;
58 my $client = Koha::Auth::Client::OAuth->new;
60 $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } );
61 my $domain = $builder->build_object(
63 class => 'Koha::Auth::Identity::Provider::Domains',
65 identity_provider_id => $provider->id, domain => '', update_on_auth => 0, allow_opac => 1,
70 my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'patron@test.com' } } );
72 email => 'electronic_mail',
73 firstname => 'given_name',
74 surname => 'family_name',
75 cardnumber => 'cardnumber',
77 $provider->set_mapping($mapping)->store;
79 my $id_token = 'header.' . encode_base64url(
82 electronic_mail => 'patron@test.com',
83 given_name => 'test name',
84 cardnumber => 'kit:12345',
89 my $data = { id_token => $id_token };
91 my ( $resolved_patron, $mapped_data, $resolved_domain ) =
92 $client->get_user( { provider => $provider->code, data => $data, interface => 'opac' } );
93 is( $mapped_data->{cardnumber}, '12345', 'Plugin manipulated mapped_data successfully' );
94 isnt( $resolved_patron->borrowernumber, $patron->borrowernumber, 'Plugin changed the resolved patron' );
95 isnt( $resolved_domain->domain, $domain->domain, 'Plugin changed the resolved domain' );
97 Koha::Plugins->RemovePlugins;
98 $schema->storage->txn_rollback;