From ab41e1ce8d8799b2f095a5f5863ad34d146c7591 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 14 Oct 2020 10:04:24 -0300 Subject: [PATCH] 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 --- Koha/SMTP/Server.pm | 18 ++++++++++++++++++ t/db_dependent/Koha/SMTP/Server.t | 14 +++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Koha/SMTP/Server.pm b/Koha/SMTP/Server.pm index 919f7898b20..d5fec72611b 100644 --- a/Koha/SMTP/Server.pm +++ b/Koha/SMTP/Server.pm @@ -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 diff --git a/t/db_dependent/Koha/SMTP/Server.t b/t/db_dependent/Koha/SMTP/Server.t index 23b368320f5..3a1c423e5ef 100755 --- a/t/db_dependent/Koha/SMTP/Server.t +++ b/t/db_dependent/Koha/SMTP/Server.t @@ -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; +}; -- 2.28.0