8000 Add HTTP-interface tests. · arangodb/arangodb@983a3ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 983a3ac

Browse files
committed
Add HTTP-interface tests.
1 parent 03b3619 commit 983a3ac

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/rb/HttpInterface/api-document-create-spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@
108108

109109
ArangoDB.drop_collection(cn)
110110
end
111+
112+
it "returns an error if an string attribute in the JSON body is corrupted" do
113+
cn = "UnitTestsCollectionBasics"
114+
id = ArangoDB.create_collection(cn)
115+
116+
cmd = "/_api/document?collection=#{id}"
117+
body = "{ \"foo\" : \"bar\xff\" }"
118+
doc = ArangoDB.log_post("#{prefix}-bad-json", cmd, :body => body)
119+
120+
doc.code.should eq(400)
121+
doc.parsed_response['error'].should eq(true)
122+
doc.parsed_response['errorNum'].should eq(600)
123+
doc.parsed_response['code'].should eq(400)
124+
doc.headers['content-type'].should eq("application/json; charset=utf-8")
125+
126+
ArangoDB.size_collection(cn).should eq(0)
127+
128+
ArangoDB.drop_collection(cn)
129+
end
111130
end
112131

113132
################################################################################

tests/rb/HttpInterface/api-document-update-spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,34 @@
118118

119119
ArangoDB.size_collection(@cid).should eq(0)
120120
end
121+
122+
it "create a document and update it with invalid JSON" do
123+
cmd = "/_api/document?collection=#{@cid}"
124+
body = "{ \"Hallo\" : \"World\" }"
125+
doc = ArangoDB.post(cmd, :body => body)
126+
127+
doc.code.should eq(201)
128+
129+
location = doc.headers['location']
130+
location.should be_kind_of(String)
131+
132+
did = doc.parsed_response['_id']
133+
rev = doc.parsed_response['_rev']
134+
135+
# update document
136+
cmd = "/_api/document/#{did}"
137+
body = "{ \"World\" : \"Hallo\xff\" }"
138+
doc = ArangoDB.log_put("#{prefix}", cmd, :body => body)
139+
140+
doc.code.should eq(400)
141+
doc.parsed_response['error'].should eq(true)
142+
doc.parsed_response['errorNum'].should eq(600)
143+
doc.parsed_response['code'].should eq(400)
144+
145+
ArangoDB.delete(location)
146+
147+
ArangoDB.size_collection(@cid).should eq(0)
148+
end
121149
end
122150

123151
################################################################################

0 commit comments

Comments
 (0)
0