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

(-)a/t/db_dependent/Auth.t (-19 / +21 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use Test::MockObject;
10
use Test::MockObject;
11
use Test::MockModule;
11
use Test::MockModule;
12
use List::MoreUtils qw/all any none/;
12
use List::MoreUtils qw/all any none/;
13
use Test::More tests => 26;
13
use Test::More tests => 20;
14
use Test::Warn;
14
use Test::Warn;
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
Lines 115-142 subtest 'track_login_daily tests' => sub { Link Here
115
115
116
};
116
};
117
117
118
my $hash1 = hash_password('password');
118
subtest 'no_set_userenv parameter tests' => sub {
119
my $hash2 = hash_password('password');
120
119
121
{ # tests no_set_userenv parameter
120
    plan tests => 7;
122
    my $patron = $builder->build( { source => 'Borrower' } );
121
123
    Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, 'password' );
122
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
124
    my $library = $builder->build(
123
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
125
        {
124
    my $password = 'password';
126
            source => 'Branch',
127
        }
128
    );
129
125
130
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
126
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
127
    $patron->set_password({ password => $password });
128
129
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
131
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
130
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
132
    C4::Context->_new_userenv('DUMMY SESSION');
131
    C4::Context->_new_userenv('DUMMY SESSION');
133
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', '');
132
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', '');
134
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' );
133
    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' );
135
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
134
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
136
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
135
    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' );
137
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
136
    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' );
138
    isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
137
    isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' );
139
}
138
};
140
139
141
# get_template_and_user tests
140
# get_template_and_user tests
142
141
Lines 311-315 my ( $template2 ); Link Here
311
ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ),
310
ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ),
312
    'OPACBaseURL is in Staff template' );
311
    'OPACBaseURL is in Staff template' );
313
312
313
my $hash1 = hash_password('password');
314
my $hash2 = hash_password('password');
315
314
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
316
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
315
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
317
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
(-)a/t/db_dependent/Koha/Patrons.t (-1 / +2 lines)
Lines 1516-1523 subtest '->store' => sub { Link Here
1516
        'Koha::Patron->store raises an exception on duplicate ID';
1516
        'Koha::Patron->store raises an exception on duplicate ID';
1517
1517
1518
    # Test password
1518
    # Test password
1519
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
1519
    my $password = 'password';
1520
    my $password = 'password';
1520
    $patron_1->update_password($patron_1->userid, $password);
1521
    $patron_1->set_password({ password => $password });
1521
    like( $patron_1->password, qr|^\$2|, 'Password should be hashed using bcrypt (start with $2)' );
1522
    like( $patron_1->password, qr|^\$2|, 'Password should be hashed using bcrypt (start with $2)' );
1522
    my $digest = $patron_1->password;
1523
    my $digest = $patron_1->password;
1523
    $patron_1->surname('xxx')->store;
1524
    $patron_1->surname('xxx')->store;
(-)a/t/db_dependent/Search/History.t (-1 / +2 lines)
Lines 369-375 my $builder = t::lib::TestBuilder->new; Link Here
369
369
370
# Borrower Creation
370
# Borrower Creation
371
our $patron = $builder->build( { source => 'Borrower' } );
371
our $patron = $builder->build( { source => 'Borrower' } );
372
Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, 'password' );
372
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
373
Koha::Patrons->find( $patron->{borrowernumber} )->set_password({ password => 'password' });
373
374
374
my $session = C4::Auth::get_session("");
375
my $session = C4::Auth::get_session("");
375
$session->flush;
376
$session->flush;
(-)a/t/db_dependent/selenium/authentication.t (-2 / +5 lines)
Lines 27-32 use Test::More tests => 2; Link Here
27
27
28
use C4::Context;
28
use C4::Context;
29
use Koha::AuthUtils;
29
use Koha::AuthUtils;
30
use t::lib::Mocks;
30
use t::lib::Selenium;
31
use t::lib::Selenium;
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
33
Lines 48-54 SKIP: { Link Here
48
49
49
        my $password = Koha::AuthUtils::generate_password();
50
        my $password = Koha::AuthUtils::generate_password();
50
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
51
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
51
        $patron->update_password( $patron->userid, $password );
52
        t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
53
        $patron->set_password({ password => $password });
52
54
53
        # Patron does not have permission to access staff interface
55
        # Patron does not have permission to access staff interface
54
        $s->auth( $patron->userid, $password );
56
        $s->auth( $patron->userid, $password );
Lines 79-85 SKIP: { Link Here
79
81
80
        my $password = Koha::AuthUtils::generate_password();
82
        my $password = Koha::AuthUtils::generate_password();
81
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
83
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
82
        $patron->update_password( $patron->userid, $password );
84
        t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
85
        $patron->set_password({ password => $password });
83
86
84
        # Using the modal
87
        # Using the modal
85
        $driver->find_element('//a[@class="login-link loginModal-trigger"]')->click;
88
        $driver->find_element('//a[@class="login-link loginModal-trigger"]')->click;
(-)a/t/db_dependent/selenium/regressions.t (-2 / +3 lines)
Lines 26-31 use C4::Context; Link Here
26
use C4::Biblio qw( AddBiblio );
26
use C4::Biblio qw( AddBiblio );
27
use C4::Circulation;
27
use C4::Circulation;
28
use Koha::AuthUtils;
28
use Koha::AuthUtils;
29
use t::lib::Mocks;
29
use t::lib::Selenium;
30
use t::lib::Selenium;
30
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
31
32
Lines 53-59 subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub { Link Here
53
    my $patron = $builder->build_object(
54
    my $patron = $builder->build_object(
54
        { class => 'Koha::Patrons', value => { flags => 1 } } );
55
        { class => 'Koha::Patrons', value => { flags => 1 } } );
55
    my $password = Koha::AuthUtils::generate_password();
56
    my $password = Koha::AuthUtils::generate_password();
56
    $patron->update_password( $patron->userid, $password );
57
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
58
    $patron->set_password({ password => $password });
57
    $s->opac_auth( $patron->userid, $password );
59
    $s->opac_auth( $patron->userid, $password );
58
    my $elt = $driver->find_element('//span[@class="loggedinusername"]');
60
    my $elt = $driver->find_element('//span[@class="loggedinusername"]');
59
    is( $elt->get_attribute('data-branchcode'), $patron->library->branchcode,
61
    is( $elt->get_attribute('data-branchcode'), $patron->library->branchcode,
60
- 

Return to bug 22048