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

(-)a/C4/Auth_with_shibboleth.pm (-1 / +19 lines)
Lines 27-33 use Koha::Patrons; Link Here
27
use C4::Members::Messaging;
27
use C4::Members::Messaging;
28
use Carp;
28
use Carp;
29
use CGI;
29
use CGI;
30
use List::Util qw(any);
30
use List::MoreUtils qw(any);
31
31
32
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
32
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
33
33
Lines 107-112 sub checkpw_shib { Link Here
107
      Koha::Database->new()->schema()->resultset('Borrower')
107
      Koha::Database->new()->schema()->resultset('Borrower')
108
      ->find( { $config->{matchpoint} => $match } );
108
      ->find( { $config->{matchpoint} => $match } );
109
    if ( defined($borrower) ) {
109
    if ( defined($borrower) ) {
110
        if ($config->{'sync'}) {
111
            _sync($borrower->borrowernumber, $config, $match);
112
        }
110
        return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') );
113
        return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') );
111
    }
114
    }
112
115
Lines 138-143 sub _autocreate { Link Here
138
    return ( 1, $patron->cardnumber, $patron->userid );
141
    return ( 1, $patron->cardnumber, $patron->userid );
139
}
142
}
140
143
144
sub _sync {
145
    my ($borrowernumber, $config, $match ) = @_;
146
    my %borrower;
147
    $borrower{'borrowernumber'} = $borrowernumber;
148
    while ( my ( $key, $entry ) = each %{$config->{'mapping'}} ) {
149
        if ( any { /(^psgi|^plack)/i } keys %ENV ) {
150
            $borrower{$key} = ( $entry->{'is'} && $ENV{"HTTP_" . uc($entry->{'is'}) } ) || $entry->{'content'} || '';
151
        } else {
152
            $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
153
        }
154
    }
155
    my $patron = Koha::Patrons->find( $borrowernumber );
156
    $patron->set(\%borrower)->store;
157
}
158
141
sub _get_uri {
159
sub _get_uri {
142
160
143
    my $protocol = "https://";
161
    my $protocol = "https://";
(-)a/t/Auth_with_shibboleth.t (-2 / +20 lines)
Lines 43-48 use Test::DBIx::Class { Link Here
43
# Mock Variables
43
# Mock Variables
44
my $matchpoint = 'userid';
44
my $matchpoint = 'userid';
45
my $autocreate = 0;
45
my $autocreate = 0;
46
my $sync = 0;
46
my %mapping    = (
47
my %mapping    = (
47
    'userid'       => { 'is' => 'uid' },
48
    'userid'       => { 'is' => 'uid' },
48
    'surname'      => { 'is' => 'sn' },
49
    'surname'      => { 'is' => 'sn' },
Lines 165-171 subtest "get_login_shib tests" => sub { Link Here
165
166
166
## checkpw_shib
167
## checkpw_shib
167
subtest "checkpw_shib tests" => sub {
168
subtest "checkpw_shib tests" => sub {
168
    plan tests => 18;
169
    plan tests => 21;
169
170
170
    my $shib_login;
171
    my $shib_login;
171
    my ( $retval, $retcard, $retuserid );
172
    my ( $retval, $retcard, $retuserid );
Lines 223-228 subtest "checkpw_shib tests" => sub { Link Here
223
      'Found $new_users surname';
224
      'Found $new_users surname';
224
    $autocreate = 0;
225
    $autocreate = 0;
225
226
227
    # sync user
228
    $sync = 1;
229
    $ENV{'city'} = 'AnotherCity';
230
    warnings_are {
231
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
232
    }
233
    [], "good user with sync";
234
235
    ok my $sync_user = ResultSet('Borrower')
236
      ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "sync user found";
237
238
    is_fields [qw/surname dateexpiry address city/], $sync_user->next,
239
      [qw/pika 2017 Address AnotherCity/],
240
      'Found $sync_user synced city';
241
    $sync = 0;
242
226
    # debug on
243
    # debug on
227
    $C4::Auth_with_shibboleth::debug = '1';
244
    $C4::Auth_with_shibboleth::debug = '1';
228
245
Lines 315-320 sub mockedConfig { Link Here
315
332
316
    my %shibboleth = (
333
    my %shibboleth = (
317
        'autocreate' => $autocreate,
334
        'autocreate' => $autocreate,
335
        'sync'       => $sync,
318
        'matchpoint' => $matchpoint,
336
        'matchpoint' => $matchpoint,
319
        'mapping'    => \%mapping
337
        'mapping'    => \%mapping
320
    );
338
    );
Lines 349-354 sub mockedSchema { Link Here
349
sub reset_config {
367
sub reset_config {
350
    $matchpoint = 'userid';
368
    $matchpoint = 'userid';
351
    $autocreate = 0;
369
    $autocreate = 0;
370
    $sync = 0;
352
    %mapping    = (
371
    %mapping    = (
353
        'userid'       => { 'is' => 'uid' },
372
        'userid'       => { 'is' => 'uid' },
354
        'surname'      => { 'is' => 'sn' },
373
        'surname'      => { 'is' => 'sn' },
355
- 

Return to bug 18507