Fix settings serialization to not serialize secure settings or not take the total size into account (#25323)
This commit is contained in:
parent
8d9a08e239
commit
406a15e7a9
|
@ -610,8 +610,10 @@ public final class Settings implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeSettingsToStream(Settings settings, StreamOutput out) throws IOException {
|
public static void writeSettingsToStream(Settings settings, StreamOutput out) throws IOException {
|
||||||
out.writeVInt(settings.size());
|
// pull getAsMap() to exclude secure settings in size()
|
||||||
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
Set<Map.Entry<String, String>> entries = settings.getAsMap().entrySet();
|
||||||
|
out.writeVInt(entries.size());
|
||||||
|
for (Map.Entry<String, String> entry : entries) {
|
||||||
out.writeString(entry.getKey());
|
out.writeString(entry.getKey());
|
||||||
out.writeOptionalString(entry.getValue());
|
out.writeOptionalString(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.elasticsearch.common.settings;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.Booleans;
|
import org.elasticsearch.common.Booleans;
|
||||||
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||||
import org.elasticsearch.common.settings.loader.YamlSettingsLoader;
|
import org.elasticsearch.common.settings.loader.YamlSettingsLoader;
|
||||||
|
@ -590,6 +592,24 @@ public class SettingsTests extends ESTestCase {
|
||||||
assertTrue(Settings.builder().setSecureSettings(secureSettings).build().isEmpty());
|
assertTrue(Settings.builder().setSecureSettings(secureSettings).build().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testWriteSettingsToStream() throws IOException {
|
||||||
|
BytesStreamOutput out = new BytesStreamOutput();
|
||||||
|
MockSecureSettings secureSettings = new MockSecureSettings();
|
||||||
|
secureSettings.setString("test.key1.foo", "somethingsecure");
|
||||||
|
secureSettings.setString("test.key1.bar", "somethingsecure");
|
||||||
|
secureSettings.setString("test.key2.foo", "somethingsecure");
|
||||||
|
secureSettings.setString("test.key2.bog", "somethingsecure");
|
||||||
|
Settings.Builder builder = Settings.builder();
|
||||||
|
builder.put("test.key1.baz", "blah1");
|
||||||
|
builder.setSecureSettings(secureSettings);
|
||||||
|
assertEquals(5, builder.build().size());
|
||||||
|
Settings.writeSettingsToStream(builder.build(), out);
|
||||||
|
StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
|
||||||
|
Settings settings = Settings.readSettingsFromStream(in);
|
||||||
|
assertEquals(1, settings.size());
|
||||||
|
assertEquals("blah1", settings.get("test.key1.baz"));
|
||||||
|
}
|
||||||
|
|
||||||
public void testSecureSettingConflict() {
|
public void testSecureSettingConflict() {
|
||||||
Setting<SecureString> setting = SecureSetting.secureString("something.secure", null);
|
Setting<SecureString> setting = SecureSetting.secureString("something.secure", null);
|
||||||
Settings settings = Settings.builder().put("something.secure", "notreallysecure").build();
|
Settings settings = Settings.builder().put("something.secure", "notreallysecure").build();
|
||||||
|
|
Loading…
Reference in New Issue