Skip to content

Commit

Permalink
Fix writing of SecurityFeatureSetUsage to pre-7.1 (#38922)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jaymode authored Feb 14, 2019
1 parent 7d449c5 commit 5d06226
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeMap(realmsUsage);
out.writeMap(rolesStoreUsage);
out.writeMap(sslUsage);
out.writeMap(tokenServiceUsage);
out.writeMap(apiKeyServiceUsage);
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -250,5 +253,19 @@ public void testUsage() throws Exception {
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()));
}
}

0 comments on commit 5d06226

Please sign in to comment.