From d1558be5ffefa062c8898ccfb24103830d3eaa16 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Wed, 16 Nov 2016 10:37:48 +0000 Subject: [PATCH] Bug 17615 - Fix updating borrower attributes in checkpw_ldap --- C4/Auth_with_ldap.pm | 2 +- t/db_dependent/Auth_with_ldap.t | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 03e81e1..a58f4e6 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -222,7 +222,7 @@ sub checkpw_ldap { next; } if (C4::Members::Attributes::CheckUniqueness($code, $borrower{$code}, $borrowernumber)) { - C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, {code => $code, value => $borrower{$code}}); + C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, {code => $code, attribute => $borrower{$code}}); } else { warn "ERROR_extended_unique_id_failed $code $borrower{$code}"; } diff --git a/t/db_dependent/Auth_with_ldap.t b/t/db_dependent/Auth_with_ldap.t index 446982c..8c4b9ba 100755 --- a/t/db_dependent/Auth_with_ldap.t +++ b/t/db_dependent/Auth_with_ldap.t @@ -20,6 +20,7 @@ use Modern::Perl; use Test::More tests => 4; use Test::MockModule; use Test::MockObject; +use t::lib::Mocks; use t::lib::TestBuilder; use Test::Warn; @@ -27,8 +28,12 @@ use C4::Context; use Koha::Patrons; -my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; +my $dbh = ''; + +# Start transaction +my $database = Koha::Database->new(); +my $schema = $database->schema(); +$schema->storage->txn_begin(); my $builder = t::lib::TestBuilder->new(); @@ -80,6 +85,14 @@ my $attr_type = $builder->build( } } ); +my $attr_type2 = $builder->build( + { + source => 'BorrowerAttributeType', + value => { + category_code => $categorycode + } + } +); my $borrower = $builder->build( { @@ -131,7 +144,7 @@ subtest 'checkpw_ldap tests' => sub { subtest 'auth_by_bind = 1 tests' => sub { - plan tests => 8; + plan tests => 9; $auth_by_bind = 1; @@ -158,6 +171,7 @@ subtest 'checkpw_ldap tests' => sub { $update = 1; reload_ldap_module(); + t::lib::Mocks::mock_preference( 'ExtendedPatronAttributes', 1 ); my $auth = Test::MockModule->new('C4::Auth_with_ldap'); $auth->mock( 'update_local', @@ -165,6 +179,14 @@ subtest 'checkpw_ldap tests' => sub { return $borrower->{cardnumber}; } ); + $auth->mock( + 'ldap_entry_2_hash', + sub { + return ( + $attr_type2->{code}, 'BAR' + ); + } + ); C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey' ); ok( @@ -175,7 +197,10 @@ subtest 'checkpw_ldap tests' => sub { }, 'Extended attributes are not deleted' ); + + is( C4::Members::Attributes::GetBorrowerAttributeValue($borrower->{borrowernumber}, $attr_type2->{code}), 'BAR', 'Mapped attribute is BAR' ); $auth->unmock('update_local'); + $auth->unmock('ldap_entry_2_hash'); $update = 0; $desired_count_result = 0; # user auth problem @@ -506,6 +531,6 @@ sub reload_ldap_module { return; } -$schema->storage->txn_rollback; +$schema->storage->txn_rollback(); 1; -- 2.7.4