Fix writing of SecurityFeatureSetUsage to pre-7.1 (#38922)
This change makes the writing of new usage data conditional based on the version that is being written to. A test has also been added to ensure serialization works as expected to an older version. Relates #38687, #38917
This commit is contained in:
parent
7d449c5f65
commit
5d06226507
|
@ -80,8 +80,10 @@ public class SecurityFeatureSetUsage extends XPackFeatureSet.Usage {
|
|||
out.writeMap(realmsUsage);
|
||||
out.writeMap(rolesStoreUsage);
|
||||
out.writeMap(sslUsage);
|
||||
if (out.getVersion().onOrAfter(Version.V_7_1_0)) {
|
||||
out.writeMap(tokenServiceUsage);
|
||||
out.writeMap(apiKeyServiceUsage);
|
||||
}
|
||||
out.writeMap(auditUsage);
|
||||
out.writeMap(ipFilterUsage);
|
||||
if (out.getVersion().before(Version.V_6_0_0_beta1)) {
|
||||
|
|
|
@ -5,16 +5,19 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.security;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.PlainActionFuture;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.xpack.core.XPackFeatureSet;
|
||||
import org.elasticsearch.xpack.core.XPackField;
|
||||
import org.elasticsearch.xpack.core.XPackSettings;
|
||||
|
@ -250,5 +253,19 @@ public class SecurityFeatureSetTests extends ESTestCase {
|
|||
assertThat(source.getValue("roles"), is(nullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
out = new BytesStreamOutput();
|
||||
out.setVersion(VersionUtils.randomVersionBetween(random(), Version.V_6_7_0, Version.V_7_0_0));
|
||||
securityUsage.writeTo(out);
|
||||
StreamInput input = out.bytes().streamInput();
|
||||
input.setVersion(out.getVersion());
|
||||
serializedUsage = new SecurityFeatureSetUsage(input);
|
||||
XContentSource source;
|
||||
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
|
||||
serializedUsage.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
source = new XContentSource(builder);
|
||||
}
|
||||
assertThat(source.getValue("token_service"), is(nullValue()));
|
||||
assertThat(source.getValue("api_key_service"), is(nullValue()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue