Skip to content

Commit

Permalink
Validate SLM policy ids strictly (#45998)
Browse files Browse the repository at this point in the history
This uses strict validation for SLM policy ids, similar to what we use
for index names.

Resolves #45997
  • Loading branch information
dakrone authored Aug 29, 2019
1 parent 947fccb commit afdd000
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ public ActionRequestValidationException validate() {
ActionRequestValidationException err = new ActionRequestValidationException();

// ID validation
if (id.contains(",")) {
err.addValidationError("invalid policy id [" + id + "]: must not contain ','");
}
if (id.contains(" ")) {
err.addValidationError("invalid policy id [" + id + "]: must not contain spaces");
if (Strings.validFileName(id) == false) {
err.addValidationError("invalid policy id [" + id + "]: must not contain the following characters " +
Strings.INVALID_FILENAME_CHARS);
}
if (id.charAt(0) == '_') {
err.addValidationError("invalid policy id [" + id + "]: must not start with '_'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void testValidation() {

ValidationException e = policy.validate();
assertThat(e.validationErrors(),
containsInAnyOrder("invalid policy id [a,b]: must not contain ','",
containsInAnyOrder(
"invalid policy id [a,b]: must not contain the following characters [ , \", *, \\, <, |, ,, >, /, ?]",
"invalid snapshot name [<my, snapshot-{now/M}>]: must not contain contain" +
" the following characters [ , \", *, \\, <, |, ,, >, /, ?]",
"invalid repository name [ ]: cannot be empty",
Expand Down

0 comments on commit afdd000

Please sign in to comment.