From 8cfcec9e6e61cbf5e0f8ef51e3676f7190578aed 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 sent_userenv routine in C4::Context were hunted down. The biggest problems were missing surnames or branch names. --- C4/Auth.pm | 24 ++++++++++++------------ C4/Context.pm | 8 +++++--- installer/InstallAuth.pm | 6 +++--- t/Circulation_barcodedecode.t | 2 +- t/db_dependent/Circulation.t | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index d73edaf..0802f90 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -665,7 +665,7 @@ sub checkauth { C4::Context->_new_userenv($sessionID); my ($ip, $lasttime, $sessiontype); 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'), @@ -938,7 +938,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'), @@ -1169,7 +1169,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'), @@ -1329,7 +1329,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'), @@ -1408,7 +1408,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'), @@ -1513,35 +1513,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; } } @@ -1550,7 +1550,7 @@ sub checkpw_internal { { # Koha superuser account -# C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1); +# C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"","",1); return 2; } if ( $userid && $userid eq 'demo' diff --git a/C4/Context.pm b/C4/Context.pm index 39927d4..e665e43 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1098,9 +1098,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. @@ -1110,6 +1111,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/installer/InstallAuth.pm b/installer/InstallAuth.pm index 0015a14..fb68e0d 100644 --- a/installer/InstallAuth.pm +++ b/installer/InstallAuth.pm @@ -250,7 +250,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'), @@ -312,7 +312,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'), "", @@ -417,7 +417,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 60b93e2..7160409 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -77,7 +77,7 @@ is( diag('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.10.4