Bug 23634: Secure the email on the API

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
This commit is contained in:
Tomas Cohen Arazi 2019-11-19 13:16:16 -03:00 committed by Aleisha Amohia
parent 813a45767d
commit f0276149f4
2 changed files with 27 additions and 2 deletions

View File

@ -194,6 +194,15 @@ sub update {
}
return try {
my $body = $c->validation->param('body');
my $user = $c->stash('koha.user');
if ( $patron->is_superlibrarian and !$user->is_superlibrarian ) {
return $c->render(
status => 403,
openapi => { error => "Not enough privileges to change a superlibrarian's email" }
) if $body->{email} ne $patron->email ;
}
$patron->set_from_api($c->validation->param('body'))->store;
$patron->discard_changes;

View File

@ -222,14 +222,14 @@ subtest 'update() tests' => sub {
$schema->storage->txn_rollback;
subtest 'librarian access tests' => sub {
plan tests => 22;
plan tests => 25;
$schema->storage->txn_begin;
my $authorized_patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 2**4 } # borrowers flag = 4
value => { flags => 1 }
}
);
my $password = 'thePassword123';
@ -330,6 +330,22 @@ subtest 'update() tests' => sub {
is(Koha::Patrons->find( $patron_2->id )->cardnumber,
$newpatron->{ cardnumber }, 'Patron is really updated!');
my $superlibrarian = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 1 }
}
);
$newpatron->{cardnumber} = $superlibrarian->cardnumber;
$newpatron->{userid} = $superlibrarian->userid;
$newpatron->{email} = 'nosense@no.no';
$authorized_patron->flags( 2**4 )->store; # borrowers flag = 4
$t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
->status_is(403, "Non-superlibrarian user change of superlibrarian email forbidden")
->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
$schema->storage->txn_rollback;
};
};