nickva commented on a change in pull request #817: Don't crash on invalid
inline attachments
URL: https://github.com/apache/couchdb/pull/817#discussion_r138920995
##########
File path: src/couch/src/couch_att.erl
##########
@@ -786,8 +794,35 @@ attachment_disk_term_test_() ->
attachment_json_term_test_() ->
- %% We need to create a few variations including stubs and inline data.
- {"JSON term tests", []}.
+ Props = [
+ {<<"content_type">>, <<"application/json">>},
+ {<<"digest">>, <<"md5-QCNtWUNXV0UzJnEjMk92YUk1JA==">>},
+ {<<"length">>, 14},
+ {<<"revpos">>, 1}
+ ],
+ PropsInline = [{<<"data">>, <<"eyJhbnN3ZXIiOiA0Mn0=">>}] ++ Props,
+ Att = couch_att:new([
+ {name, <<"attachment.json">>},
+ {type, <<"application/json">>}
+ ]),
+ ResultStub = couch_att:new([
+ {name, <<"attachment.json">>},
+ {type, <<"application/json">>},
+ {att_len, 14},
+ {disk_len, 14},
+ {md5, <<"@#mYCWWE3&q#2OvaI5$">>},
+ {revpos, 1},
+ {data, stub},
+ {encoding, identity}
+ ]),
+ ResultFollows = ResultStub#att{data = follows},
+ ResultInline = ResultStub#att{md5 = <<>>, data = <<"{\"answer\": 42}">>},
+ {"JSON term tests", [
+ ?_assertEqual(ResultStub, stub_from_json(Att, Props)),
+ ?_assertEqual(ResultFollows, follow_from_json(Att, Props)),
+ ?_assertEqual(ResultInline, inline_from_json(Att, PropsInline)),
+ ?_assertThrow({bad_request, _}, inline_from_json(Att, Props))
Review comment:
In this case the data would be undefined so the case when data is not
available at all in the request. Maybe have another clause where data is
present but is invalid?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services