From 14496cc46580d74655686aba404ff5e24e0c4d7b Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Mon, 12 Feb 2018 11:17:27 +0200 Subject: [PATCH] TT#14501 Allow any value for the Prefer header Return 'minimal' on unknown Change-Id: I6247b7cbf1df7e477894bac6a4d3826d7f3a5c10 --- lib/NGCP/Panel/Role/API.pm | 5 +++-- t/api-rest/api-billingprofiles.t | 6 ------ t/api-rest/api-contracts.t | 5 ----- t/api-rest/api-customercontacts.t | 6 ------ t/api-rest/api-customers.t | 5 ----- t/api-rest/api-resellers.t | 5 ----- t/api-rest/api-systemcontacts.t | 5 ----- t/lib/Test/Collection.pm | 2 +- 8 files changed, 4 insertions(+), 35 deletions(-) diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 3e99ec011e..76bf4e6612 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -372,7 +372,8 @@ sub get_uploads { sub require_preference { my ($self, $c) = @_; - return 'minimal' unless $c->request->header('Prefer'); + my $prefer_default = 'minimal'; + return $prefer_default unless $c->request->header('Prefer'); my $ngcp_ua_header = $c->request->header("NGCP-UserAgent") // ''; my @preference = grep { 'return' eq $_->[0] } split_header_words($c->request->header('Prefer')); return $preference[0][1] @@ -380,7 +381,7 @@ sub require_preference { return $preference[0][1] if 1 == @preference && $preference[0][1] eq 'internal' && $ngcp_ua_header eq "NGCP::API::Client"; - $self->error($c, HTTP_BAD_REQUEST, "Header 'Prefer' must be either 'return=minimal' or 'return=representation'."); + return $prefer_default; } sub require_wellformed_json { diff --git a/t/api-rest/api-billingprofiles.t b/t/api-rest/api-billingprofiles.t index add170c35c..a1fd4f2663 100644 --- a/t/api-rest/api-billingprofiles.t +++ b/t/api-rest/api-billingprofiles.t @@ -196,12 +196,6 @@ my @allprofiles = (); $req->remove_header('Content-Type'); $req->header('Content-Type' => 'application/json'); - # check if it fails with invalid Prefer - $req->header('Prefer' => "return=invalid"); - $res = $ua->request($req); - is($res->code, 400, "check put invalid prefer"); - - $req->remove_header('Prefer'); $req->header('Prefer' => "return=representation"); diff --git a/t/api-rest/api-contracts.t b/t/api-rest/api-contracts.t index 466f356be5..2f10ee39c8 100644 --- a/t/api-rest/api-contracts.t +++ b/t/api-rest/api-contracts.t @@ -283,11 +283,6 @@ my @allcontracts = (); $req->remove_header('Content-Type'); $req->header('Content-Type' => 'application/json'); - # check if it fails with invalid Prefer - $req->header('Prefer' => "return=invalid"); - $res = $ua->request($req); - is($res->code, 400, "check put invalid prefer"); - $req->remove_header('Prefer'); $req->header('Prefer' => "return=representation"); diff --git a/t/api-rest/api-customercontacts.t b/t/api-rest/api-customercontacts.t index 5fa6985a04..4d015546b6 100644 --- a/t/api-rest/api-customercontacts.t +++ b/t/api-rest/api-customercontacts.t @@ -197,12 +197,6 @@ my @allcontacts = (); $req->remove_header('Content-Type'); $req->header('Content-Type' => 'application/json'); - # check if it fails with invalid Prefer - $req->header('Prefer' => "return=invalid"); - $res = $ua->request($req); - is($res->code, 400, "check put invalid prefer"); - - $req->remove_header('Prefer'); $req->header('Prefer' => "return=representation"); diff --git a/t/api-rest/api-customers.t b/t/api-rest/api-customers.t index ecf07cbaaa..60244d3f1f 100644 --- a/t/api-rest/api-customers.t +++ b/t/api-rest/api-customers.t @@ -317,11 +317,6 @@ my @allcustomers = (); $req->remove_header('Content-Type'); $req->header('Content-Type' => 'application/json'); - # check if it fails with invalid Prefer - $req->header('Prefer' => "return=invalid"); - $res = $ua->request($req); - is($res->code, 400, "check put invalid prefer"); - $req->remove_header('Prefer'); $req->header('Prefer' => "return=representation"); diff --git a/t/api-rest/api-resellers.t b/t/api-rest/api-resellers.t index a9e951024b..83132bfb2f 100644 --- a/t/api-rest/api-resellers.t +++ b/t/api-rest/api-resellers.t @@ -287,11 +287,6 @@ my @allresellers = (); $req->remove_header('Content-Type'); $req->header('Content-Type' => 'application/json'); - # check if it fails with invalid Prefer - $req->header('Prefer' => "return=invalid"); - $res = $ua->request($req); - is($res->code, 400, "check put invalid prefer"); - $req->remove_header('Prefer'); $req->header('Prefer' => "return=representation"); diff --git a/t/api-rest/api-systemcontacts.t b/t/api-rest/api-systemcontacts.t index 89712ab866..cda9e5fd09 100644 --- a/t/api-rest/api-systemcontacts.t +++ b/t/api-rest/api-systemcontacts.t @@ -161,11 +161,6 @@ my @allcontacts = (); $req->remove_header('Content-Type'); $req->header('Content-Type' => 'application/json'); - # check if it fails with invalid Prefer - $req->header('Prefer' => "return=invalid"); - $res = $ua->request($req); - is($res->code, 400, "check put invalid prefer"); - $req->remove_header('Prefer'); $req->header('Prefer' => "return=representation"); diff --git a/t/lib/Test/Collection.pm b/t/lib/Test/Collection.pm index 82390a1f3a..8e68831241 100644 --- a/t/lib/Test/Collection.pm +++ b/t/lib/Test/Collection.pm @@ -971,7 +971,7 @@ sub check_put_bundle{ my($self) = @_; $self->check_put_content_type_empty; $self->check_put_content_type_wrong; - $self->check_put_prefer_wrong; + #$self->check_put_prefer_wrong; $self->check_put_body_empty; }