Skip to content

Commit

Permalink
CMR-8038: Fix CMR search app 500 error when searching with empty JSON (
Browse files Browse the repository at this point in the history
…#1881)

* CMR-8038 Adding empty json validation test

* CMR-8038 Modified error response for empty json queries

* CMR-8038 Minor string changes

* CMR-8038 Formatting and indentation changes

* CMR-8038 Indentation fix

---------

Co-authored-by: drewpesall <[email protected]>
  • Loading branch information
dpesall and drewpesall authored Apr 3, 2023
1 parent f7bb3f7 commit d3c9a26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
"Perform all validations against the provided JSON query."
[concept-type json-query]
(concept-type-validation concept-type)
(when-not json-query
(errors/throw-service-errors :invalid-data ["JSON query cannot be empty"]))
(when-let [errors (seq (js/validate-json (concept-type->json-query-schema concept-type) json-query))]
(errors/throw-service-errors :bad-request errors)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@
(search/get-search-failure-xml-data
(search/find-concepts-in-format
"application/echo11+xml" :collection {})))))

(testing "invalid format html escape"
(is (= {:status 400,
:errors ["The mime types specified in the accept header [application/html &quot;qss=&quot;QssAttrValue] are not supported."]}
Expand Down Expand Up @@ -1221,3 +1221,29 @@
(is (= ["STAC result format is only supported for granule searches"]
(:errors response)
(:errors ext-response))))))

(deftest search-with-empty-json
(let [coll1 (d/ingest "PROV1" (dc/collection))
coll-concept-id (:concept-id coll1)
_ (index/wait-until-indexed)
response1 (client/get
(url/search-url :collection)
{:accept "application/json"
:content-type "application/json"
:body nil
:throw-exceptions false
:connection-manager (s/conn-mgr)})
response2 (client/get
(url/search-url :collection)
{:accept "application/json"
:content-type "application/json"
:body ""
:throw-exceptions false
:connection-manager (s/conn-mgr)})]
(testing "testing collection search with empty json body"
(is (= 422
(:status response1)
(:status response2)))
(is (= "JSON query cannot be empty"
(first (:errors (json/decode (:body response1) true)))
(first (:errors (json/decode (:body response2) true))))))))

0 comments on commit d3c9a26

Please sign in to comment.