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

(-)a/t/db_dependent/Auth.t (-20 / +24 lines)
Lines 8-14 use Modern::Perl; Link Here
8
use CGI qw ( -utf8 );
8
use CGI qw ( -utf8 );
9
use Test::MockModule;
9
use Test::MockModule;
10
use List::MoreUtils qw/all any none/;
10
use List::MoreUtils qw/all any none/;
11
use Test::More tests => 18;
11
use Test::More tests => 20;
12
use Test::Warn;
12
use Test::Warn;
13
use t::lib::Mocks;
13
use t::lib::Mocks;
14
use t::lib::TestBuilder;
14
use t::lib::TestBuilder;
Lines 27-32 $schema->storage->txn_begin; Link Here
27
my $builder = t::lib::TestBuilder->new;
27
my $builder = t::lib::TestBuilder->new;
28
my $dbh     = C4::Context->dbh;
28
my $dbh     = C4::Context->dbh;
29
29
30
my $hash1 = hash_password('password');
31
my $hash2 = hash_password('password');
32
33
{ # tests no_set_userenv parameter
34
    my $patron = $builder->build( { source => 'Borrower' } );
35
    changepassword( $patron->{userid}, $patron->{borrowernumber}, $hash1 );
36
    my $library = $builder->build(
37
        {
38
            source => 'Branch',
39
        }
40
    );
41
42
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
43
    is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
44
    C4::Context->_new_userenv('DUMMY SESSION');
45
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', '');
46
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' );
47
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
48
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
49
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
50
    isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
51
}
52
30
# get_template_and_user tests
53
# get_template_and_user tests
31
54
32
{   # Tests for the language URL parameter
55
{   # Tests for the language URL parameter
Lines 172-194 my ( $template2 ); Link Here
172
ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ),
195
ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ),
173
    'OPACBaseURL is in Staff template' );
196
    'OPACBaseURL is in Staff template' );
174
197
175
my $hash1 = hash_password('password');
176
my $hash2 = hash_password('password');
177
178
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
198
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
179
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
199
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
180
181
my $patron = $builder->build( { source => 'Borrower' } );
182
changepassword( $patron->{userid}, $patron->{borrowernumber}, $hash1 );
183
my $library = $builder->build(
184
    {
185
        source => 'Branch',
186
    }
187
);
188
189
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', '');
190
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' );
191
ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
192
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
193
ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
194
isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
195
- 

Return to bug 16492