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

(-)a/C4/Auth_with_shibboleth.pm (-3 / +8 lines)
Lines 103-111 sub checkpw_shib { Link Here
103
    $debug and warn "User Shibboleth-authenticated as: $match";
103
    $debug and warn "User Shibboleth-authenticated as: $match";
104
104
105
    # Does the given shibboleth attribute value ($match) match a valid koha user ?
105
    # Does the given shibboleth attribute value ($match) match a valid koha user ?
106
    my $borrower =
106
    my $borrowers = Koha::Patrons->search( { $config->{matchpoint} => $match } );
107
      Koha::Database->new()->schema()->resultset('Borrower')
107
    if ( $borrowers->count > 1 ){
108
      ->find( { $config->{matchpoint} => $match } );
108
        # If we have more than 1 borrower the matchpoint is not unique
109
        # we cannot know which patron is the correct one, so we should fail
110
         $debug and warn "There are several users with $config->{matchpoint} of $match, matchpoints must be unique";
111
        return 0;
112
    }
113
    my $borrower = $borrowers->next;
109
    if ( defined($borrower) ) {
114
    if ( defined($borrower) ) {
110
        if ($config->{'sync'}) {
115
        if ($config->{'sync'}) {
111
            _sync($borrower->borrowernumber, $config, $match);
116
            _sync($borrower->borrowernumber, $config, $match);
(-)a/t/Auth_with_shibboleth.t (-4 / +28 lines)
Lines 166-172 subtest "get_login_shib tests" => sub { Link Here
166
166
167
## checkpw_shib
167
## checkpw_shib
168
subtest "checkpw_shib tests" => sub {
168
subtest "checkpw_shib tests" => sub {
169
    plan tests => 21;
169
    plan tests => 24;
170
170
171
    my $shib_login;
171
    my $shib_login;
172
    my ( $retval, $retcard, $retuserid );
172
    my ( $retval, $retcard, $retuserid );
Lines 174-181 subtest "checkpw_shib tests" => sub { Link Here
174
    # Setup Mock Database Data
174
    # Setup Mock Database Data
175
    fixtures_ok [
175
    fixtures_ok [
176
        'Borrower' => [
176
        'Borrower' => [
177
            [qw/cardnumber userid surname address city/],
177
            [qw/cardnumber userid surname address city email/],
178
            [qw/testcardnumber test1234 renvoize myaddress johnston/],
178
            [qw/testcardnumber test1234 renvoize myaddress johnston  /],
179
            [qw/testcardnumber1 test12345 clamp1 myaddress quechee kid@clamp.io/],
180
            [qw/testcardnumber2 test123456 clamp2 myaddress quechee kid@clamp.io/],
179
        ],
181
        ],
180
        'Category' => [ [qw/categorycode default_privacy/], [qw/S never/], ]
182
        'Category' => [ [qw/categorycode default_privacy/], [qw/S never/], ]
181
      ],
183
      ],
Lines 202-207 subtest "checkpw_shib tests" => sub { Link Here
202
    [], "bad user with no debug";
204
    [], "bad user with no debug";
203
    is( $retval, "0", "user not authenticated" );
205
    is( $retval, "0", "user not authenticated" );
204
206
207
    # duplicated matchpoint
208
    $matchpoint = 'email';
209
    $mapping{'email'} = { is => 'email' };
210
    $shib_login = 'kid@clamp.io';
211
    warnings_are {
212
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
213
    }
214
    [], "bad user with no debug";
215
    is( $retval, "0", "user not authenticated if duplicated matchpoint" );
216
    $C4::Auth_with_shibboleth::debug = '1';
217
    warnings_are {
218
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
219
    }
220
    [
221
        q/checkpw_shib/,
222
        q/koha borrower field to match: email/,
223
        q/shibboleth attribute to match: email/,
224
        q/User Shibboleth-authenticated as: kid@clamp.io/,
225
        q/There are several users with email of kid@clamp.io, matchpoints must be unique/
226
    ], "duplicated matchpoint warned with debug";
227
    $C4::Auth_with_shibboleth::debug = '0';
228
    reset_config();
229
205
    # autocreate user
230
    # autocreate user
206
    $autocreate  = 1;
231
    $autocreate  = 1;
207
    $shib_login  = 'test4321';
232
    $shib_login  = 'test4321';
208
- 

Return to bug 24065