Skip to content

Commit dcd6bd8

Browse files
committed
Merge branch 'master' into add-setting-to-delete-searchable-snapshot-on-index-deletion
2 parents 6621511 + 0a8f725 commit dcd6bd8

File tree

248 files changed

+4858
-3173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+4858
-3173
lines changed

.ci/bwcVersions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ BWC_VERSION:
3737
- "7.13.1"
3838
- "7.13.2"
3939
- "7.13.3"
40+
- "7.13.4"
4041
- "7.14.0"
4142
- "7.15.0"
4243
- "8.0.0"

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
250250
- is_false: "value_to_replace"
251251
- is_true: "value_not_to_replace"
252252
- is_false: "value_not_to_replace"
253-
253+
---
254+
"use cat with no header":
255+
- do:
256+
cat.indices:
257+
{}
258+
- match: {}
254259
""".stripIndent()
255260
when:
256261
def result = gradleRunner("yamlRestCompatTest").build()
@@ -337,6 +342,16 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
337342
- is_false: "replaced_value"
338343
- is_true: "value_not_to_replace"
339344
- is_false: "value_not_to_replace"
345+
---
346+
"use cat with no header":
347+
- do:
348+
cat.indices:
349+
{}
350+
allowed_warnings:
351+
- "added allowed warning"
352+
allowed_warnings_regex:
353+
- "added allowed warning regex .* [0-9]"
354+
- match: {}
340355
""".stripIndent()).readAll()
341356

