diff --git a/lib/pf/ConfigStore/Source.pm b/lib/pf/ConfigStore/Source.pm index e5d755db24fb..f3b41c0a2946 100644 --- a/lib/pf/ConfigStore/Source.pm +++ b/lib/pf/ConfigStore/Source.pm @@ -44,6 +44,14 @@ our %TYPE_TO_EXPANDED_FIELDS = ( GoogleWorkspaceLDAP => [qw(searchattributes host)], ); +our %TYPE_TO_FLATTEN = ( + SMS => [qw(message)], + Twilio => [qw(message)], + Clickatell => [qw(message)], + Email => [qw(allowed_domains banned_domains)], + RADIUS => [qw(options)], +); + sub _fields_expanded { my ($self, $item) = @_; my $type = $item->{type} // ''; @@ -133,25 +141,18 @@ sub cleanupAfterRead { push @{$item->{"${class}_rules"}}, $rule; } my $type = $item->{type}; - - if ($type eq 'SMS' || $type eq "Twilio") { - # This can be an array if it's fresh out of the file. We make it separated by newlines so it works fine the frontend - if(ref($item->{message}) eq 'ARRAY'){ - $item->{message} = $self->join_options($item->{message}); - } - } elsif ($type eq 'Email') { - for my $f (qw(allowed_domains banned_domains)) { + if (exists $TYPE_TO_FLATTEN{$type}) { + for my $f (@{$TYPE_TO_FLATTEN{$type}}) { next unless exists $item->{$f}; my $val = $item->{$f}; if (ref($val) eq 'ARRAY') { $item->{$f} = $self->join_options($val); } } - } elsif ($type eq 'RADIUS') { - if(ref($item->{options}) eq 'ARRAY'){ - $item->{options} = $self->join_options($item->{options}); - } - } elsif ($type eq 'OpenID') { + + } + + if ($type eq 'OpenID') { $self->expand_ordered_array($item, 'person_mappings', 'person_mapping'); } diff --git a/t/data/authentication.conf b/t/data/authentication.conf index 94ef9ddb336c..974ddaa7c260 100644 --- a/t/data/authentication.conf +++ b/t/data/authentication.conf @@ -517,3 +517,10 @@ port=33389 type=AD host=127.0.0.1 cache_match=1 + +[ClickatellSource] +type=Clickatell +message=< 7; + +#This test will running last +use Test::NoWarnings; +use Test::Mojo; + +my $t = Test::Mojo->new('pf::UnifiedApi'); +use pf::ConfigStore::Source; +use Utils; +my ($fh, $filename) = Utils::tempfileForConfigStore("pf::ConfigStore::Source"); +my $true = bless( do { \( my $o = 1 ) }, 'JSON::PP::Boolean' ); +my $false = bless( do { \( my $o = 0 ) }, 'JSON::PP::Boolean' ); + +my $collection_base_url = '/api/v1/config/sources'; + +my $base_url = '/api/v1/config/source'; +my $id1 = "id_$$"; +my $id2 = "id2_$$"; + +#This is the second test +$t->post_ok("$collection_base_url" => + json => { + type => 'Clickatell', + description => 'das', + hash_passwords => 'plaintext', + password_length => '10', + id => $id1, + message => qq{ + Hello + World + }, + api_key => 'asasasaas', + } + ) + ->status_is(201) + ; +#This is the second test +$t->patch_ok("$base_url/$id1" => + json => { + type => 'Clickatell', + description => 'das', + hash_passwords => 'plaintext', + password_length => '10', + message => qq{ + Hello + World + }, + api_key => 'asasasaas', + } + ) + ->status_is(200) + ; + +$t->get_ok("$collection_base_url") + ->status_is(200) + ; +use Data::Dumper; print Dumper($t->tx->res->json); + + +=head1 AUTHOR + +Inverse inc. + +=head1 COPYRIGHT + +Copyright (C) 2005-2023 Inverse inc. + +=head1 LICENSE + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +USA. + +=cut + +1; diff --git a/t/unittest/authentication.t b/t/unittest/authentication.t index 333b17ee6eb2..0be20f2443d2 100755 --- a/t/unittest/authentication.t +++ b/t/unittest/authentication.t @@ -22,7 +22,7 @@ BEGIN { use Date::Parse; -use Test::More tests => 60; # last test to print +use Test::More tests => 61; # last test to print use Test::NoWarnings; @@ -560,6 +560,14 @@ is_deeply( ); } +{ + my $source = pf::authentication::getAuthenticationSource("ClickatellSource"); + is_deeply( + $source->{message}, + "line1 \$pin\nline2", + ); +} + =head1 AUTHOR Inverse inc.