8000 Bug fix/schema validation return code by jsteemann · Pull Request #11341 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/schema validation return code #11341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy state 8000 ment. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion arangod/VocBase/Validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ ValidatorJsonSchema::ValidatorJsonSchema(VPackSlice params) : ValidatorBase(para
if (!rule.isObject()) {
std::string msg = "No valid schema in rule attribute given (no object): ";
msg += params.toJson();
LOG_TOPIC("ababf", ERR, Logger::VALIDATION) << msg;
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_VALIDATION_BAD_PARAMETER, msg);
}
auto taoRuleValue = validation::slice_to_value(rule);
Expand Down
2 changes: 1 addition & 1 deletion lib/ApplicationFeatures/EnvironmentFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void EnvironmentFeature::prepare() {
overriddenmsg = " (overridden by environment variable)";
}
LOG_TOPIC("25362", INFO, Logger::MEMORY)
<< "Available physical memory: " << ram << overriddenmsg;
<< "Available physical memory: " << ram << overriddenmsg << " bytes";

// test local ipv6 support
try {
Expand Down
2 changes: 2 additions & 0 deletions lib/Rest/GeneralResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ rest::ResponseCode GeneralResponse::responseCode(int code) {
case TRI_ERROR_KEY_MUST_BE_PREFIXED_WITH_SMART_JOIN_ATTRIBUTE:
case TRI_ERROR_NO_SMART_JOIN_ATTRIBUTE:
case TRI_ERROR_CLUSTER_MUST_NOT_CHANGE_SMART_JOIN_ATTRIBUTE:
case TRI_ERROR_VALIDATION_FAILED:
case TRI_ERROR_VALIDATION_BAD_PARAMETER:
return ResponseCode::BAD;

case TRI_ERROR_ARANGO_USE_SYSTEM_DATABASE:
Expand Down
94 changes: 94 additions & 0 deletions tests/rb/HttpInterface/api-collection-rocksdb-spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,100 @@
end
end

################################################################################
## schema validation
################################################################################

context "schema validation:" do
before do
@cn = "UnitTestsCollectionBasics"
ArangoDB.drop_collection(@cn)
@cid = ArangoDB.create_collection(@cn, false)
end

after do
ArangoDB.drop_collection(@cn)
end

it "sets an invalid schema" do
cmd = api + "/" + @cn + "/properties"
body = "{ \"validation\": { \"rule\": \"peng!\", \"level\": \"strict\", \"message\": \"document has an invalid schema!\" } }"
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)

doc.code.should eq(400)
doc.parsed_response['error'].should eq(true)
doc.parsed_response['code'].should eq(400)
doc.parsed_response['errorNum'].should eq(1621)
end

it "sets a valid schema" do
cmd = api + "/" + @cn + "/properties"
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!\" } }"
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)
doc = ArangoDB.log_get("#{prefix}-get-schema", cmd)

doc.code.should eq(200)
doc.headers['content-type'].should eq("application/json; charset=utf-8")
doc.parsed_response['error'].should eq(false)
doc.parsed_response['code'].should eq(200)
doc.parsed_response['id'].should eq(@cid)
doc.parsed_response['name'].should eq(@cn)
doc.parsed_response['validation']['level'].should eq("strict")
doc.parsed_response['validation']['message'].should eq("document has an invalid schema!")
end

it "stores valid documents" do
cmd = api + "/" + @cn + "/properties"
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!\" } }"
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)
doc.code.should eq(200)

body = "{ \"name\": { \"first\": \"test\", \"last\": \"test\" }, \"status\": \"active\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(202)

body = "{ \"name\": { \"first\": \"a\", \"last\": \"b\" }, \"status\": \"inactive\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(202)
end

it "stores invalid documents" do
cmd = api + "/" + @cn + "/properties"
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!\" } }"
doc = ArangoDB.log_put("#{prefix}-schema", cmd, :body => body)

body = "{ \"name\": { \"first\" : \"\", \"last\": \"test\" }, \"status\": \"active\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(400)
doc.parsed_response['errorNum'].should eq(1620)

body = "{ \"name\": { \"first\" : \"\", \"last\": \"\" }, \"status\": \"active\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(400)
doc.parsed_response['errorNum'].should eq(1620)

body = "{ \"name\": { \"first\" : \"test\", \"last\": \"test\" } }"
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(400)
doc.parsed_response['errorNum'].should eq(1620)

body = "{ \"name\": { \"first\" : \"test\", \"last\": \"test\" }, \"status\": \"foo\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(400)
doc.parsed_response['errorNum'].should eq(1620)

body = "{ \"name\": { }, \"status\": \"active\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(400)
doc.parsed_response['errorNum'].should eq(1620)

body = "{ \"first\": \"abc\", \"last\": \"test\", \"status\": \"active\" }"
doc = ArangoDB.log_post("#{prefix}-schema-doc-invalid", "/_api/document/?collection=" + @cn, :body => body)
doc.code.should eq(400)
doc.parsed_response['errorNum'].should eq(1620)
end
end

################################################################################
## reading a collection
################################################################################
Expand Down
0