Skip to content

Commit 976448e

Browse files
committed
_ is a forbidden character for container (repository)
According to [Containers naming guide](http://msdn.microsoft.com/en-us/library/dd135715.aspx): > A container name must be a valid DNS name, conforming to the following naming rules: > > * Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character. > * Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names. > * All letters in a container name must be lowercase. > * Container names must be from 3 through 63 characters long. We need to fix the documentation and control that before calling Azure API. The validation will come with issue #27. Closes #21. (cherry picked from commit 6531165)
1 parent 0005eab commit 976448e

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,21 @@ client.admin().cluster().preparePutRepository("my_backup3")
395395
).get();
396396
```
397397

398+
Repository validation rules
399+
---------------------------
400+
401+
According to the [containers naming guide](http://msdn.microsoft.com/en-us/library/dd135715.aspx), a container name must
402+
be a valid DNS name, conforming to the following naming rules:
403+
404+
* Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
405+
* Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not
406+
permitted in container names.
407+
* All letters in a container name must be lowercase.
408+
* Container names must be from 3 through 63 characters long.
409+
398410

399411
Testing
400-
-------
412+
=======
401413

402414
Integrations tests in this plugin require working Azure configuration and therefore disabled by default.
403415
To enable tests prepare a config file elasticsearch.yml with the following content:

src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java

+44
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.microsoft.windowsazure.services.core.ServiceException;
2424
import com.microsoft.windowsazure.services.core.storage.StorageException;
25+
import org.apache.lucene.util.LuceneTestCase;
2526
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
2627
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
2728
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
@@ -32,6 +33,7 @@
3233
import org.elasticsearch.common.Strings;
3334
import org.elasticsearch.common.settings.ImmutableSettings;
3435
import org.elasticsearch.common.settings.Settings;
36+
import org.elasticsearch.repositories.RepositoryException;
3537
import org.elasticsearch.repositories.RepositoryMissingException;
3638
import org.elasticsearch.snapshots.SnapshotState;
3739
import org.elasticsearch.test.ElasticsearchIntegrationTest;
@@ -44,6 +46,7 @@
4446

4547
import static org.hamcrest.Matchers.equalTo;
4648
import static org.hamcrest.Matchers.greaterThan;
49+
import static org.hamcrest.Matchers.is;
4750

4851
/**
4952
* This test needs Azure to run and -Dtests.azure=true to be set
@@ -224,6 +227,47 @@ public void testMultipleRepositories() {
224227
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(true));
225228
}
226229

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+
227271
/**
228272
* Deletes repositories, supports wildcard notation.
229273
*/

0 commit comments

Comments
 (0)