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

(-)a/C4/Auth_with_ldap.pm (-12 / +7 lines)
Lines 207-231 sub checkpw_ldap { Link Here
207
        return 0;   # B2, D2
207
        return 0;   # B2, D2
208
    }
208
    }
209
    if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) {
209
    if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) {
210
        my @extended_patron_attributes;
211
        foreach my $attribute_type ( C4::Members::AttributeTypes::GetAttributeTypes() ) {
210
        foreach my $attribute_type ( C4::Members::AttributeTypes::GetAttributeTypes() ) {
212
            my $code = $attribute_type->{code};
211
            my $code = $attribute_type->{code};
213
            if ( exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { # skip empty values
212
            unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) {
214
                push @extended_patron_attributes, { code => $code, value => $borrower{$code} };
213
                next;
215
            }
214
            }
216
        }
215
217
        #Check before add
216
            if (C4::Members::Attributes::CheckUniqueness($code, $borrower{$code}, $borrowernumber)) {
218
        my @unique_attr;
217
                C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, {code => $code, value => $borrower{$code}});
219
        foreach my $attr ( @extended_patron_attributes ) {
220
            if (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) {
221
                push @unique_attr, $attr;
222
            } else {
218
            } else {
223
                warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}";
219
                warn "ERROR_extended_unique_id_failed $code $borrower{$code}";
224
            }
220
            }
225
        }
221
        }
226
        C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, \@unique_attr);
227
    }
222
    }
228
return(1, $cardnumber, $userid);
223
    return(1, $cardnumber, $userid);
229
}
224
}
230
225
231
# Pass LDAP entry object and local cardnumber (userid).
226
# Pass LDAP entry object and local cardnumber (userid).
(-)a/t/db_dependent/Auth_with_ldap.t (-3 / +46 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Test::More tests => 4;
20
use Test::More tests => 4;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::MockObject;
22
use Test::MockObject;
23
use t::lib::TestBuilder;
23
use Test::Warn;
24
use Test::Warn;
24
25
25
use C4::Context;
26
use C4::Context;
Lines 29-34 my $dbh = C4::Context->dbh; Link Here
29
$dbh->{ AutoCommit } = 0;
30
$dbh->{ AutoCommit } = 0;
30
$dbh->{ RaiseError } = 1;
31
$dbh->{ RaiseError } = 1;
31
32
33
my $builder = t::lib::TestBuilder->new();
34
32
# Variables controlling LDAP server config
35
# Variables controlling LDAP server config
33
my $update         = 0;
36
my $update         = 0;
34
my $replicate      = 0;
37
my $replicate      = 0;
Lines 61-66 $ldap->mock( 'new', sub { Link Here
61
    }
64
    }
62
});
65
});
63
66
67
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
68
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
69
my $attrType = $builder->build({
70
    source => 'BorrowerAttributeType',
71
    value => {
72
        category_code => $categorycode
73
    }
74
});
75
76
my $borrower = $builder->build({
77
    source => 'Borrower',
78
    value => {
79
        userid => 'hola',
80
        branchcode   => $branchcode,
81
        categorycode => $categorycode
82
    }
83
});
84
85
$builder->build({
86
    source => 'BorrowerAttribute',
87
    value => {
88
        borrowernumber => $borrower->{borrowernumber},
89
        code => $attrType->{code},
90
        attribute => 'FOO'
91
    }
92
});
64
93
65
# C4::Auth_with_ldap needs several stuff set first ^^^
94
# C4::Auth_with_ldap needs several stuff set first ^^^
66
use_ok( 'C4::Auth_with_ldap' );
95
use_ok( 'C4::Auth_with_ldap' );
Lines 84-90 subtest "checkpw_ldap tests" => sub { Link Here
84
113
85
    subtest "auth_by_bind = 1 tests" => sub {
114
    subtest "auth_by_bind = 1 tests" => sub {
86
115
87
        plan tests => 7;
116
        plan tests => 8;
88
117
89
        $auth_by_bind          = 1;
118
        $auth_by_bind          = 1;
90
119
Lines 105-112 subtest "checkpw_ldap tests" => sub { Link Here
105
        $anonymous_bind        = 1;
134
        $anonymous_bind        = 1;
106
        $desired_bind_result   = 'success';
135
        $desired_bind_result   = 'success';
107
        $desired_search_result = 'success';
136
        $desired_search_result = 'success';
108
        $desired_count_result  = 0; # user auth problem
137
        $desired_count_result  = 1;
109
        $non_anonymous_bind_result = 'success';
138
        $non_anonymous_bind_result = 'success';
139
        $update = 1;
140
        reload_ldap_module();
141
142
        my $auth = new Test::MockModule('C4::Auth_with_ldap');
143
        $auth->mock( 'update_local', sub {
144
                return $borrower->{cardnumber};
145
        });
146
147
        C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey');
148
        ok(@{ C4::Members::Attributes::GetBorrowerAttributes($borrower->{borrowernumber}) }, 'Extended attributes are not deleted');
149
        $auth->unmock('update_local');
150
151
        $update = 0;
152
        $desired_count_result = 0; # user auth problem
153
        C4::Members::DelMember($borrower->{borrowernumber});
110
        reload_ldap_module();
154
        reload_ldap_module();
111
        is ( C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey' ),
155
        is ( C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey' ),
112
            0, "checkpw_ldap returns 0 if user lookup returns 0");
156
            0, "checkpw_ldap returns 0 if user lookup returns 0");
113
- 

Return to bug 15889