You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/09/14 15:10:59 UTC

[GitHub] eiri commented on a change in pull request #817: Don't crash on invalid inline attachments

eiri commented on a change in pull request #817: Don't crash on invalid inline attachments
URL: https://github.com/apache/couchdb/pull/817#discussion_r138922582
 
 

 ##########
 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:
   This covers the original's issue exception, but sure, I'll add another test.
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services