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

(-)a/C4/Auth_with_shibboleth.pm (+19 lines)
Lines 27-32 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::MoreUtils qw(any);
30
31
31
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
32
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
32
33
Lines 101-106 sub checkpw_shib { Link Here
101
      Koha::Database->new()->schema()->resultset('Borrower')
102
      Koha::Database->new()->schema()->resultset('Borrower')
102
      ->find( { $config->{matchpoint} => $match } );
103
      ->find( { $config->{matchpoint} => $match } );
103
    if ( defined($borrower) ) {
104
    if ( defined($borrower) ) {
105
        if ($config->{'sync'}) {
106
            _sync($borrower->borrowernumber, $config, $match);
107
        }
104
        return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') );
108
        return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') );
105
    }
109
    }
106
110
Lines 128-133 sub _autocreate { Link Here
128
    return ( 1, $patron->cardnumber, $patron->userid );
132
    return ( 1, $patron->cardnumber, $patron->userid );
129
}
133
}
130
134
135
sub _sync {
136
    my ($borrowernumber, $config, $match ) = @_;
137
    my %borrower;
138
    $borrower{'borrowernumber'} = $borrowernumber;
139
    while ( my ( $key, $entry ) = each %{$config->{'mapping'}} ) {
140
        if ( any { /(^psgi|^plack)/i } keys %ENV ) {
141
            $borrower{$key} = ( $entry->{'is'} && $ENV{"HTTP_" . uc($entry->{'is'}) } ) || $entry->{'content'} || '';
142
        } else {
143
            $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
144
        }
145
    }
146
    my $patron = Koha::Patrons->find( $borrowernumber );
147
    $patron->set(\%borrower)->store;
148
}
149
131
sub _get_uri {
150
sub _get_uri {
132
151
133
    my $protocol = "https://";
152
    my $protocol = "https://";
(-)a/t/Auth_with_shibboleth.t (-2 / +20 lines)
Lines 39-44 use Test::DBIx::Class; Link Here
39
# Mock Variables
39
# Mock Variables
40
my $matchpoint = 'userid';
40
my $matchpoint = 'userid';
41
my $autocreate = 0;
41
my $autocreate = 0;
42
my $sync = 0;
42
my %mapping    = (
43
my %mapping    = (
43
    'userid'       => { 'is' => 'uid' },
44
    'userid'       => { 'is' => 'uid' },
44
    'surname'      => { 'is' => 'sn' },
45
    'surname'      => { 'is' => 'sn' },
Lines 156-162 subtest "get_login_shib tests" => sub { Link Here
156
157
157
## checkpw_shib
158
## checkpw_shib
158
subtest "checkpw_shib tests" => sub {
159
subtest "checkpw_shib tests" => sub {
159
    plan tests => 18;
160
    plan tests => 21;
160
161
161
    my $shib_login;
162
    my $shib_login;
162
    my ( $retval, $retcard, $retuserid );
163
    my ( $retval, $retcard, $retuserid );
Lines 214-219 subtest "checkpw_shib tests" => sub { Link Here
214
      'Found $new_users surname';
215
      'Found $new_users surname';
215
    $autocreate = 0;
216
    $autocreate = 0;
216
217
218
    # sync user
219
    $sync = 1;
220
    $ENV{'city'} = 'AnotherCity';
221
    warnings_are {
222
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
223
    }
224
    [], "good user with sync";
225
226
    ok my $sync_user = ResultSet('Borrower')
227
      ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "sync user found";
228
229
    is_fields [qw/surname dateexpiry address city/], $sync_user->next,
230
      [qw/pika 2017 Address AnotherCity/],
231
      'Found $sync_user synced city';
232
    $sync = 0;
233
217
    # debug on
234
    # debug on
218
    $C4::Auth_with_shibboleth::debug = '1';
235
    $C4::Auth_with_shibboleth::debug = '1';
219
236
Lines 280-285 sub mockedConfig { Link Here
280
297
281
    my %shibboleth = (
298
    my %shibboleth = (
282
        'autocreate' => $autocreate,
299
        'autocreate' => $autocreate,
300
        'sync'       => $sync,
283
        'matchpoint' => $matchpoint,
301
        'matchpoint' => $matchpoint,
284
        'mapping'    => \%mapping
302
        'mapping'    => \%mapping
285
    );
303
    );
Lines 306-311 sub mockedSchema { Link Here
306
sub reset_config {
324
sub reset_config {
307
    $matchpoint = 'userid';
325
    $matchpoint = 'userid';
308
    $autocreate = 0;
326
    $autocreate = 0;
327
    $sync = 0;
309
    %mapping    = (
328
    %mapping    = (
310
        'userid'       => { 'is' => 'uid' },
329
        'userid'       => { 'is' => 'uid' },
311
        'surname'      => { 'is' => 'sn' },
330
        'surname'      => { 'is' => 'sn' },
312
- 

Return to bug 18507