Merge pull request #13862 from xuzha/index_name_dot

Forbid index name `.` and `..`
This commit is contained in:
Xu Zhang 2015-10-04 20:20:31 -07:00
commit 83366e7017
2 changed files with 22 additions and 1 deletions

View File

@ -203,6 +203,9 @@ public class MetaDataCreateIndexService extends AbstractComponent {
if (state.metaData().hasAlias(index)) {
throw new InvalidIndexNameException(new Index(index), index, "already exists as alias");
}
if (index.equals(".") || index.equals("..")) {
throw new InvalidIndexNameException(new Index(index), index, "must not be '.' or '..'");
}
}
private void createIndex(final CreateIndexClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener, final Semaphore mdLock) {

View File

@ -203,7 +203,7 @@ public class IndexActionIT extends ESIntegTestCase {
try {
// Catch chars that are more than a single byte
client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES -1).toLowerCase(Locale.ROOT) +
client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES - 1).toLowerCase(Locale.ROOT) +
"Ϟ".toLowerCase(Locale.ROOT),
"mytype").setSource("foo", "bar").get();
fail("exception should have been thrown on too-long index name");
@ -215,4 +215,22 @@ public class IndexActionIT extends ESIntegTestCase {
// we can create an index of max length
createIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES).toLowerCase(Locale.ROOT));
}
public void testInvalidIndexName() {
try {
createIndex(".");
fail("exception should have been thrown on dot index name");
} catch (InvalidIndexNameException e) {
assertThat("exception contains message about index name is dot " + e.getMessage(),
e.getMessage().contains("Invalid index name [.], must not be \'.\' or '..'"), equalTo(true));
}
try {
createIndex("..");
fail("exception should have been thrown on dot index name");
} catch (InvalidIndexNameException e) {
assertThat("exception contains message about index name is dot " + e.getMessage(),
e.getMessage().contains("Invalid index name [..], must not be \'.\' or '..'"), equalTo(true));
}
}
}