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

(-)a/t/Auth_with_shibboleth.t (-58 / +32 lines)
Lines 16-48 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
20
20
$| = 1;
21
use Test::More tests => 18;
21
use Module::Load::Conditional qw/check_install/;
22
use Test::More;
23
use Test::MockModule;
22
use Test::MockModule;
24
use Test::Warn;
23
use Test::Warn;
24
use CGI qw(-utf8 );
25
use File::Temp qw(tempdir);
25
use File::Temp qw(tempdir);
26
26
27
use t::lib::Mocks::Logger;
27
use t::lib::Mocks::Logger;
28
use t::lib::TestBuilder;
28
29
29
use utf8;
30
use CGI qw(-utf8 );
31
use C4::Context;
30
use C4::Context;
31
use Koha::Database;
32
32
33
BEGIN {
33
my $schema = Koha::Database->new->schema;
34
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
34
$schema->storage->txn_begin;
35
        plan tests => 18;
35
my $builder = t::lib::TestBuilder->new;
36
    }
37
    else {
38
        plan skip_all => "Need Test::DBIx::Class";
39
    }
40
}
41
42
use Test::DBIx::Class {
43
    schema_class => 'Koha::Schema',
44
    connect_info => [ 'dbi:SQLite:dbname=:memory:', '', '' ]
45
};
46
36
47
# Mock Variables
37
# Mock Variables
48
my $matchpoint = 'userid';
38
my $matchpoint = 'userid';
Lines 85-96 $context->mock( 'timezone', sub { return 'local'; } ); Link Here
85
my $interface = 'opac';
75
my $interface = 'opac';
86
$context->mock( 'interface', \&mockedInterface );
76
$context->mock( 'interface', \&mockedInterface );
87
77
88
## Mock Database
89
my $database = Test::MockModule->new('Koha::Database');
90
91
### Mock ->schema
92
$database->mock( 'schema', \&mockedSchema );
93
94
### Mock Letters
78
### Mock Letters
95
my $mocked_letters = Test::MockModule->new('C4::Letters');
79
my $mocked_letters = Test::MockModule->new('C4::Letters');
96
# we want to test the params
80
# we want to test the params
Lines 147-157 subtest "shib_ok tests" => sub { Link Here
147
    reset_config();
131
    reset_config();
148
};
132
};
149
133
150
## logout_shib
151
#my $query = CGI->new();
152
#is(logout_shib($query),"https://".$opac."/Shibboleth.sso/Logout?return="."https://".$opac,"logout_shib");
153
154
## login_shib_url
155
subtest "login_shib_url tests" => sub {
134
subtest "login_shib_url tests" => sub {
156
    plan tests => 2;
135
    plan tests => 2;
157
136
Lines 214-236 subtest "get_login_shib tests" => sub { Link Here
214
193
215
## checkpw_shib
194
## checkpw_shib
216
subtest "checkpw_shib tests" => sub {
195
subtest "checkpw_shib tests" => sub {
217
196
    plan tests => 33;
218
    plan tests => 34;
219
197
220
    my $shib_login;
198
    my $shib_login;
221
    my ( $retval, $retcard, $retuserid );
199
    my ( $retval, $retcard, $retuserid );
222
200
223
    # Setup Mock Database Data
201
    # Test borrower data
224
    fixtures_ok [
202
    my $test_borrowers = [
225
        'Borrower' => [
203
        { cardnumber => 'testcardnumber', userid => 'test1234', surname => 'renvoize', address => 'myaddress', city => 'johnston', email => undef },
226
            [qw/cardnumber userid surname address city email/],
204
        { cardnumber => 'testcardnumber1', userid => 'test12345', surname => 'clamp1', address => 'myaddress', city => 'quechee', email => 'kid@clamp.io' },
227
            [qw/testcardnumber test1234 renvoize myaddress johnston  /],
205
        { cardnumber => 'testcardnumber2', userid => 'test123456', surname => 'clamp2', address => 'myaddress', city => 'quechee', email => 'kid@clamp.io' },
228
            [qw/testcardnumber1 test12345 clamp1 myaddress quechee kid@clamp.io/],
206
    ];
229
            [qw/testcardnumber2 test123456 clamp2 myaddress quechee kid@clamp.io/],
207
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { default_privacy => 'never' }});
230
        ],
208
    $builder->build_object({ class => 'Koha::Patrons', value => { %$_, categorycode => $category->categorycode }}) for @$test_borrowers;
231
        'Category' => [ [qw/categorycode default_privacy/], [qw/S never/], ]
209
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
232
      ],
233
      'Installed some custom fixtures via the Populate fixture class';
234
210
235
    # good user
211
    # good user
236
    $shib_login = "test1234";
212
    $shib_login = "test1234";
Lines 276-286 subtest "checkpw_shib tests" => sub { Link Here
276
    $shib_login      = 'test4321';
252
    $shib_login      = 'test4321';
277
    $ENV{'uid'}      = 'test4321';
253
    $ENV{'uid'}      = 'test4321';
278
    $ENV{'sn'}       = "pika";
254
    $ENV{'sn'}       = "pika";
279
    $ENV{'exp'}      = "2017";
255
    $ENV{'exp'}      = "2017-01-01";
280
    $ENV{'cat'}      = "S";
256
    $ENV{'cat'}      = $category->categorycode;
281
    $ENV{'add'}      = 'Address';
257
    $ENV{'add'}      = 'Address';
282
    $ENV{'city'}     = 'City';
258
    $ENV{'city'}     = 'City';
283
    $ENV{'emailpro'} = 'me@myemail.com';
259
    $ENV{'emailpro'} = 'me@myemail.com';
260
    $ENV{branchcode} = $library->branchcode; # needed since T::D::C does no longer hides the FK constraint
284
261
285
    warnings_are {
262
    warnings_are {
286
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
263
        ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login);
Lines 297-307 subtest "checkpw_shib tests" => sub { Link Here
297
           ->debug_is("shibboleth attribute to match: uid",   "shib match attribute debug info")
274
           ->debug_is("shibboleth attribute to match: uid",   "shib match attribute debug info")
298
           ->clear();
275
           ->clear();
299
276
300
    ok my $new_user = ResultSet('Borrower')
277
    ok my $new_user = $schema->resultset('Borrower')
301
      ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "new user found";
278
      ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "new user found";
302
    is_fields [qw/surname dateexpiry address city/], $new_user->next,
279
    my $rec = $new_user->next;
303
      [qw/pika 2017 Address City/],
280
    is_deeply( [ map { $rec->$_ } qw/surname dateexpiry address city/ ],
304
      'Found $new_users surname';
281
        [qw/pika 2017-01-01 Address City/],
282
        'Found $new_user surname' );
305
    $autocreate = 0;
283
    $autocreate = 0;
306
    $welcome    = 0;
284
    $welcome    = 0;
307
285
Lines 313-324 subtest "checkpw_shib tests" => sub { Link Here
313
           ->debug_is("shibboleth attribute to match: uid",   "shib match attribute debug info")
291
           ->debug_is("shibboleth attribute to match: uid",   "shib match attribute debug info")
314
           ->clear();
292
           ->clear();
315
293
316
    ok my $sync_user = ResultSet('Borrower')
294
    ok my $sync_user = $schema->resultset('Borrower')
317
      ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "sync user found";
295
      ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "sync user found";
318
296
319
    is_fields [qw/surname dateexpiry address city/], $sync_user->next,
297
    $rec = $sync_user->next;
320
      [qw/pika 2017 Address AnotherCity/],
298
    is_deeply( [ map { $rec->$_ } qw/surname dateexpiry address city/ ],
321
      'Found $sync_user synced city';
299
        [qw/pika 2017-01-01 Address AnotherCity/],
300
        'Found $sync_user synced city' );
322
    $sync = 0;
301
    $sync = 0;
323
302
324
    # good user
303
    # good user
Lines 434-443 sub mockedInterface { Link Here
434
    return $interface;
413
    return $interface;
435
}
414
}
436
415
437
sub mockedSchema {
438
    return Schema();
439
}
440
441
## Convenience method to reset config
416
## Convenience method to reset config
442
sub reset_config {
417
sub reset_config {
443
    $matchpoint = 'userid';
418
    $matchpoint = 'userid';
Lines 452-457 sub reset_config { Link Here
452
        'address'      => { 'is' => 'add' },
427
        'address'      => { 'is' => 'add' },
453
        'city'         => { 'is' => 'city' },
428
        'city'         => { 'is' => 'city' },
454
        'emailpro'     => { 'is' => 'emailpro' },
429
        'emailpro'     => { 'is' => 'emailpro' },
430
        'branchcode'   => { 'is' => 'branchcode' },
455
    );
431
    );
456
    $ENV{'uid'}      = "test1234";
432
    $ENV{'uid'}      = "test1234";
457
    $ENV{'sn'}       = undef;
433
    $ENV{'sn'}       = undef;
Lines 463-466 sub reset_config { Link Here
463
439
464
    return 1;
440
    return 1;
465
}
441
}
466
467
- 

Return to bug 33778