|
22 | 22 |
|
23 | 23 | import com.microsoft.windowsazure.services.core.ServiceException;
|
24 | 24 | import com.microsoft.windowsazure.services.core.storage.StorageException;
|
| 25 | +import org.apache.lucene.util.LuceneTestCase; |
25 | 26 | import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
|
26 | 27 | import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
27 | 28 | import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
|
32 | 33 | import org.elasticsearch.common.Strings;
|
33 | 34 | import org.elasticsearch.common.settings.ImmutableSettings;
|
34 | 35 | import org.elasticsearch.common.settings.Settings;
|
| 36 | +import org.elasticsearch.repositories.RepositoryException; |
35 | 37 | import org.elasticsearch.repositories.RepositoryMissingException;
|
36 | 38 | import org.elasticsearch.snapshots.SnapshotState;
|
37 | 39 | import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
|
44 | 46 |
|
45 | 47 | import static org.hamcrest.Matchers.equalTo;
|
46 | 48 | import static org.hamcrest.Matchers.greaterThan;
|
| 49 | +import static org.hamcrest.Matchers.is; |
47 | 50 |
|
48 | 51 | /**
|
49 | 52 | * This test needs Azure to run and -Dtests.azure=true to be set
|
@@ -224,6 +227,47 @@ public void testMultipleRepositories() {
|
224 | 227 | assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(true));
|
225 | 228 | }
|
226 | 229 |
|
| 230 | + /** |
| 231 | + * For issue #21: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/21 |
| 232 | + */ |
| 233 | + @Test @LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/21") |
| 234 | + public void testForbiddenContainerName() { |
| 235 | + checkContainerName("", false); |
| 236 | + checkContainerName("es", false); |
| 237 | + checkContainerName("-elasticsearch", false); |
| 238 | + checkContainerName("elasticsearch--integration", false); |
| 239 | + checkContainerName("elasticsearch_integration", false); |
| 240 | + checkContainerName("ElAsTicsearch_integration", false); |
| 241 | + checkContainerName("123456789-123456789-123456789-123456789-123456789-123456789-1234", false); |
| 242 | + checkContainerName("123456789-123456789-123456789-123456789-123456789-123456789-123", true); |
| 243 | + checkContainerName("elasticsearch-integration", true); |
| 244 | + checkContainerName("elasticsearch-integration-007", true); |
| 245 | + } |
| 246 | + |
| 247 | + /** |
| 248 | + * Create repository with wrong or correct container name |
| 249 | + * @param container Container name we want to create |
| 250 | + * @param correct Is this container name correct |
| 251 | + */ |
| 252 | + private void checkContainerName(String container, boolean correct) { |
| 253 | + logger.info("--> creating azure repository with container name [{}]", container); |
| 254 | + try { |
| 255 | + PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") |
| 256 | + .setType("azure").setSettings(ImmutableSettings.settingsBuilder() |
| 257 | + .put(AzureStorageService.Fields.CONTAINER, container) |
| 258 | + .put(AzureStorageService.Fields.BASE_PATH, basePath) |
| 259 | + .put(AzureStorageService.Fields.CHUNK_SIZE, randomIntBetween(1000, 10000)) |
| 260 | + ).get(); |
| 261 | + assertThat(putRepositoryResponse.isAcknowledged(), is(correct)); |
| 262 | + client().admin().cluster().prepareDeleteRepository("test-repo").get(); |
| 263 | + } catch (RepositoryException e) { |
| 264 | + if (correct) { |
| 265 | + // We did not expect any exception here :( |
| 266 | + throw e; |
| 267 | + } |
| 268 | + } |
| 269 | + } |
| 270 | + |
227 | 271 | /**
|
228 | 272 | * Deletes repositories, supports wildcard notation.
|
229 | 273 | */
|
|
0 commit comments