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

(-)a/t/Auth_with_shibboleth.t (-27 / +68 lines)
Lines 47-53 use Test::DBIx::Class { Link Here
47
# Mock Variables
47
# Mock Variables
48
my $matchpoint = 'userid';
48
my $matchpoint = 'userid';
49
my $autocreate = 0;
49
my $autocreate = 0;
50
my $sync = 0;
50
my $welcome    = 0;
51
my $sync       = 0;
51
my %mapping    = (
52
my %mapping    = (
52
    'userid'       => { 'is' => 'uid' },
53
    'userid'       => { 'is' => 'uid' },
53
    'surname'      => { 'is' => 'sn' },
54
    'surname'      => { 'is' => 'sn' },
Lines 55-67 my %mapping = ( Link Here
55
    'categorycode' => { 'is' => 'cat' },
56
    'categorycode' => { 'is' => 'cat' },
56
    'address'      => { 'is' => 'add' },
57
    'address'      => { 'is' => 'add' },
57
    'city'         => { 'is' => 'city' },
58
    'city'         => { 'is' => 'city' },
59
    'emailpro'     => { 'is' => 'emailpro' },
58
);
60
);
59
$ENV{'uid'}  = "test1234";
61
$ENV{'uid'}      = "test1234";
60
$ENV{'sn'}   = undef;
62
$ENV{'sn'}       = undef;
61
$ENV{'exp'}  = undef;
63
$ENV{'exp'}      = undef;
62
$ENV{'cat'}  = undef;
64
$ENV{'cat'}      = undef;
63
$ENV{'add'}  = undef;
65
$ENV{'add'}      = undef;
64
$ENV{'city'} = undef;
66
$ENV{'city'}     = undef;
67
$ENV{'emailpro'} = undef;
65
68
66
# Setup Mocks
69
# Setup Mocks
67
## Mock Context
70
## Mock Context
Lines 88-93 my $database = Test::MockModule->new('Koha::Database'); Link Here
88
### Mock ->schema
91
### Mock ->schema
89
$database->mock( 'schema', \&mockedSchema );
92
$database->mock( 'schema', \&mockedSchema );
90
93
94
### Mock Letters
95
my $mocked_letters = Test::MockModule->new('C4::Letters');
96
# we want to test the params
97
$mocked_letters->mock( 'GetPreparedLetter', sub {
98
    warn "GetPreparedLetter called";
99
    return 1;
100
});
101
# we don't care about EnqueueLetter for now
102
$mocked_letters->mock( 'EnqueueLetter', sub {
103
    warn "EnqueueLetter called";
104
    # return a 'message_id'
105
    return 42;
106
});
107
# we don't care about EnqueueLetter for now
108
$mocked_letters->mock( 'SendQueuedMessages', sub {
109
    my $params = shift;
110
    warn "SendQueuedMessages called with message_id: $params->{message_id}";
111
    return 1;
112
});
113
91
# Tests
114
# Tests
92
##############################################################
115
##############################################################
93
116
Lines 192-198 subtest "get_login_shib tests" => sub { Link Here
192
## checkpw_shib
215
## checkpw_shib
193
subtest "checkpw_shib tests" => sub {
216
subtest "checkpw_shib tests" => sub {
194
217
195
    plan tests => 33;
218
    plan tests => 34;
196
219
197
    my $shib_login;
220
    my $shib_login;
198
    my ( $retval, $retcard, $retuserid );
221
    my ( $retval, $retcard, $retuserid );
Lines 247-263 subtest "checkpw_shib tests" => sub { Link Here
247
270
248
    reset_config();
271
    reset_config();
249
272
250
    # autocreate user
273
    # autocreate user (welcome)
251
    $autocreate  = 1;
274
    $autocreate      = 1;
252
    $shib_login  = 'test4321';
275
    $welcome         = 1;
253
    $ENV{'uid'}  = 'test4321';
276
    $shib_login      = 'test4321';
254
    $ENV{'sn'}   = "pika";
277
    $ENV{'uid'}      = 'test4321';
255
    $ENV{'exp'}  = "2017";
278
    $ENV{'sn'}       = "pika";
256
    $ENV{'cat'}  = "S";
279
    $ENV{'exp'}      = "2017";
257
    $ENV{'add'}  = 'Address';
280
    $ENV{'cat'}      = "S";
258
    $ENV{'city'} = 'City';
281
    $ENV{'add'}      = 'Address';
259
282
    $ENV{'city'}     = 'City';
260
    ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
283
    $ENV{'emailpro'} = 'me@myemail.com';
284
285
    warnings_are {
286
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
287
    }
288
    [
289
        'GetPreparedLetter called',
290
        'EnqueueLetter called',
291
        'SendQueuedMessages called with message_id: 42'
292
    ],
293
      "WELCOME notice Prepared, Enqueued and Send";
261
    is( $retval,    "1",        "user authenticated" );
294
    is( $retval,    "1",        "user authenticated" );
262
    is( $retuserid, "test4321", "expected userid returned" );
295
    is( $retuserid, "test4321", "expected userid returned" );
263
    $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info")
296
    $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info")
Lines 270-275 subtest "checkpw_shib tests" => sub { Link Here
270
      [qw/pika 2017 Address City/],
303
      [qw/pika 2017 Address City/],
271
      'Found $new_users surname';
304
      'Found $new_users surname';
272
    $autocreate = 0;
305
    $autocreate = 0;
306
    $welcome    = 0;
273
307
274
    # sync user
308
    # sync user
275
    $sync = 1;
309
    $sync = 1;
Lines 364-369 sub mockedConfig { Link Here
364
398
365
    my %shibboleth = (
399
    my %shibboleth = (
366
        'autocreate' => $autocreate,
400
        'autocreate' => $autocreate,
401
        'welcome'    => $welcome,
367
        'sync'       => $sync,
402
        'sync'       => $sync,
368
        'matchpoint' => $matchpoint,
403
        'matchpoint' => $matchpoint,
369
        'mapping'    => \%mapping
404
        'mapping'    => \%mapping
Lines 384-389 sub mockedPref { Link Here
384
        $return = $staffClientBaseURL;
419
        $return = $staffClientBaseURL;
385
    }
420
    }
386
421
422
    if ( $param eq 'AutoEmailPrimaryAddress' ) {
423
        $return = 'OFF';
424
    }
425
387
    return $return;
426
    return $return;
388
}
427
}
389
428
Lines 399-419 sub mockedSchema { Link Here
399
sub reset_config {
438
sub reset_config {
400
    $matchpoint = 'userid';
439
    $matchpoint = 'userid';
401
    $autocreate = 0;
440
    $autocreate = 0;
441
    $welcome = 0;
402
    $sync = 0;
442
    $sync = 0;
403
    %mapping    = (
443
    %mapping = (
404
        'userid'       => { 'is' => 'uid' },
444
        'userid'       => { 'is' => 'uid' },
405
        'surname'      => { 'is' => 'sn' },
445
        'surname'      => { 'is' => 'sn' },
406
        'dateexpiry'   => { 'is' => 'exp' },
446
        'dateexpiry'   => { 'is' => 'exp' },
407
        'categorycode' => { 'is' => 'cat' },
447
        'categorycode' => { 'is' => 'cat' },
408
        'address'      => { 'is' => 'add' },
448
        'address'      => { 'is' => 'add' },
409
        'city'         => { 'is' => 'city' },
449
        'city'         => { 'is' => 'city' },
450
        'emailpro'     => { 'is' => 'emailpro' },
410
    );
451
    );
411
    $ENV{'uid'}  = "test1234";
452
    $ENV{'uid'}      = "test1234";
412
    $ENV{'sn'}   = undef;
453
    $ENV{'sn'}       = undef;
413
    $ENV{'exp'}  = undef;
454
    $ENV{'exp'}      = undef;
414
    $ENV{'cat'}  = undef;
455
    $ENV{'cat'}      = undef;
415
    $ENV{'add'}  = undef;
456
    $ENV{'add'}      = undef;
416
    $ENV{'city'} = undef;
457
    $ENV{'city'}     = undef;
458
    $ENV{'emailpro'} = undef;
417
459
418
    return 1;
460
    return 1;
419
}
461
}
420
- 

Return to bug 30646