couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: svn commit: r773260 - in /couchdb/trunk: share/www/script/test/basics.js src/couchdb/couch_doc.erl
Date Sat, 09 May 2009 21:52:35 GMT

On 9 May 2009, at 23:25, Paul Davis wrote:

> I noticed that when I wrote the test. I originally wrote it expecting
> 400 errors and then got confused it was returning 500's. I decided
> that in the interest of backporting to leave as 500 and then figure
> out later.

Sounds like a plan. I don't think immediate action is required, but
we might want to open a ticket for this so we don't forget :)

Cheers
Jan
--



>
> On Sat, May 9, 2009 at 5:22 PM, Jan Lehnardt <jan@apache.org> wrote:
>>
>> On 9 May 2009, at 21:06, davisp@apache.org wrote:
>>
>>> Author: davisp
>>> Date: Sat May  9 19:06:00 2009
>>> New Revision: 773260
>>>
>>> URL: http://svn.apache.org/viewvc?rev=773260&view=rev
>>> Log:
>>> Check for invalid document members.
>>>
>>> Removes a guard that only checked for fields with integer values.  
>>> Adds
>>> tests to
>>> basics.js
>>>
>>>
>>> Modified:
>>>   couchdb/trunk/share/www/script/test/basics.js
>>>   couchdb/trunk/src/couchdb/couch_doc.erl
>>>
>>> Modified: couchdb/trunk/share/www/script/test/basics.js
>>> URL:
>>> http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=773260&r1=773259&r2=773260&view=diff
>>>
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> ====================================================================
>>> --- couchdb/trunk/share/www/script/test/basics.js (original)
>>> +++ couchdb/trunk/share/www/script/test/basics.js Sat May  9  
>>> 19:06:00 2009
>>> @@ -169,6 +169,28 @@
>>>    xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not- 
>>> exist");
>>>    T(xhr.status == 404);
>>>
>>> +  // Check for invalid document members
>>> +  bad_docs = [
>>> +    ["goldfish", {"_zing": 4}],
>>> +    ["zebrafish", {"_zoom": "hello"}],
>>> +    ["mudfish", {"zane": "goldfish", "_fan": "something smells
>>> delicious"}],
>>> +    ["tastyfish", {"_bing": {"wha?": "soda can"}}]
>>> +  ]
>>> +  var test_doc = function(info) {
>>> +    var data = JSON.stringify(info[1]);
>>> +
>>> +    xhr = CouchDB.request("PUT", "/test_suite_db/" + info[0],  
>>> {body:
>>> data});
>>> +    T(xhr.status == 500);
>>
>> A web server should send a 500 error on purpose. It is meant as a  
>> catch-all
>> error condition for unknown and unforeseen errors. Unfortunately  
>> there's not
>> a very good fitting 4xx code for this, but the closest would  
>> probably be a
>> 400 Bad Request.
>>
>>
>> Cheers
>> Jan
>> --
>>
>>
>>> +    result = JSON.parse(xhr.responseText);
>>> +    T(result.error == "doc_validation");
>>> +
>>> +    xhr = CouchDB.request("POST", "/test_suite_db/", {body: data});
>>> +    T(xhr.status == 500);
>>> +    result = JSON.parse(xhr.responseText);
>>> +    T(result.error == "doc_validation");
>>> +  };
>>> +  bad_docs.forEach(test_doc);
>>> +
>>>    // Check some common error responses.
>>>    // PUT body not an object
>>>    xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"});
>>>
>>> Modified: couchdb/trunk/src/couchdb/couch_doc.erl
>>> URL:
>>> http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_doc.erl?rev=773260&r1=773259&r2=773260&view=diff
>>>
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> ====================================================================
>>> --- couchdb/trunk/src/couchdb/couch_doc.erl (original)
>>> +++ couchdb/trunk/src/couchdb/couch_doc.erl Sat May  9 19:06:00 2009
>>> @@ -215,7 +215,7 @@
>>>    transfer_fields(Rest, Doc);
>>>
>>> % unknown special field
>>> -transfer_fields([{<<"_",Name/binary>>, Start} | _], _) when
>>> is_integer(Start) ->
>>> +transfer_fields([{<<"_",Name/binary>>, _} | _], _) ->
>>>    throw({doc_validation,
>>>            ?l2b(io_lib:format("Bad special document member: _~s",
>>> [Name]))});
>>>
>>>
>>>
>>>
>>
>>
>


Mime
View raw message