From 7df9ab51945385c85cbe42dc4ad2a18776ad1bde Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 13 Oct 2016 15:10:36 +0300 Subject: [PATCH] Bug 17006: (follow-up) Test for changing another user's password The previous patches work for changing your own password, but the tests are lacking a case where librarian attempts to change patron's password. This feature was unnoticed and not implemented. To test: 1. Run t/db_dependent/api/v1/patrons.t 2. Observe failing test 3. Proceed to next patch to fix the failing test Signed-off-by: Josef Moravec --- t/db_dependent/api/v1/patrons.t | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 3d5b6ce..0efa374 100644 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 44; +use Test::More tests => 46; use Test::Mojo; use t::lib::TestBuilder; use t::lib::Mocks; @@ -62,6 +62,16 @@ my $borrower = $builder->build({ } }); +my $librarian = $builder->build({ + source => 'Borrower', + value => { + branchcode => $branchcode, + categorycode => $categorycode, + flags => 16, + password => Koha::AuthUtils::hash_password("test"), + } +}); + $t->get_ok('/api/v1/patrons') ->status_is(401); @@ -82,6 +92,13 @@ $session2->param('ip', '127.0.0.1'); $session2->param('lasttime', time()); $session2->flush; +my $session3 = C4::Auth::get_session(''); +$session3->param('number', $librarian->{ borrowernumber }); +$session3->param('id', $librarian->{ userid }); +$session3->param('ip', '127.0.0.1'); +$session3->param('lasttime', time()); +$session3->flush; + my $tx = $t->ua->build_tx(GET => '/api/v1/patrons'); $tx->req->cookies({name => 'CGISESSID', value => $session->id}); $t->request_ok($tx) @@ -210,4 +227,9 @@ $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); $t->request_ok($tx) ->status_is(200); +$tx = $t->ua->build_tx(PATCH => '/api/v1/patrons/'.$borrower->{borrowernumber}.'/password' => json => $password_obj); +$tx->req->cookies({name => 'CGISESSID', value => $session3->id}); +$t->request_ok($tx) + ->status_is(200); + $schema->storage->txn_rollback; -- 2.1.4