From fea5c60e136f77905e859106cfa78860139d8909 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 20 Sep 2013 21:36:46 -0400 Subject: [PATCH] Bug 10900 - Incorrect calling conventions accessing C4::Context There were multiple calling conventions for C4::Context's set_userenv routine. So the following commands were used to find discrepancies: grep "::set_userenv" `find .` grep "\->set_userenv" `find .` The first grep demonstrated that the smaller change is from :: to -> as only C4/Auth.pm, installer/InstallAuth.pm, and t/db_dependent/Circulation.t would need to be modified. This patch corrects C4::Context's set_userenv routine to be object call based (use ->) by using a shift to ignore the first parameter, and modify the three files found with :: calls. As the result of trying to roll a distribution, t/Circulation_barcodedecode.t was discovered to be faulty. The cause being incorrect parameters! This was hidden when there was no shift in the set_userenv routine. However, with its correction, the test broke. This led me to read the POD documentation for the function set_userenv in C4::Context and realize it was outdated as well. It has been revised to match the current version of the function. Then intentionally bad parameters passed to the set_userenv routine in C4::Context were hunted down. The biggest problems were missing surnames or branch names. Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Auth.pm | 22 +++++++++++----------- C4/Context.pm | 8 +++++--- C4/InstallAuth.pm | 6 +++--- t/Circulation_barcodedecode.t | 2 +- t/db_dependent/Circulation.t | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 9dba5e5..5018c2b 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -691,7 +691,7 @@ sub checkauth { my $s_userid = ''; if ($session){ $s_userid = $session->param('id') // ''; - C4::Context::set_userenv( + C4::Context->set_userenv( $session->param('number'), $s_userid, $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), @@ -982,7 +982,7 @@ sub checkauth { if ($persona){ $session->param('persona',1); } - C4::Context::set_userenv( + C4::Context->set_userenv( $session->param('number'), $session->param('id'), $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), @@ -1214,7 +1214,7 @@ sub check_api_auth { my $session = get_session($sessionID); C4::Context->_new_userenv($sessionID); if ($session) { - C4::Context::set_userenv( + C4::Context->set_userenv( $session->param('number'), $session->param('id'), $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), @@ -1377,7 +1377,7 @@ sub check_api_auth { $session->param('ip',$session->remote_addr()); $session->param('lasttime',time()); } - C4::Context::set_userenv( + C4::Context->set_userenv( $session->param('number'), $session->param('id'), $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), @@ -1456,7 +1456,7 @@ sub check_cookie_auth { my $session = get_session($sessionID); C4::Context->_new_userenv($sessionID); if ($session) { - C4::Context::set_userenv( + C4::Context->set_userenv( $session->param('number'), $session->param('id'), $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), @@ -1576,35 +1576,35 @@ sub checkpw_internal { my $sth = $dbh->prepare( -"select password,cardnumber,borrowernumber,userid,firstname,surname,branchcode,flags from borrowers where userid=?" +"select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where userid=?" ); $sth->execute($userid); if ( $sth->rows ) { my ( $stored_hash, $cardnumber, $borrowernumber, $userid, $firstname, - $surname, $branchcode, $flags ) + $surname, $branchcode, $branchname, $flags ) = $sth->fetchrow; if ( checkpw_hash($password, $stored_hash) ) { C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber, - $firstname, $surname, $branchcode, $flags ); + $firstname, $surname, $branchcode, $branchname, $flags ); return 1, $cardnumber, $userid; } } $sth = $dbh->prepare( -"select password,cardnumber,borrowernumber,userid, firstname,surname,branchcode,flags from borrowers where cardnumber=?" +"select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where cardnumber=?" ); $sth->execute($userid); if ( $sth->rows ) { my ( $stored_hash, $cardnumber, $borrowernumber, $userid, $firstname, - $surname, $branchcode, $flags ) + $surname, $branchcode, $branchname, $flags ) = $sth->fetchrow; if ( checkpw_hash($password, $stored_hash) ) { C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber, - $firstname, $surname, $branchcode, $flags ); + $firstname, $surname, $branchcode, $branchname, $flags ); return 1, $cardnumber, $userid; } } diff --git a/C4/Context.pm b/C4/Context.pm index 9a7b75d..adb7a8f 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1100,9 +1100,10 @@ sub userenv { =head2 set_userenv - C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname, - $usersurname, $userbranch, $userflags, $emailaddress, $branchprinter, - $persona); + C4::Context->set_userenv($usernum, $userid, $usercnum, + $userfirstname, $usersurname, + $userbranch, $branchname, $userflags, + $emailaddress, $branchprinter, $persona); Establish a hash of user environment variables. @@ -1112,6 +1113,7 @@ set_userenv is called in Auth.pm #' sub set_userenv { + shift @_; my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona)= @_; my $var=$context->{"activeuser"} || ''; my $cell = { diff --git a/C4/InstallAuth.pm b/C4/InstallAuth.pm index 35ac2e1..97b45a0 100644 --- a/C4/InstallAuth.pm +++ b/C4/InstallAuth.pm @@ -246,7 +246,7 @@ sub checkauth { new CGI::Session( "driver:File;serializer:yaml", $sessionID, { Directory => '/tmp' } ); if ( $session->param('cardnumber') ) { - C4::Context::set_userenv( + C4::Context->set_userenv( $session->param('number'), $session->param('id'), $session->param('cardnumber'), @@ -308,7 +308,7 @@ sub checkauth { #Only superlibrarian should have access to this page. #Since if it is a user, it is supposed that there is a borrower table #And thus that data structure is loaded. - my $hash = C4::Context::set_userenv( + my $hash = C4::Context->set_userenv( 0, 0, C4::Context->config('user'), C4::Context->config('user'), C4::Context->config('user'), "", @@ -412,7 +412,7 @@ sub checkpw { C4::Context->config('user'), C4::Context->config('user'), C4::Context->config('user'), - "", 1 + "", "NO_LIBRARY_SET", 1 ); return 2; } diff --git a/t/Circulation_barcodedecode.t b/t/Circulation_barcodedecode.t index f76f7fc..f76042c 100644 --- a/t/Circulation_barcodedecode.t +++ b/t/Circulation_barcodedecode.t @@ -6,7 +6,7 @@ use warnings; use Test::More tests => 26; C4::Context->_new_userenv(123456); -C4::Context->set_userenv(1,'kmkale' , 1, 'kk1' , 'IMS', 0, 'kmkale@anantcorp.com'); +C4::Context->set_userenv(1,'kmkale' , 1, 'km', 'kale' , 'IMS', 'IMS Branch DEscription', 0, 'kmkale@anantcorp.com'); BEGIN { use_ok('C4::Circulation'); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 4bc565f..2faec07 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -93,7 +93,7 @@ is( # Now, set a userenv C4::Context->_new_userenv('xxx'); -C4::Context::set_userenv(0,0,0,'firstname','surname', 'MPL', 'Midway Public Library', '', '', ''); +C4::Context->set_userenv(0,0,0,'firstname','surname', 'MPL', 'Midway Public Library', '', '', ''); is(C4::Context->userenv->{branch}, 'MPL', 'userenv set'); # Userenv set, PickupLibrary -- 1.7.9.5