https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43022

--- Comment #1 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 211486
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211486&action=edit
Bug 43022: Return 400 for undecodable MARC in biblio create

Biblios->add called the MARC::Record parsers without any eval, so a
malformed MARCXML, MARC-in-JSON or ISO2709 body produced a raw 500.
The parsers also return a record with no fields rather than dying for
some invalid input, and add accepted that, saving a biblio with blank
metadata.

Wrap the parsers the same way update() already does, reject records
with no fields with 400 bad_record, and map
Koha::Exceptions::Metadata::Invalid raised while saving to 400
bad_record on both create and update. update() now calls
C4::Biblio::ModBiblio fully qualified so it can be mocked in tests, as
add() already does with AddBiblio.

Document the bad_record error_code for POST and PUT /biblios in the
swagger spec.

To test:
1. POST /api/v1/biblios with Content-Type application/marcxml+xml and a
   truncated body such as
   <record><leader>00000nam a2200000 a 4500</leader><datafield tag="245"
   Before: 500 internal_server_error. After: 400 with error_code
   bad_record, and no biblio created.
2. Repeat with Content-Type application/marc-in-json and truncated JSON,
   and with application/marc and the text "this is not a valid usmarc
   record". Before: 500, or 200 with an empty biblio. After: 400.
3. PUT the same bodies to /api/v1/biblios/{biblio_id}. Expect 400
   bad_record and the biblio unchanged.
4. Run prove t/db_dependent/api/v1/biblios.t and prove xt/api.t.

Sponsored-by: OpenFifth
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to