Validate SLM policy ids strictly (#45998) (#46145)

This uses strict validation for SLM policy ids, similar to what we use
for index names.

Resolves #45997
This commit is contained in:
Lee Hinman 2019-09-03 09:20:02 -06:00 committed by GitHub
parent f77aed8ea9
commit 3d4b8e01c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -128,11 +128,9 @@ public class SnapshotLifecyclePolicy extends AbstractDiffable<SnapshotLifecycleP
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 '_'");

View File

@ -56,7 +56,8 @@ public class SnapshotLifecyclePolicyTests extends AbstractSerializingTestCase<Sn
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",