Test: Allow merging mock secure settings (#25387)

While real secure settings (ie an ES keystore) cannot be merged
together, mocked secure settings can and need to be sometimes merged.
This commit adds a merge method to allow tests to merge together
multiple instances of secure settings.
This commit is contained in:
Ryan Ernst 2017-06-25 10:19:51 -07:00 committed by GitHub
parent 4e4a104f4a
commit 1583f81047
3 changed files with 18 additions and 2 deletions

View File

@ -718,6 +718,10 @@ public final class Settings implements ToXContent {
if (secureSettings.isLoaded() == false) { if (secureSettings.isLoaded() == false) {
throw new IllegalStateException("Secure settings must already be loaded"); throw new IllegalStateException("Secure settings must already be loaded");
} }
if (this.secureSettings.get() != null) {
throw new IllegalArgumentException("Secure settings already set. Existing settings: " +
this.secureSettings.get().getSettingNames() + ", new settings: " + secureSettings.getSettingNames());
}
this.secureSettings.set(secureSettings); this.secureSettings.set(secureSettings);
return this; return this;
} }

View File

@ -677,8 +677,8 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
continue; continue;
} }
Settings mergedSettings = Settings.builder() Settings mergedSettings = Settings.builder()
.put(defaultSettings) .put(defaultSettings.getAsMap())
.put(profileSettings) .put(profileSettings.getAsMap())
.build(); .build();
result.put(name, mergedSettings); result.put(name, mergedSettings);
} }

View File

@ -72,6 +72,18 @@ public class MockSecureSettings implements SecureSettings {
settingNames.add(setting); settingNames.add(setting);
} }
/** Merge the given secure settings into this one. */
public void merge(MockSecureSettings secureSettings) {
for (String setting : secureSettings.getSettingNames()) {
if (settingNames.contains(setting)) {
throw new IllegalArgumentException("Cannot overwrite existing secure setting " + setting);
}
}
settingNames.addAll(secureSettings.settingNames);
secureStrings.putAll(secureSettings.secureStrings);
files.putAll(secureSettings.files);
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
closed.set(true); closed.set(true);