Fix static / version based BWC tests (elastic/x-pack-elasticsearch#1456)

With the leniency in Version.java we missed to really setup BWC
testing for static indices. This change brings back the testing and adds
missing bwc indices.

Relates to elastic/elasticsearch#24732

Original commit: elastic/x-pack-elasticsearch@85e6270338
This commit is contained in:
Simon Willnauer 2017-05-17 17:28:35 +02:00 committed by GitHub
parent bfc3779f51
commit d2e1b31bc7
24 changed files with 38 additions and 43 deletions

View File

@ -235,7 +235,7 @@ public class XPackInfoResponse extends ActionResponse {
public FeatureSet(StreamInput in) throws IOException {
this(in.readString(), in.readOptionalString(), in.readBoolean(), in.readBoolean(),
in.getVersion().onOrAfter(Version.V_5_4_0_UNRELEASED) ? in.readMap() : null);
in.getVersion().onOrAfter(Version.V_5_4_0) ? in.readMap() : null);
}
public FeatureSet(String name, @Nullable String description, boolean available, boolean enabled,
@ -287,7 +287,7 @@ public class XPackInfoResponse extends ActionResponse {
out.writeOptionalString(description);
out.writeBoolean(available);
out.writeBoolean(enabled);
if (out.getVersion().onOrAfter(Version.V_5_4_0_UNRELEASED)) {
if (out.getVersion().onOrAfter(Version.V_5_4_0)) {
out.writeMap(nativeCodeInfo);
}
}

View File

@ -90,7 +90,7 @@ public class MlMetadata implements MetaData.Custom {
@Override
public Version getMinimalSupportedVersion() {
return Version.V_5_4_0_UNRELEASED;
return Version.V_5_4_0;
}
@Override

View File

@ -64,7 +64,7 @@ public class MonitoringBulkDoc extends MonitoringDoc implements Writeable {
String id = in.readOptionalString();
BytesReference source = in.readBytesReference();
XContentType xContentType;
if (source != BytesArray.EMPTY && in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
if (source != BytesArray.EMPTY && in.getVersion().onOrAfter(Version.V_5_3_0)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(source);
@ -84,7 +84,7 @@ public class MonitoringBulkDoc extends MonitoringDoc implements Writeable {
out.writeOptionalString(type);
out.writeOptionalString(id);
out.writeBytesReference(source);
if (source != null && source != BytesArray.EMPTY && out.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
if (source != null && source != BytesArray.EMPTY && out.getVersion().onOrAfter(Version.V_5_3_0)) {
xContentType.writeTo(out);
}
}

View File

@ -183,7 +183,7 @@ public final class PersistentTasksCustomMetaData extends AbstractNamedDiffable<M
@Override
public Version getMinimalSupportedVersion() {
return Version.V_5_4_0_UNRELEASED;
return Version.V_5_4_0;
}
@Override

View File

@ -25,7 +25,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.common.xcontent.XContentUtils;
import org.elasticsearch.xpack.security.authz.privilege.ClusterPrivilege;
import org.elasticsearch.xpack.security.support.MetadataUtils;
import org.elasticsearch.xpack.security.support.Validation;
@ -179,7 +178,7 @@ public class RoleDescriptor implements ToXContentObject {
Map<String, Object> metadata = in.readMap();
final Map<String, Object> transientMetadata;
if (in.getVersion().onOrAfter(Version.V_5_2_0_UNRELEASED)) {
if (in.getVersion().onOrAfter(Version.V_5_2_0)) {
transientMetadata = in.readMap();
} else {
transientMetadata = Collections.emptyMap();
@ -196,7 +195,7 @@ public class RoleDescriptor implements ToXContentObject {
}
out.writeStringArray(descriptor.runAs);
out.writeMap(descriptor.metadata);
if (out.getVersion().onOrAfter(Version.V_5_2_0_UNRELEASED)) {
if (out.getVersion().onOrAfter(Version.V_5_2_0)) {
out.writeMap(descriptor.transientMetadata);
}
}

View File

@ -94,7 +94,7 @@ public class SecurityServerTransportInterceptor extends AbstractComponent implem
securityContext.executeAsUser(SystemUser.INSTANCE, (original) -> sendWithUser(connection, action, request, options,
new ContextRestoreResponseHandler<>(threadPool.getThreadContext().wrapRestorable(original)
, handler), sender), connection.getVersion());
} else if (reservedRealmEnabled && connection.getVersion().before(Version.V_5_2_0_UNRELEASED) &&
} else if (reservedRealmEnabled && connection.getVersion().before(Version.V_5_2_0) &&
KibanaUser.NAME.equals(securityContext.getUser().principal())) {
final User kibanaUser = securityContext.getUser();
final User bwcKibanaUser = new User(kibanaUser.principal(), new String[] { "kibana" }, kibanaUser.fullName(),

View File

@ -124,7 +124,7 @@ public interface ServerTransportFilter {
}
authcService.authenticate(securityAction, request, null, ActionListener.wrap((authentication) -> {
if (reservedRealmEnabled && authentication.getVersion().before(Version.V_5_2_0_UNRELEASED) &&
if (reservedRealmEnabled && authentication.getVersion().before(Version.V_5_2_0) &&
KibanaUser.NAME.equals(authentication.getUser().authenticatedUser().principal())) {
executeAsCurrentVersionKibanaUser(securityAction, request, transportChannel, listener, authentication);
} else if (securityAction.equals(TransportService.HANDSHAKE_ACTION_NAME) &&

View File

@ -15,7 +15,7 @@ public class LogstashSystemUser extends User {
public static final String NAME = "logstash_system";
private static final String ROLE_NAME = "logstash_system";
public static final Version DEFINED_SINCE = Version.V_5_2_0_UNRELEASED;
public static final Version DEFINED_SINCE = Version.V_5_2_0;
public static final BuiltinUserInfo USER_INFO = new BuiltinUserInfo(NAME, ROLE_NAME, DEFINED_SINCE);
public LogstashSystemUser(boolean enabled) {

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.security.user;
import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.Version;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
@ -197,7 +196,7 @@ public class User implements ToXContentObject {
boolean hasInnerUser = input.readBoolean();
if (hasInnerUser) {
User innerUser = readFrom(input);
if (input.getVersion().onOrBefore(Version.V_5_4_0_UNRELEASED)) {
if (input.getVersion().onOrBefore(Version.V_5_4_0)) {
// backcompat: runas user was read first, so reverse outer and inner
return new User(innerUser, outerUser);
} else {
@ -219,7 +218,7 @@ public class User implements ToXContentObject {
if (user.authenticatedUser == null) {
// no backcompat necessary, since there is no inner user
writeUser(user, output);
} else if (output.getVersion().onOrBefore(Version.V_5_4_0_UNRELEASED)) {
} else if (output.getVersion().onOrBefore(Version.V_5_4_0)) {
// backcompat: write runas user as the "inner" user
writeUser(user.authenticatedUser, output);
output.writeBoolean(true);

View File

@ -240,7 +240,7 @@ public class ExecuteWatchRequest extends MasterNodeReadRequest<ExecuteWatchReque
}
if (in.readBoolean()) {
watchSource = in.readBytesReference();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
if (in.getVersion().onOrAfter(Version.V_5_3_0)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(watchSource);
@ -272,7 +272,7 @@ public class ExecuteWatchRequest extends MasterNodeReadRequest<ExecuteWatchReque
out.writeBoolean(watchSource != null);
if (watchSource != null) {
out.writeBytesReference(watchSource);
if (out.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
if (out.getVersion().onOrAfter(Version.V_5_3_0)) {
xContentType.writeTo(out);
}
}

View File

@ -125,7 +125,7 @@ public class PutWatchRequest extends MasterNodeRequest<PutWatchRequest> {
id = in.readString();
source = in.readBytesReference();
active = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
if (in.getVersion().onOrAfter(Version.V_5_3_0)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(source);
@ -138,7 +138,7 @@ public class PutWatchRequest extends MasterNodeRequest<PutWatchRequest> {
out.writeString(id);
out.writeBytesReference(source);
out.writeBoolean(active);
if (out.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
if (out.getVersion().onOrAfter(Version.V_5_3_0)) {
xContentType.writeTo(out);
}
}

View File

@ -101,7 +101,7 @@ public abstract class AbstractOldXPackIndicesBackwardsCompatibilityTestCase exte
SortedSet<String> expectedVersions = new TreeSet<>();
for (Version v : VersionUtils.allReleasedVersions()) {
if (false == shouldTestVersion(v)) continue;
if (v.before(Version.V_5_0_0)) continue; // we can only support one major version backward
if (v.before(Version.CURRENT.minimumIndexCompatibilityVersion())) continue; // we can only support one major version backward
if (v.equals(Version.CURRENT)) continue; // the current version is always compatible with itself
if (v.isBeta() == true || v.isAlpha() == true || v.isRC() == true) continue; // don't check alphas etc
expectedVersions.add("x-pack-" + v.toString() + ".zip");

View File

@ -87,7 +87,6 @@ public class OldSecurityIndexBackwardsCompatibilityTests extends AbstractOldXPac
assertThat(builder.string(),
anyOf(containsString("\"roles\":{\"native\":{\"size\":1,\"fls\":true,\"dls\":true}"),
containsString("\"roles\":{\"native\":{\"size\":1,\"dls\":true,\"fls\":true}")));
}
}
@ -128,7 +127,7 @@ public class OldSecurityIndexBackwardsCompatibilityTests extends AbstractOldXPac
/* check that a search that misses all documents doesn't hit any alias starting with `-`. We have one in the backwards compatibility
* indices for versions before 5.1.0 because we can't create them any more. */
if (version.before(Version.V_5_1_1_UNRELEASED)) {
if (version.before(Version.V_5_1_1)) {
GetAliasesResponse aliasesResponse = client().admin().indices().prepareGetAliases().get();
List<AliasMetaData> aliases = aliasesResponse.getAliases().get("index3");
assertThat("alias doesn't exist", aliases, hasSize(1));

View File

@ -64,7 +64,7 @@ public class JobStateTests extends ESTestCase {
@SuppressWarnings("unchecked")
public void testStreaming_v54BackwardsCompatibility() throws IOException {
StreamOutput out = mock(StreamOutput.class);
when(out.getVersion()).thenReturn(Version.V_5_4_0_UNRELEASED);
when(out.getVersion()).thenReturn(Version.V_5_4_0);
ArgumentCaptor<Enum> enumCaptor = ArgumentCaptor.forClass(Enum.class);
doAnswer(new Answer<Void>() {

View File

@ -59,7 +59,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
public void testSerializationBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("AQNtSWQBBTUuMS4yAAAAAQEEdHlwZQECaWQNeyJmb28iOiJiYXIifQAAAAAAAAAA");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
Version.V_5_1_1, Version.V_5_1_2, Version.V_5_2_0);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
MonitoringBulkDoc bulkDoc = MonitoringBulkDoc.readFrom(in);

View File

@ -40,7 +40,7 @@ public class MonitoringDocTests extends ESTestCase {
String nodeId = randomAlphaOfLength(5);
TransportAddress address = buildNewFakeTransportAddress();
Version version = randomFrom(Version.V_5_0_1, Version.V_5_3_0_UNRELEASED, Version.CURRENT);
Version version = randomFrom(Version.V_5_0_1, Version.V_5_3_0, Version.CURRENT);
String name = randomBoolean() ? randomAlphaOfLength(5) : "";
Map<String, String> attributes = new HashMap<>();

View File

@ -167,7 +167,7 @@ public class NativeRealmMigratorTests extends ESTestCase {
.immutableMap()
);
String[] disabledUsers = new String[]{LogstashSystemUser.NAME, BeatsSystemUser.NAME};
verifyUpgrade(randomFrom(Version.V_5_1_1_UNRELEASED, Version.V_5_0_2, Version.V_5_0_0), disabledUsers, true);
verifyUpgrade(randomFrom(Version.V_5_1_1, Version.V_5_0_2, Version.V_5_0_0), disabledUsers, true);
}
public void testDisableBeatsAndConvertPasswordsOnUpgradeFromVersionPriorToV6() throws Exception {
@ -179,7 +179,7 @@ public class NativeRealmMigratorTests extends ESTestCase {
.immutableMap()
);
String[] disabledUsers = new String[]{BeatsSystemUser.NAME};
Version version = randomFrom(Version.V_5_3_0_UNRELEASED, Version.V_5_2_1_UNRELEASED);
Version version = randomFrom(Version.V_5_3_0, Version.V_5_2_1);
verifyUpgrade(version, disabledUsers, true);
}
@ -193,7 +193,7 @@ public class NativeRealmMigratorTests extends ESTestCase {
.immutableMap()
));
String[] disabledUsers = new String[]{BeatsSystemUser.NAME};
verifyUpgrade(Version.V_5_2_0_UNRELEASED, disabledUsers, true);
verifyUpgrade(Version.V_5_2_0, disabledUsers, true);
}
private void verifyUpgrade(Version fromVersion, String[] disabledUsers, boolean convertDefaultPasswords) throws Exception {

View File

@ -360,13 +360,13 @@ public class ReservedRealmTests extends ESTestCase {
switch (principal) {
case LogstashSystemUser.NAME:
assertThat(versionPredicate.test(Version.V_5_0_0), is(false));
assertThat(versionPredicate.test(Version.V_5_1_1_UNRELEASED), is(false));
assertThat(versionPredicate.test(Version.V_5_2_0_UNRELEASED), is(true));
assertThat(versionPredicate.test(Version.V_5_1_1), is(false));
assertThat(versionPredicate.test(Version.V_5_2_0), is(true));
break;
default:
assertThat(versionPredicate.test(Version.V_5_0_0), is(true));
assertThat(versionPredicate.test(Version.V_5_1_1_UNRELEASED), is(true));
assertThat(versionPredicate.test(Version.V_5_2_0_UNRELEASED), is(true));
assertThat(versionPredicate.test(Version.V_5_1_1), is(true));
assertThat(versionPredicate.test(Version.V_5_2_0), is(true));
break;
}
assertThat(versionPredicate.test(Version.V_6_0_0_alpha1_UNRELEASED), is(true));

View File

@ -31,7 +31,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentType;
@ -183,7 +182,7 @@ public class IndexLifecycleManagerTests extends ESTestCase {
assertThat(manager.isTemplateCreationPending(), Matchers.equalTo(templateUpdatePending));
assertThat(manager.isMappingUpToDate(), Matchers.equalTo(false));
assertThat(manager.getMappingVersion(), Matchers.equalTo(Version.V_5_1_2_UNRELEASED));
assertThat(manager.getMappingVersion(), Matchers.equalTo(Version.V_5_1_2));
assertThat(manager.isMappingUpdatePending(), Matchers.equalTo(mappingUpdatePending));
assertThat(manager.isWritable(), Matchers.equalTo(false));

View File

@ -211,7 +211,7 @@ public class SecurityServerTransportInterceptorTests extends ESTestCase {
};
AsyncSender sender = interceptor.interceptSender(intercepted);
Transport.Connection connection = mock(Transport.Connection.class);
final Version version = Version.fromId(randomIntBetween(Version.V_5_0_0_ID, Version.V_5_2_0_ID_UNRELEASED - 100));
final Version version = Version.fromId(randomIntBetween(Version.V_5_0_0_ID, Version.V_5_2_0_ID - 100));
when(connection.getVersion()).thenReturn(version);
sender.sendRequest(connection, "indices:foo[s]", null, null, null);
assertTrue(calledWrappedSender.get());
@ -223,7 +223,7 @@ public class SecurityServerTransportInterceptorTests extends ESTestCase {
// reset and test with version that was changed
calledWrappedSender.set(false);
sendingUser.set(null);
when(connection.getVersion()).thenReturn(Version.V_5_2_0_UNRELEASED);
when(connection.getVersion()).thenReturn(Version.V_5_2_0);
sender.sendRequest(connection, "indices:foo[s]", null, null, null);
assertTrue(calledWrappedSender.get());
assertEquals(user, sendingUser.get());

View File

@ -223,7 +223,7 @@ public class ServerTransportFilterTests extends ESTestCase {
TransportRequest request = mock(TransportRequest.class);
User user = new User("kibana", "kibana");
Authentication authentication = mock(Authentication.class);
final Version version = Version.fromId(randomIntBetween(Version.V_5_0_0_ID, Version.V_5_2_0_ID_UNRELEASED - 100));
final Version version = Version.fromId(randomIntBetween(Version.V_5_0_0_ID, Version.V_5_2_0_ID - 100));
when(authentication.getVersion()).thenReturn(version);
when(authentication.getUser()).thenReturn(user);
doAnswer((i) -> {
@ -253,7 +253,7 @@ public class ServerTransportFilterTests extends ESTestCase {
rolesRef.set(null);
user = new KibanaUser(true);
when(authentication.getUser()).thenReturn(user);
when(authentication.getVersion()).thenReturn(Version.V_5_2_0_UNRELEASED);
when(authentication.getVersion()).thenReturn(Version.V_5_2_0);
future = new PlainActionFuture<>();
filter.inbound("_action", request, channel, future);
assertNotNull(rolesRef.get());

View File

@ -12,7 +12,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
@ -66,7 +65,7 @@ public class UserTests extends ESTestCase {
BytesStreamOutput output = new BytesStreamOutput();
User.writeTo(authUser, output);
StreamInput input = output.bytes().streamInput();
input.setVersion(randomFrom(Version.V_5_0_0, Version.V_5_4_0_UNRELEASED));
input.setVersion(randomFrom(Version.V_5_0_0, Version.V_5_4_0));
User readFrom = User.readFrom(input);
assertThat(readFrom.principal(), is(user.principal()));
@ -84,7 +83,7 @@ public class UserTests extends ESTestCase {
User authUser = new User(randomAlphaOfLengthBetween(4, 30), generateRandomStringArray(20, 30, false), user);
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(randomFrom(Version.V_5_0_0, Version.V_5_4_0_UNRELEASED));
output.setVersion(randomFrom(Version.V_5_0_0, Version.V_5_4_0));
User.writeTo(authUser, output);
StreamInput input = output.bytes().streamInput();
User readFrom = User.readFrom(input);

View File

@ -36,7 +36,7 @@ public class ExecuteWatchRequestTests extends ESTestCase {
public void testSerializationBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("ADwDAAAAAAAAAAAAAAAAAAABDnsid2F0Y2giOiJtZSJ9AAAAAAAAAA==");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
Version.V_5_1_1, Version.V_5_1_2, Version.V_5_2_0);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
ExecuteWatchRequest request = new ExecuteWatchRequest();

View File

@ -65,7 +65,7 @@ public class PutWatchSerializationTests extends ESTestCase {
public void testPutWatchSerializationXContentBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("ADwDAmlkDXsiZm9vIjoiYmFyIn0BAAAA");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
Version.V_5_1_1, Version.V_5_1_2, Version.V_5_2_0);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
PutWatchRequest request = new PutWatchRequest();