Skip to content

Commit cb78313

Browse files
committed
Adapt integration tests to secure settings
That was a missing part in #23405.
1 parent cb8289b commit cb78313

4 files changed

Lines changed: 31 additions & 39 deletions

File tree

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AbstractAzureWithThirdPartyIntegTestCase.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,25 @@
2626
import java.util.Arrays;
2727
import java.util.Collection;
2828

29-
import static org.elasticsearch.repositories.azure.AzureTestUtils.readSettingsFromFile;
29+
import static org.elasticsearch.repositories.azure.AzureTestUtils.generateMockSecureSettings;
3030

3131
/**
3232
* Base class for Azure tests that require credentials.
3333
* <p>
34-
* You must specify {@code -Dtests.thirdparty=true -Dtests.config=/path/to/config}
34+
* You must specify {@code -Dtests.thirdparty=true -Dtests.azure.account=AzureStorageAccount -Dtests.azure.key=AzureStorageKey}
3535
* in order to run these tests.
3636
*/
3737
@ThirdParty
3838
public abstract class AbstractAzureWithThirdPartyIntegTestCase extends AbstractAzureIntegTestCase {
3939

40+
Settings.Builder generateMockSettings() {
41+
return Settings.builder().setSecureSettings(generateMockSecureSettings());
42+
}
43+
4044
@Override
4145
protected Settings nodeSettings(int nodeOrdinal) {
42-
return Settings.builder()
46+
return generateMockSettings()
4347
.put(super.nodeSettings(nodeOrdinal))
44-
.put(readSettingsFromFile())
4548
.build();
4649
}
4750

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreListSnapshotsTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
import java.net.URISyntaxException;
3434
import java.util.concurrent.TimeUnit;
3535

36-
import static org.elasticsearch.repositories.azure.AzureTestUtils.readSettingsFromFile;
3736
import static org.elasticsearch.repositories.azure.AzureSnapshotRestoreTests.getContainerName;
3837
import static org.hamcrest.Matchers.equalTo;
3938
import static org.hamcrest.Matchers.lessThanOrEqualTo;
4039

4140
/**
4241
* This test needs Azure to run and -Dtests.thirdparty=true to be set
43-
* and -Dtests.config=/path/to/elasticsearch.yml
42+
* and -Dtests.azure.account=AzureStorageAccount and -Dtests.azure.key=AzureStorageKey
4443
*
4544
* Note that this test requires an Azure storage account, with the account
4645
* and credentials set in the elasticsearch.yml config file passed in to the
@@ -55,8 +54,8 @@
5554
transportClientRatio = 0.0)
5655
public class AzureSnapshotRestoreListSnapshotsTests extends AbstractAzureWithThirdPartyIntegTestCase {
5756

58-
private final AzureStorageService azureStorageService = new AzureStorageServiceImpl(readSettingsFromFile(),
59-
AzureStorageSettings.load(readSettingsFromFile()));
57+
private final AzureStorageService azureStorageService = new AzureStorageServiceImpl(generateMockSettings().build(),
58+
AzureStorageSettings.load(generateMockSettings().build()));
6059
private final String containerName = getContainerName();
6160

6261
public AzureSnapshotRestoreListSnapshotsTests() {

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,18 @@
4747
import org.junit.Before;
4848

4949
import java.net.URISyntaxException;
50+
import java.net.UnknownHostException;
5051
import java.util.Arrays;
5152
import java.util.Collection;
52-
import java.net.UnknownHostException;
5353
import java.util.Locale;
5454
import java.util.concurrent.TimeUnit;
5555

56-
import static org.elasticsearch.repositories.azure.AzureTestUtils.readSettingsFromFile;
5756
import static org.hamcrest.Matchers.equalTo;
5857
import static org.hamcrest.Matchers.greaterThan;
5958

6059
/**
6160
* This test needs Azure to run and -Dtests.thirdparty=true to be set
62-
* and -Dtests.config=/path/to/elasticsearch.yml
61+
* and -Dtests.azure.account=AzureStorageAccount and -Dtests.azure.key=AzureStorageKey
6362
* @see AbstractAzureWithThirdPartyIntegTestCase
6463
*/
6564
@ClusterScope(
@@ -546,10 +545,10 @@ public static void wipeRepositories(String... repositories) {
546545
* Purge the test containers
547546
*/
548547
public void cleanRepositoryFiles(String... containers) throws StorageException, URISyntaxException, UnknownHostException {
549-
Settings settings = readSettingsFromFile();
550-
AzureStorageService client = new AzureStorageServiceImpl(settings, AzureStorageSettings.load(settings));
548+
AzureStorageService client = new AzureStorageServiceImpl(generateMockSettings().build(),
549+
AzureStorageSettings.load(generateMockSettings().build()));
551550
for (String container : containers) {
552-
client.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
551+
client.removeContainer("default", LocationMode.PRIMARY_ONLY, container);
553552
}
554553
}
555554
}

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureTestUtils.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,27 @@
2020
package org.elasticsearch.repositories.azure;
2121

2222
import org.elasticsearch.common.Strings;
23-
import org.elasticsearch.common.io.PathUtils;
24-
import org.elasticsearch.common.settings.Settings;
25-
import org.elasticsearch.common.settings.SettingsException;
26-
27-
import java.io.IOException;
23+
import org.elasticsearch.common.settings.MockSecureSettings;
24+
import org.elasticsearch.common.settings.SecureSettings;
2825

2926
public class AzureTestUtils {
3027
/**
31-
* Read settings from file when running integration tests with ThirdParty annotation.
32-
* elasticsearch.yml file path has to be set with -Dtests.config=/path/to/elasticsearch.yml.
33-
* @return Settings from elasticsearch.yml integration test file (for 3rd party tests)
28+
* Mock secure settings from sysprops when running integration tests with ThirdParty annotation.
29+
* Start the tests with {@code -Dtests.azure.account=AzureStorageAccount and -Dtests.azure.key=AzureStorageKey}
30+
* @return Mock Settings from sysprops
3431
*/
35-
public static Settings readSettingsFromFile() {
36-
Settings.Builder settings = Settings.builder();
32+
public static SecureSettings generateMockSecureSettings() {
33+
MockSecureSettings secureSettings = new MockSecureSettings();
3734

38-
// if explicit, just load it and don't load from env
39-
try {
40-
if (Strings.hasText(System.getProperty("tests.config"))) {
41-
try {
42-
settings.loadFromPath(PathUtils.get((System.getProperty("tests.config"))));
43-
} catch (IOException e) {
44-
throw new IllegalArgumentException("could not load azure tests config", e);
45-
}
46-
} else {
47-
throw new IllegalStateException("to run integration tests, you need to set -Dtests.thirdparty=true and " +
48-
"-Dtests.config=/path/to/elasticsearch.yml");
49-
}
50-
} catch (SettingsException exception) {
51-
throw new IllegalStateException("your test configuration file is incorrect: " + System.getProperty("tests.config"), exception);
35+
if (Strings.isEmpty(System.getProperty("tests.azure.account")) ||
36+
Strings.isEmpty(System.getProperty("tests.azure.key"))) {
37+
throw new IllegalStateException("to run integration tests, you need to set -Dtests.thirdparty=true and " +
38+
"-Dtests.azure.account=azure-account -Dtests.azure.key=azure-key");
5239
}
53-
return settings.build();
40+
41+
secureSettings.setString("azure.client.default.account", System.getProperty("tests.azure.account"));
42+
secureSettings.setString("azure.client.default.key", System.getProperty("tests.azure.key"));
43+
44+
return secureSettings;
5445
}
5546
}

0 commit comments

Comments
 (0)