8000 Bug fix/schema validation return code (#11341) · arangodb/arangodb@19d1e20 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19d1e20

Browse files
authored
Bug fix/schema validation return code (#11341)
1 parent e5bcd44 commit 19d1e20

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

arangod/VocBase/Validators.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ ValidatorJsonSchema::ValidatorJsonSchema(VPackSlice params) : ValidatorBase(para
178178
if (!rule.isObject()) {
179179
std::string msg = "No valid schema in rule attribute given (no object): ";
180180
msg += params.toJson();
181-
LOG_TOPIC("ababf", ERR, Logger::VALIDATION) << msg;
182181
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_VALIDATION_BAD_PARAMETER, msg);
183182
}
184183
auto taoRuleValue = validation::slice_to_value(rule);

lib/ApplicationFeatures/EnvironmentFeature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void EnvironmentFeature::prepare() {
253253
overriddenmsg = " (overridden by environment variable)";
254254
}
255255
LOG_TOPIC("25362", INFO, Logger::MEMORY)
256-
<< "Available physical memory: " << ram << overriddenmsg;
256+
<< "Available physical memory: " << ram << overriddenmsg << " bytes";
257257

258258
// test local ipv6 support
259259
try {

lib/Rest/GeneralResponse.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ rest::ResponseCode GeneralResponse::responseCode(int code) {
373373
case TRI_ERROR_KEY_MUST_BE_PREFIXED_WITH_SMART_JOIN_ATTRIBUTE:
374374
case TRI_ERROR_NO_SMART_JOIN_ATTRIBUTE:
375375
case TRI_ERROR_CLUSTER_MUST_NOT_CHANGE_SMART_JOIN_ATTRIBUTE:
376+
case TRI_ERROR_VALIDATION_FAILED:
377+
case TRI_ERROR_VALIDATION_BAD_PARAMETER:
376378
return ResponseCode::BAD;
377379

378380
case TRI_ERROR_ARANGO_USE_SYSTEM_DATABASE:

tests/rb/HttpInterface/api-collection-rocksdb-spec.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,100 @@
157157
end
158158
end
159159

160+
################################################################################
161+
## schema validation
162+
################################################################################
163+
164+
context "schema validation:" do
165+
before do
166+
@cn = "UnitTestsCollectionBasics"
167+
ArangoDB.drop_collection(@cn)
168+
@cid = ArangoDB.create_collection(@cn, false)
169+
end
170+
171+
after do
172+
ArangoDB.drop_collection(@cn)
173+
end
174+
175+
it "sets an invalid schema" do
176+
cmd = api + "/" + @cn + "/properties"
177+
body = "{ \"validation\": { \"rule\": \"peng!\", \"level\": \"strict\", \"message\": \"document has an invalid schema!\" } }"
178+
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)
179+
180+
doc.code.should eq(400)
181+
doc.parsed_response['error'].should eq(true)
182+
doc.parsed_response['code'].should eq(400)
183+
doc.parsed_response['errorNum'].should eq(1621)
184+
end
185+
186+
it "sets a valid schema" do
187+
cmd = api + "/" + @cn + "/properties"
188+
body = "{ \"validation\": { \"rule\": { \"properties\": { \"_key\": { \"type\": \"string\" }, \"_rev\": { \"type\": \"string\" }, \"_id\": { \"type\": \"string\" }, \"name\": { \"type\": \"object\", \"properties\": { \"first\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 50 }, \"last\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 50 } }, \"required\": [\"first\", \"last\"] }, \"status\": { \"enum\": [\"active\", \"inactive\", \"deleted\"] } }, \"additionalProperties\": false, \"required\": [\"name\", \"status\"] }, \"level\": \"strict\", \"message\": \"document has an invalid schema!\" } }"
189+
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)
190+
doc = ArangoDB.log_get("#{prefix}-get-schema", cmd)
191+
192+
doc.code.should eq(200)
193+
doc.headers['content-type'].should eq("application/json; charset=utf-8")
194+
doc.parsed_response['error'].should eq(false)
195+
doc.parsed_response['code'].should eq(200)
196+
doc.parsed_response['id'].should eq(@cid)
197+
doc.parsed_response['name'].should eq(@cn)
198+
doc.parsed_response['validation']['level'].should eq("strict")
199+
doc.parsed_response['validation']['message'].should eq("document has an invalid schema!")
200+
end
201+
202+
it "stores valid documents" do
203+
cmd = api + "/" + @cn + "/properties"
204+
body = "{ \"validation\": { \"rule\": { \"properties\": { \"_key\": { \"type\": \"string\" }, \"_rev\": { \"type\": \"string\" }, \"_id\": { \"type\": \"string\" }, \"name\": { \"type\": \"object\", \"properties\": { \"first\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 50 }, \"last\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 50 } }, \"required\": [\"first\", \"last\"] }, \"status\": { \"enum\": [\"active\", \"inactive\", \"deleted\"] } }, \"additionalProperties\": false, \"required\": [\"name\", \"status\"] }, \"level\": \"strict\", \"message\": \"document has an invalid schema!\" } }"
205+
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)
206+
doc.code.should eq(200)
207+
208+
body = "{ \"name\": { \"first\": \"test\", \"last\": \"test\" }, \"status\": \"active\" }"
209+
doc = ArangoDB.log_post("#{prefix}-schema-doc", "/_api/document/?collection=" + @cn, :body => body)
210+
doc.code.should eq(202)
211+
212+
body = "{ \"name\": { \"first\": \"a\", \"last\": \"b\" }, \"status\": \"inactive\" }"
213+
doc = ArangoDB.log_post("#{prefix}-schema-doc", "/_api/document/?collection=" + @cn, :body => body)
214+
doc.code.should eq(202)
215+
end
216+
217+
it "stores invalid documents" do
218+
cmd = api + "/" + @cn + "/properties"
219+
body = "{ \"validation\": { \"rule\": { \"properties\": { \"_key\": { \"type\": \"string\" }, \"_rev\": { \"type\": \"string\" }, \"_id\": { \"type\": \"string\" }, \"name\": { \"type\": \"object\", \"properties\": { \"first\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 50 }, \"last\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 50 } }, \"required\": [\"first\", \"last\"] }, \"status\": { \"enum\": [\"active\", \"inactive\", \"deleted\"] } }, \"additionalProperties\": false, \"required\": [\"name\", \"status\"] }, \"level\": \"strict\", \"message\": \"document has an invalid schema!\" } }"
220+
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)
221+
222+
body = "{ \"name\": { \"first\" : \"\", \"last\": \"test\" }, \"status\": \"active\" }"
223+
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
224+
doc.code.should eq(400)
225+
doc.parsed_response['errorNum'].should eq(1620)
226+
227+
body = "{ \"name\": { \"first\" : \"\", \"last\": \"\" }, \"status\": \"active\" }"
228+
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
229+
doc.code.should eq(400)
230+
doc.parsed_response['errorNum'].should eq(1620)
231+
232+
body = "{ \"name\": { \"first\" : \"test\", \"last\": \"test\" } }"
233+
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
234+
doc.code.should eq(400)
235+
doc.parsed_response['errorNum'].should eq(1620)
236+
237+
body = "{ \"name\": { \"first\" : \"test\", \"last\": \"test\" }, \"status\": \"foo\" }"
238+
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
239+
doc.code.should eq(400)
240+
doc.parsed_response['errorNum'].should eq(1620)
241+
242+
body = "{ \"name\": { }, \"status\": \"active\" }"
243+
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
244+
doc.code.should eq(400)
245+
doc.parsed_response['errorNum'].should eq(1620)
246+
247+
body = "{ \"first\": \"abc\", \"last\": \"test\", \"status\": \"active\" }"
248+
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
249+
doc.code.should eq(400)
250+
doc.parsed_response['errorNum'].should eq(1620)
251+
end
252+
end
253+
160254
################################################################################
161255
## reading a collection
162256
################################################################################

0 commit comments

Comments
 (0)
0