Bug 26595: Remove password from the smtp_server API object

This patch makes the SMTP server objects do not include the password for
API representation. If we need the password itself, we can add a route
to retrieve it with specific permissions.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2020-10-14 10:04:24 -03:00 committed by Jonathan Druart
parent 8eb68c082a
commit baabaceb32
2 changed files with 31 additions and 1 deletions

View File

@ -99,6 +99,24 @@ sub is_system_default {
return $self->{_is_system_default};
}
=head3 to_api
my $json = $smtp_server->to_api;
Overloaded method that returns a JSON representation of the Koha::SMTP::Server object,
suitable for API output.
=cut
sub to_api {
my ( $self, $params ) = @_;
my $json = $self->SUPER::to_api( $params );
delete $json->{password};
return $json;
}
=head3 to_api_mapping
This method returns the mapping for representing a Koha::SMTP::Server object

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 2;
use Test::More tests => 3;
use Test::Exception;
use Test::Warn;
@ -70,3 +70,15 @@ subtest 'is_system_default() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'to_api() tests' => sub {
plan tests => 1;
$schema->storage->txn_begin;
my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' });
ok( !exists $smtp_server->to_api->{password}, 'Password is not part of the API representation' );
$schema->storage->txn_rollback;
};