TT#168050 fix allowed_cli check for duplicates

Change-Id: I09874917c946b0e9be60ca1a0682f70c2d4f84df
mr10.4
Rene Krenn 3 years ago
parent 194dc6a26f
commit 4df49f5639

@ -885,29 +885,20 @@ sub update_preferences {
last SWITCH; last SWITCH;
}; };
/^allowed_clis$/ && do { /^allowed_clis$/ && do {
if ($replace) { my $old_seen = {};
#check duplicates in case of PUT unless ($replace) {
if ($resource->{$pref}) {
my %seen;
foreach my $allowed_cli (@{$resource->{$pref}}) {
next unless $seen{$allowed_cli}++;
$c->log->error("Duplicate $pref value: ".$allowed_cli);
&$err_code(HTTP_UNPROCESSABLE_ENTITY, "Duplicate $pref value: ".$allowed_cli);
return;
}
}
}
else {
#in case of PATCH, check duplicates only for new values, since there could already be duplicates in some systems #in case of PATCH, check duplicates only for new values, since there could already be duplicates in some systems
if ($resource->{$pref} && $old_resource->{$pref}) { ($old_seen) = array_to_map($old_resource->{$pref},undef,undef,'first');
my @new_clis = @{$resource->{$pref}}[scalar @{$old_resource->{$pref}} .. scalar @{$resource->{$pref}} - 1]; }
my %existing_clis = map {$_ => 1} @{$old_resource->{$pref}}; my $seen = {};
my ($allowed_cli) = grep { exists $existing_clis{$_} } @new_clis; foreach my $allowed_cli (@{$resource->{$pref} // []}) {
if ( $allowed_cli ) { next if exists $old_seen->{$allowed_cli};
$c->log->error("Duplicate $pref value: ".$allowed_cli); if (exists $seen->{$allowed_cli}) {
&$err_code(HTTP_UNPROCESSABLE_ENTITY, "Duplicate $pref value: ".$allowed_cli); $c->log->error("Duplicate $pref value: ".$allowed_cli);
return; &$err_code(HTTP_UNPROCESSABLE_ENTITY, "Duplicate $pref value: ".$allowed_cli);
} return;
} else {
$seen->{$allowed_cli} = 1;
} }
} }
}; };

Loading…
Cancel
Save