Skip to content
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 statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate xContentType in PutWatchRequest. #31088

Merged
merged 4 commits into from
Jun 12, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public ActionRequestValidationException validate() {
if (source == null) {
validationException = ValidateActions.addValidationError("watch source is missing", validationException);
}
if (xContentType == null) {
validationException = ValidateActions.addValidationError("request body is missing", validationException);
}
return validationException;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"body": {
"description" : "The watch",
"required" : true
"required" : false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@
}
}
- match: { _id: "my_watch" }

---
"Test empty body is rejected by put watch":
- do:
cluster.health:
wait_for_status: yellow

- do:
catch: bad_request
xpack.watcher.put_watch:
id: "my_watch"
- match: { error.root_cause.0.type: "action_request_validation_exception" }
- match: { error.root_cause.0.reason: "Validation Failed: 1: request body is missing;" }
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public void testPutWatchSourceNull() {
assertThat(e.validationErrors(), hasItem("watch source is missing"));
}

public void testPutWatchContentNull() {
ActionRequestValidationException e = new PutWatchRequest("foo", BytesArray.EMPTY, null).validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("request body is missing"));
}

public void testGetWatchInvalidWatchId() {
ActionRequestValidationException e = new GetWatchRequest("id with whitespaces").validate();
assertThat(e, is(notNullValue()));
Expand Down