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:
parent
4e4a104f4a
commit
1583f81047
|
@ -718,6 +718,10 @@ public final class Settings implements ToXContent {
|
|||
if (secureSettings.isLoaded() == false) {
|
||||
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);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -677,8 +677,8 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
|
|||
continue;
|
||||
}
|
||||
Settings mergedSettings = Settings.builder()
|
||||
.put(defaultSettings)
|
||||
.put(profileSettings)
|
||||
.put(defaultSettings.getAsMap())
|
||||
.put(profileSettings.getAsMap())
|
||||
.build();
|
||||
result.put(name, mergedSettings);
|
||||
}
|
||||
|
|
|
@ -72,6 +72,18 @@ public class MockSecureSettings implements SecureSettings {
|
|||
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
|
||||
public void close() throws IOException {
|
||||
closed.set(true);
|
||||
|
|
Loading…
Reference in New Issue