Skip to content

Commit

Permalink
_ is a forbidden character for container (repository)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
dadoonet committed Jul 30, 2014
1 parent 0005eab commit 976448e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -395,9 +395,21 @@ client.admin().cluster().preparePutRepository("my_backup3")
).get();
```

Repository validation rules
---------------------------

According to the [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.


Testing
-------
=======

Integrations tests in this plugin require working Azure configuration and therefore disabled by default.
To enable tests prepare a config file elasticsearch.yml with the following content:
Expand Down
Expand Up @@ -22,6 +22,7 @@

import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.core.storage.StorageException;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
Expand All @@ -32,6 +33,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.repositories.RepositoryException;
import org.elasticsearch.repositories.RepositoryMissingException;
import org.elasticsearch.snapshots.SnapshotState;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
Expand All @@ -44,6 +46,7 @@

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;

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

/**
* For issue #21: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/21
*/
@Test @LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/21")
public void testForbiddenContainerName() {
checkContainerName("", false);
checkContainerName("es", false);
checkContainerName("-elasticsearch", false);
checkContainerName("elasticsearch--integration", false);
checkContainerName("elasticsearch_integration", false);
checkContainerName("ElAsTicsearch_integration", false);
checkContainerName("123456789-123456789-123456789-123456789-123456789-123456789-1234", false);
checkContainerName("123456789-123456789-123456789-123456789-123456789-123456789-123", true);
checkContainerName("elasticsearch-integration", true);
checkContainerName("elasticsearch-integration-007", true);
}

/**
* Create repository with wrong or correct container name
* @param container Container name we want to create
* @param correct Is this container name correct
*/
private void checkContainerName(String container, boolean correct) {
logger.info("--> creating azure repository with container name [{}]", container);
try {
PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo")
.setType("azure").setSettings(ImmutableSettings.settingsBuilder()
.put(AzureStorageService.Fields.CONTAINER, container)
.put(AzureStorageService.Fields.BASE_PATH, basePath)
.put(AzureStorageService.Fields.CHUNK_SIZE, randomIntBetween(1000, 10000))
).get();
assertThat(putRepositoryResponse.isAcknowledged(), is(correct));
client().admin().cluster().prepareDeleteRepository("test-repo").get();
} catch (RepositoryException e) {
if (correct) {
// We did not expect any exception here :(
throw e;
}
}
}

/**
* Deletes repositories, supports wildcard notation.
*/
Expand Down

0 comments on commit 976448e

Please sign in to comment.