gateway: a refusal behind a prefix that isn't JSON, like [HTTP 400], is still read by its structure (#451 follow-up) — the scan for a vendor's JSON error stopped at the first bracket it couldn't decode, so [HTTP 400] {"detail":[…]} fell back to text matching: an echoed metadata in the input was taken for a refusal and a real extra_forbidden was missed. The scan now looks on past such a bracket. text-prefixed-extra and text-prefixed-input-echo in TestRefusedOptionalNamesOnlyUnsupportedFields fail without the change.
This commit is contained in:
2 files changed
+5
-1
No files matched your search
@@ -2197,7 +2197,9 @@ func unsupportedOptionalField(fault any, field string) bool {
|
||||
var inner any
|
||||
dec := json.NewDecoder(strings.NewReader(rest[i:]))
|
||||
if dec.Decode(&inner) != nil {
|
||||
break
|
||||
// not JSON there ([HTTP 400]): look on past the bracket
|
||||
rest = rest[i+1:]
|
||||
continue
|
||||
}
|
||||
if hasOptionalErrorObject(inner) {
|
||||
return unsupportedOptionalField(inner, field)
|
||||
|
||||
@@ -162,6 +162,8 @@ func TestRefusedOptionalNamesOnlyUnsupportedFields(t *testing.T) {
|
||||
{"mixed-array-input-echo", `[400,{"type":"dict_type","loc":["body","metadata"],"msg":"Input should be a valid dictionary","input":"Unknown name 'metadata': Cannot find field."}]`, 422, nil},
|
||||
{"status-prefixed-extra", `[400] {"detail":[{"type":"extra_forbidden","loc":["body","store"],"msg":"Extra inputs are not permitted"}]}`, 400, []string{"store"}},
|
||||
{"status-prefixed-input-echo", `[400] {"detail":[{"type":"dict_type","loc":["body","metadata"],"msg":"Input should be a valid dictionary","input":"Unknown name 'metadata': Cannot find field."}]}`, 400, nil},
|
||||
{"text-prefixed-extra", `[HTTP 400] {"detail":[{"type":"extra_forbidden","loc":["body","store"],"msg":"Extra inputs are not permitted"}]}`, 400, []string{"store"}},
|
||||
{"text-prefixed-input-echo", `[HTTP 400] {"detail":[{"type":"dict_type","loc":["body","metadata"],"msg":"Input should be a valid dictionary","input":"Unknown name 'metadata': Cannot find field."}]}`, 400, nil},
|
||||
{"nested-extra", `{"detail":[{"type":"extra_forbidden","loc":["body","metadata","store"],"msg":"Extra inputs are not permitted"}]}`, 422, nil},
|
||||
{"nested-unknown", `{"error":{"message":"Invalid JSON payload received. Unknown name \"store\" at 'metadata': Cannot find field."}}`, 400, nil},
|
||||
{"other-parameter", `{"error":{"message":"'metadata' is unsupported","param":"model","code":"unsupported_value"}}`, 400, nil},
|
||||
|
||||
Reference in new issue
Block a user