342357
expectedAll.eachWithIndex{ ObjectNode expected, int i ->

build-tools-internal/src/main/groovy/elasticsearch.fips.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ if (BuildParams.inFipsJvm) {
7676
}
7777
}
7878
project.tasks.withType(Test).configureEach { Test task ->
79+
dependsOn 'fipsResources'
7980
task.systemProperty('javax.net.ssl.trustStorePassword', 'password')
8081
task.systemProperty('javax.net.ssl.keyStorePassword', 'password')
8182
task.systemProperty('javax.net.ssl.trustStoreType', 'BCFKS')

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.io.IOException;
5454
import java.util.ArrayList;
5555
import java.util.Arrays;
56+
import java.util.Iterator;
5657
import java.util.LinkedHashMap;
5758
import java.util.LinkedList;
5859
import java.util.List;
@@ -94,7 +95,18 @@ public RestCompatTestTransformTask(
9495
// always inject compat headers
9596
headers.put("Content-Type", "application/vnd.elasticsearch+json;compatible-with=" + compatibleVersion);
9697
headers.put("Accept", "application/vnd.elasticsearch+json;compatible-with=" + compatibleVersion);
97-
transformations.add(new InjectHeaders(headers));
98+
transformations.add(new InjectHeaders(headers, Set.of(RestCompatTestTransformTask::doesNotHaveCatOperation)));
99+
}
100+
101+
private static boolean doesNotHaveCatOperation(ObjectNode doNodeValue) {
102+
final Iterator<String> fieldNamesIterator = doNodeValue.fieldNames();
103+
while (fieldNamesIterator.hasNext()) {
104+
final String fieldName = fieldNamesIterator.next();
105+
if (fieldName.startsWith("cat.")) {
106+
return false;
107+
}
108+
}
109+
return true;
98110
}
99111

100112
/**

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/transform/headers/InjectHeaders.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import org.gradle.api.tasks.Internal;
1919

2020
import java.util.Map;
21+
import java.util.Set;
22+
import java.util.function.BiConsumer;
23+
import java.util.function.Function;
2124

2225
/**
2326
* A {@link RestTestTransform} that injects HTTP headers into a REST test. This includes adding the necessary values to the "do" section
@@ -28,25 +31,37 @@ public class InjectHeaders extends FeatureInjector implements RestTestTransformB
2831
private static JsonNodeFactory jsonNodeFactory = JsonNodeFactory.withExactBigDecimals(false);
2932

3033
private final Map<String, String> headers;
34+
private final Set<Function<ObjectNode, Boolean>> applyConditions;
3135

3236
/**
3337
* @param headers The headers to inject
38+
* @param applyConditions a set of conditions that has to be satisfied in order to apply headers
39+
* If the Set is empty then headers are always applied.
3440
*/
35-
public InjectHeaders(Map<String, String> headers) {
41+
public InjectHeaders(Map<String, String> headers, Set<Function<ObjectNode, Boolean>> applyConditions) {
3642
this.headers = headers;
43+
this.applyConditions = applyConditions;
3744
}
3845

3946
@Override
4047
public void transformTest(ObjectNode doNodeParent) {
4148
ObjectNode doNodeValue = (ObjectNode) doNodeParent.get(getKeyToFind());
42-
ObjectNode headersNode = (ObjectNode) doNodeValue.get("headers");
43-
if (headersNode == null) {
44-
headersNode = new ObjectNode(jsonNodeFactory);
45-
}
46-
for (Map.Entry<String, String> entry : headers.entrySet()) {
47-
headersNode.set(entry.getKey(), TextNode.valueOf(entry.getValue()));
49+
50+
if (shouldApplyHeaders(doNodeValue)) {
51+
ObjectNode headersNode = (ObjectNode) doNodeValue.get("headers");
52+
if (headersNode == null) {
53+
headersNode = new ObjectNode(jsonNodeFactory);
54+
}
55+
56+
for (Map.Entry<String, String> entry : headers.entrySet()) {
57+
headersNode.set(entry.getKey(), TextNode.valueOf(entry.getValue()));
58+
}
59+
doNodeValue.set("headers", headersNode);
4860
}
49-
doNodeValue.set("headers", headersNode);
61+
}
62+
63+
private boolean shouldApplyHeaders(ObjectNode doNodeValue) {
64+
return applyConditions.stream().allMatch(f -> f.apply(doNodeValue));
5065
}
5166

5267
@Override

build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/test/rest/transform/TransformTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Set;
3535
import java.util.concurrent.atomic.AtomicBoolean;
3636
import java.util.concurrent.atomic.LongAdder;
37+
import java.util.function.Consumer;
3738
import java.util.stream.Collectors;
3839

3940
public abstract class TransformTests extends GradleUnitTestCase {
@@ -125,8 +126,8 @@ protected List<String> getKnownFeatures() {
125126

126127
protected List<RestTestTransform<?>> getTransformations() {
127128
List<RestTestTransform<?>> transformations = new ArrayList<>();
128-
transformations.add(new InjectHeaders(headers1));
129-
transformations.add(new InjectHeaders(headers2));
129+
transformations.add(new InjectHeaders(headers1, Collections.emptySet()));
130+
transformations.add(new InjectHeaders(headers2, Collections.emptySet()));
130131
return transformations;
131132
}
132133

build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/test/rest/transform/header/InjectHeaderTests.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
import org.elasticsearch.gradle.internal.test.rest.transform.headers.InjectHeaders;
1515
import org.junit.Test;
1616

17+
import java.util.ArrayList;
1718
import java.util.Collections;
19+
import java.util.Iterator;
1820
import java.util.List;
1921
import java.util.Map;
22+
import java.util.Set;
2023

2124
public class InjectHeaderTests extends InjectFeatureTests {
2225

@@ -57,14 +60,42 @@ public void testInjectHeadersWithPreExisting() throws Exception {
5760
validateBodyHasHeaders(transformedTests, headers);
5861
}
5962

63+
64+
@Test
65+
public void testNotInjectingHeaders() throws Exception {
66+
String testName = "/rest/transform/header/with_operation_to_skip_adding_headers.yml";
67+
List<ObjectNode> tests = getTests(testName);
68+
validateSetupExist(tests);
69+
validateBodyHasHeaders(tests, Map.of("foo", "bar"));
70+
71+
List<RestTestTransform<?>> transformations =
72+
Collections.singletonList(new InjectHeaders(headers, Set.of(InjectHeaderTests::applyCondition)));
73+
List<ObjectNode> transformedTests = transformTests(tests, transformations);
74+
printTest(testName, transformedTests);
75+
validateSetupAndTearDown(transformedTests);
76+
validateBodyHasHeaders(tests, Map.of("foo", "bar"));
77+
validateBodyHasHeaders(transformedTests, Map.of("foo", "bar"));
78+
}
79+
80+
private static boolean applyCondition(ObjectNode doNodeValue) {
81+
final Iterator<String> fieldNamesIterator = doNodeValue.fieldNames();
82+
while (fieldNamesIterator.hasNext()) {
83+
final String fieldName = fieldNamesIterator.next();
84+
if (fieldName.startsWith("something_to_skip")) {
85+
return false;
86+
}
87+
}
88+
return true;
89+
}
90+
6091
@Override
6192
protected List<String> getKnownFeatures() {
6293
return Collections.singletonList("headers");
6394
}
6495

6596
@Override
6697
protected List<RestTestTransform<?>> getTransformations() {
67-
return Collections.singletonList(new InjectHeaders(headers));
98+
return Collections.singletonList(new InjectHeaders(headers, Collections.emptySet()));
6899
}
69100

70101
@Override
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
setup:
3+
- skip:
4+
features: headers
5+
---
6+
"Test without a setup":
7+
- do:
8+
headers:
9+
foo: "bar"
10+
something_to_skip:
11+
id: "something"
12+
- match: { acknowledged: true }
13+

distribution/packages/src/common/scripts/postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ case "$1" in
2323
configure)
2424

2525
# If $1=configure and $2 is set, this is an upgrade
26-
if [ -n $2 ]; then
26+
if [ -n "$2" ]; then
2727
IS_UPGRADE=true
2828
fi
2929
PACKAGE=deb

distribution/tools/keystore-cli/src/test/java/org/elasticsearch/common/settings/KeyStoreWrapperTests.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
package org.elasticsearch.common.settings;
1010

1111
import org.apache.lucene.codecs.CodecUtil;
12+
import org.apache.lucene.store.Directory;
1213
import org.apache.lucene.store.IOContext;
1314
import org.apache.lucene.store.IndexOutput;
14-
import org.apache.lucene.store.SimpleFSDirectory;
1515
import org.elasticsearch.common.Randomness;
1616
import org.elasticsearch.core.internal.io.IOUtils;
1717
import org.elasticsearch.env.Environment;
@@ -198,8 +198,10 @@ public void testUpgradeNoop() throws Exception {
198198
public void testFailWhenCannotConsumeSecretStream() throws Exception {
199199
assumeFalse("Cannot open unprotected keystore on FIPS JVM", inFipsJvm());
200200
Path configDir = env.configFile();
201-
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
202-
try (IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)) {
201+
try (
202+
Directory directory = newFSDirectory(configDir);
203+
IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)
204+
) {
203205
CodecUtil.writeHeader(indexOutput, "elasticsearch.keystore", 3);
204206
indexOutput.writeByte((byte) 0); // No password
205207
SecureRandom random = Randomness.createSecure();
@@ -227,8 +229,10 @@ public void testFailWhenCannotConsumeSecretStream() throws Exception {
227229
public void testFailWhenCannotConsumeEncryptedBytesStream() throws Exception {
228230
assumeFalse("Cannot open unprotected keystore on FIPS JVM", inFipsJvm());
229231
Path configDir = env.configFile();
230-
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
231-
try (IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)) {
232+
try (
233+
Directory directory = newFSDirectory(configDir);
234+
IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)
235+
) {
232236
CodecUtil.writeHeader(indexOutput, "elasticsearch.keystore", 3);
233237
indexOutput.writeByte((byte) 0); // No password
234238
SecureRandom random = Randomness.createSecure();
@@ -257,8 +261,10 @@ public void testFailWhenCannotConsumeEncryptedBytesStream() throws Exception {
257261
public void testFailWhenSecretStreamNotConsumed() throws Exception {
258262
assumeFalse("Cannot open unprotected keystore on FIPS JVM", inFipsJvm());
259263
Path configDir = env.configFile();
260-
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
261-
try (IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)) {
264+
try (
265+
Directory directory = newFSDirectory(configDir);
266+
IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)
267+
) {
262268
CodecUtil.writeHeader(indexOutput, "elasticsearch.keystore", 3);
263269
indexOutput.writeByte((byte) 0); // No password
264270
SecureRandom random = Randomness.createSecure();
@@ -285,8 +291,10 @@ public void testFailWhenSecretStreamNotConsumed() throws Exception {
285291
public void testFailWhenEncryptedBytesStreamIsNotConsumed() throws Exception {
286292
assumeFalse("Cannot open unprotected keystore on FIPS JVM", inFipsJvm());
287293
Path configDir = env.configFile();
288-
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
289-
try (IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)) {
294+
try (
295+
Directory directory = newFSDirectory(configDir);
296+
IndexOutput indexOutput = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)
297+
) {
290298
CodecUtil.writeHeader(indexOutput, "elasticsearch.keystore", 3);
291299
indexOutput.writeByte((byte) 0); // No password
292300
SecureRandom random = Randomness.createSecure();
@@ -372,8 +380,10 @@ public void testIllegalSettingName() throws Exception {
372380
public void testBackcompatV1() throws Exception {
373381
assumeFalse("Can't run in a FIPS JVM as PBE is not available", inFipsJvm());
374382
Path configDir = env.configFile();
375-
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
376-
try (IndexOutput output = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)) {
383+
try (
384+
Directory directory = newFSDirectory(configDir);
385+
IndexOutput output = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)
386+
) {
377387
CodecUtil.writeHeader(output, "elasticsearch.keystore", 1);
378388
output.writeByte((byte) 0); // hasPassword = false
379389
output.writeString("PKCS12");
@@ -403,10 +413,12 @@ public void testBackcompatV1() throws Exception {
403413
public void testBackcompatV2() throws Exception {
404414
assumeFalse("Can't run in a FIPS JVM as PBE is not available", inFipsJvm());
405415
Path configDir = env.configFile();
406-
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
407416
byte[] fileBytes = new byte[20];
408417
random().nextBytes(fileBytes);
409-
try (IndexOutput output = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)) {
418+
try (
419+
Directory directory = newFSDirectory(configDir);
420+
IndexOutput output = directory.createOutput("elasticsearch.keystore", IOContext.DEFAULT)
421+
) {
410422

411423
CodecUtil.writeHeader(output, "elasticsearch.keystore", 2);
412424
output.writeByte((byte) 0); // hasPassword = false

0 commit comments

Comments
 (0)