Skip to content

Commit 85ec740

Browse files
committed
Merge branch 'master' into feature/searchable-snapshots
2 parents a990dd7 + 7923833 commit 85ec740

File tree

103 files changed

+2736
-551
lines changed

Some content is hidden

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

103 files changed

+2736
-551
lines changed

.ci/matrix-vagrant-packaging.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used as part of a matrix build in Jenkins where the
2+
# values below are included as an axis of the matrix.
3+
4+
# This axis of the build matrix represents the versions subprojects
5+
# of the :qa:os project which will be tested on a metal CI worker
6+
# for the purposes of verifying of Vagrant-based tooling
7+
8+
OS:
9+
- centos-7
10+
- debian-9
11+
- fedora-28
12+
- fedora-29
13+
- oel-7
14+
- sles-12
15+
- ubuntu-1804
16+
- windows-2012r2
17+
- windows-2016

buildSrc/src/main/resources/fips_java.security

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
22
security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider fips:BCFIPS
33
security.provider.3=SUN
4+
security.provider.4=SunJGSS
45
securerandom.source=file:/dev/urandom
56
securerandom.strongAlgorithms=NativePRNGBlocking:SUN,DRBG:SUN
67
securerandom.drbg.config=

buildSrc/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ joda = 2.10.4
3131
# - x-pack/plugin/security
3232
bouncycastle = 1.61
3333
# test dependencies
34-
randomizedrunner = 2.7.4
34+
randomizedrunner = 2.7.6
3535
junit = 4.12
3636
httpclient = 4.5.10
3737
httpcore = 4.4.12

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,15 @@ private static Request getStyleRequest(String method, GetRequest getRequest) {
275275
return request;
276276
}
277277

278-
static Request sourceExists(GetRequest getRequest) {
279-
Params parameters = new Params();
280-
parameters.withPreference(getRequest.preference());
281-
parameters.withRouting(getRequest.routing());
282-
parameters.withRefresh(getRequest.refresh());
283-
parameters.withRealtime(getRequest.realtime());
284-
parameters.withFetchSourceContext(getRequest.fetchSourceContext());
285-
// Version params are not currently supported by the _source API so are not passed
286-
287-
String endpoint = endpoint(getRequest.index(), "_source", getRequest.id());
288-
Request request = new Request(HttpHead.METHOD_NAME, endpoint);
289-
request.addParameters(parameters.asMap());
290-
return request;
278+
static Request sourceExists(GetSourceRequest getSourceRequest) {
279+
return sourceRequest(getSourceRequest, HttpHead.METHOD_NAME);
291280
}
292281

293282
static Request getSource(GetSourceRequest getSourceRequest) {
283+
return sourceRequest(getSourceRequest, HttpGet.METHOD_NAME);
284+
}
285+
286+
private static Request sourceRequest(GetSourceRequest getSourceRequest, String httpMethodName) {
294287
Params parameters = new Params();
295288
parameters.withPreference(getSourceRequest.preference());
296289
parameters.withRouting(getSourceRequest.routing());
@@ -299,7 +292,7 @@ static Request getSource(GetSourceRequest getSourceRequest) {
299292
parameters.withFetchSourceContext(getSourceRequest.fetchSourceContext());
300293

301294
String endpoint = endpoint(getSourceRequest.index(), "_source", getSourceRequest.id());
302-
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
295+
Request request = new Request(httpMethodName, endpoint);
303296
request.addParameters(parameters.asMap());
304297
return request;
305298
}

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,13 @@ public final Cancellable existsAsync(GetRequest getRequest, RequestOptions optio
843843
* @param getRequest the request
844844
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
845845
* @return <code>true</code> if the document and _source field exists, <code>false</code> otherwise
846+
* @deprecated use {@link #existsSource(GetSourceRequest, RequestOptions)} instead
846847
*/
848+
@Deprecated
847849
public boolean existsSource(GetRequest getRequest, RequestOptions options) throws IOException {
848-
return performRequest(getRequest, RequestConverters::sourceExists, options, RestHighLevelClient::convertExistsResponse, emptySet());
850+
GetSourceRequest getSourceRequest = GetSourceRequest.from(getRequest);
851+
return performRequest(getSourceRequest, RequestConverters::sourceExists, options,
852+
RestHighLevelClient::convertExistsResponse, emptySet());
849853
}
850854

851855
/**
@@ -856,37 +860,68 @@ public boolean existsSource(GetRequest getRequest, RequestOptions options) throw
856860
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
857861
* @param listener the listener to be notified upon request completion
858862
* @return cancellable that may be used to cancel the request
863+
* @deprecated use {@link #existsSourceAsync(GetSourceRequest, RequestOptions, ActionListener)} instead
859864
*/
865+
@Deprecated
860866
public final Cancellable existsSourceAsync(GetRequest getRequest, RequestOptions options, ActionListener<Boolean> listener) {
861-
return performRequestAsync(getRequest, RequestConverters::sourceExists, options,
867+
GetSourceRequest getSourceRequest = GetSourceRequest.from(getRequest);
868+
return performRequestAsync(getSourceRequest, RequestConverters::sourceExists, options,
869+
RestHighLevelClient::convertExistsResponse, listener, emptySet());
870+
}
871+
872+
/**
873+
* Checks for the existence of a document with a "_source" field. Returns true if it exists, false otherwise.
874+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source">Source exists API
875+
* on elastic.co</a>
876+
* @param getSourceRequest the request
877+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
878+
* @return <code>true</code> if the document and _source field exists, <code>false</code> otherwise
879+
*/
880+
public boolean existsSource(GetSourceRequest getSourceRequest, RequestOptions options) throws IOException {
881+
return performRequest(getSourceRequest, RequestConverters::sourceExists, options,
882+
RestHighLevelClient::convertExistsResponse, emptySet());
883+
}
884+
885+
/**
886+
* Asynchronously checks for the existence of a document with a "_source" field. Returns true if it exists, false otherwise.
887+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source">Source exists API
888+
* on elastic.co</a>
889+
* @param getSourceRequest the request
890+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
891+
* @param listener the listener to be notified upon request completion
892+
* @return cancellable that may be used to cancel the request
893+
*/
894+
public final Cancellable existsSourceAsync(GetSourceRequest getSourceRequest, RequestOptions options,
895+
ActionListener<Boolean> listener) {
896+
return performRequestAsync(getSourceRequest, RequestConverters::sourceExists, options,
862897
RestHighLevelClient::convertExistsResponse, listener, emptySet());
863898
}
864899

865900
/**
866901
* Retrieves the source field only of a document using GetSource API.
867902
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source">Get Source API
868903
* on elastic.co</a>
869-
* @param getRequest the request
904+
* @param getSourceRequest the request
870905
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
871906
* @return the response
872907
*/
873-
public GetSourceResponse getSource(GetSourceRequest getRequest, RequestOptions options) throws IOException {
874-
return performRequestAndParseEntity(getRequest, RequestConverters::getSource, options,
908+
public GetSourceResponse getSource(GetSourceRequest getSourceRequest, RequestOptions options) throws IOException {
909+
return performRequestAndParseEntity(getSourceRequest, RequestConverters::getSource, options,
875910
GetSourceResponse::fromXContent, emptySet());
876911
}
877912

878913
/**
879914
* Asynchronously retrieves the source field only of a document using GetSource API.
880915
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source">Get Source API
881916
* on elastic.co</a>
882-
* @param getRequest the request
917+
* @param getSourceRequest the request
883918
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
884919
* @param listener the listener to be notified upon request completion
885920
* @return cancellable that may be used to cancel the request
886921
*/
887-
public final Cancellable getSourceAsync(GetSourceRequest getRequest, RequestOptions options,
922+
public final Cancellable getSourceAsync(GetSourceRequest getSourceRequest, RequestOptions options,
888923
ActionListener<GetSourceResponse> listener) {
889-
return performRequestAsyncAndParseEntity(getRequest, RequestConverters::getSource, options,
924+
return performRequestAsyncAndParseEntity(getSourceRequest, RequestConverters::getSource, options,
890925
GetSourceResponse::fromXContent, listener, emptySet());
891926
}
892927

client/rest-high-level/src/main/java/org/elasticsearch/client/core/GetSourceRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.client.core;
2121

22+
import org.elasticsearch.action.get.GetRequest;
2223
import org.elasticsearch.client.Validatable;
2324
import org.elasticsearch.common.xcontent.ToXContentObject;
2425
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -43,6 +44,15 @@ public GetSourceRequest(String index, String id) {
4344
this.id = id;
4445
}
4546

47+
public static GetSourceRequest from(GetRequest getRequest) {
48+
return new GetSourceRequest(getRequest.index(), getRequest.id())
49+
.routing(getRequest.routing())
50+
.preference(getRequest.preference())
51+
.refresh(getRequest.refresh())
52+
.realtime(getRequest.realtime())
53+
.fetchSourceContext(getRequest.fetchSourceContext());
54+
}
55+
4656
/**
4757
* Controls the shard routing of the request. Using this value to hash the shard
4858
* and not the id.

client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ public void testExists() throws IOException {
181181
}
182182
}
183183

184-
public void testSourceExists() throws IOException {
184+
// used deprecated API existsSource(GetRequest, RequestOptions)
185+
// see test `testSourceExists` with new API tests
186+
public void testDeprecatedSourceExists() throws IOException {
185187
{
186188
GetRequest getRequest = new GetRequest("index", "id");
187189
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
@@ -204,6 +206,25 @@ public void testSourceExists() throws IOException {
204206
}
205207
}
206208

209+
public void testSourceExists() throws IOException {
210+
{
211+
GetSourceRequest getRequest = new GetSourceRequest("index", "id");
212+
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
213+
}
214+
IndexRequest index = new IndexRequest("index").id("id");
215+
index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON);
216+
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
217+
highLevelClient().index(index, RequestOptions.DEFAULT);
218+
{
219+
GetSourceRequest getRequest = new GetSourceRequest("index", "id");
220+
assertTrue(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
221+
}
222+
{
223+
GetSourceRequest getRequest = new GetSourceRequest("index", "does_not_exist");
224+
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
225+
}
226+
}
227+
207228
public void testSourceDoesNotExist() throws IOException {
208229
final String noSourceIndex = "no_source";
209230
{
@@ -230,7 +251,11 @@ public void testSourceDoesNotExist() throws IOException {
230251
{
231252
GetRequest getRequest = new GetRequest(noSourceIndex, "1");
232253
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
254+
// used deprecated API existsSource(GetRequest, RequestOptions)
233255
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
256+
// used new API existsSource(GetSourceRequest, RequestOptions)
257+
GetSourceRequest getSourceRequest = new GetSourceRequest(noSourceIndex, "1");
258+
assertFalse(execute(getSourceRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
234259
}
235260
}
236261

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,17 @@ public void testGet() {
154154
}
155155

156156
public void testSourceExists() throws IOException {
157-
doTestSourceExists((index, id) -> new GetRequest(index, id));
158-
}
159-
160-
public void testSourceExistsWithType() throws IOException {
161-
doTestSourceExists((index, id) -> new GetRequest(index, id));
157+
doTestSourceExists((index, id) -> new GetSourceRequest(index, id));
162158
}
163159

164160
public void testGetSource() throws IOException {
165161
doTestGetSource((index, id) -> new GetSourceRequest(index, id));
166162
}
167163

168-
private static void doTestSourceExists(BiFunction<String, String, GetRequest> requestFunction) throws IOException {
164+
private static void doTestSourceExists(BiFunction<String, String, GetSourceRequest> requestFunction) throws IOException {
169165
String index = randomAlphaOfLengthBetween(3, 10);
170166
String id = randomAlphaOfLengthBetween(3, 10);
171-
final GetRequest getRequest = requestFunction.apply(index, id);
167+
final GetSourceRequest getRequest = requestFunction.apply(index, id);
172168

173169
Map<String, String> expectedParams = new HashMap<>();
174170
if (randomBoolean()) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.cli.UserException;
3030
import org.elasticsearch.env.Environment;
3131

32+
import static org.hamcrest.Matchers.anyOf;
3233
import static org.hamcrest.Matchers.containsString;
3334

3435
public class AddFileKeyStoreCommandTests extends KeyStoreCommandTestCase {
@@ -192,7 +193,17 @@ public void testIncorrectPassword() throws Exception {
192193
terminal.addSecretInput("thewrongkeystorepassword");
193194
UserException e = expectThrows(UserException.class, () -> execute("foo", file.toString()));
194195
assertEquals(e.getMessage(), ExitCodes.DATA_ERROR, e.exitCode);
195-
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
196+
if (inFipsJvm()) {
197+
assertThat(
198+
e.getMessage(),
199+
anyOf(
200+
containsString("Provided keystore password was incorrect"),
201+
containsString("Keystore has been corrupted or tampered with")
202+
)
203+
);
204+
} else {
205+
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
206+
}
196207
}
197208

198209
public void testAddToUnprotectedKeystore() throws Exception {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.cli.UserException;
3131
import org.elasticsearch.env.Environment;
3232

33+
import static org.hamcrest.Matchers.anyOf;
3334
import static org.hamcrest.Matchers.containsString;
3435
import static org.hamcrest.Matchers.hasToString;
3536

@@ -57,7 +58,17 @@ public void testInvalidPassphrease() throws Exception {
5758
terminal.addSecretInput("thewrongpassword");
5859
UserException e = expectThrows(UserException.class, () -> execute("foo2"));
5960
assertEquals(e.getMessage(), ExitCodes.DATA_ERROR, e.exitCode);
60-
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
61+
if (inFipsJvm()) {
62+
assertThat(
63+
e.getMessage(),
64+
anyOf(
65+
containsString("Provided keystore password was incorrect"),
66+
containsString("Keystore has been corrupted or tampered with")
67+
)
68+
);
69+
} else {
70+
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
71+
}
6172

6273
}
6374

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.util.Map;
2828

29+
import static org.hamcrest.Matchers.anyOf;
2930
import static org.hamcrest.Matchers.containsString;
3031

3132
public class ChangeKeyStorePasswordCommandTests extends KeyStoreCommandTestCase {
@@ -90,6 +91,16 @@ public void testChangeKeyStorePasswordWrongExistingPassword() throws Exception {
9091
// We'll only be prompted once (for the old password)
9192
UserException e = expectThrows(UserException.class, this::execute);
9293
assertEquals(e.getMessage(), ExitCodes.DATA_ERROR, e.exitCode);
93-
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
94+
if (inFipsJvm()) {
95+
assertThat(
96+
e.getMessage(),
97+
anyOf(
98+
containsString("Provided keystore password was incorrect"),
99+
containsString("Keystore has been corrupted or tampered with")
100+
)
101+
);
102+
} else {
103+
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
104+
}
94105
}
95106
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.util.Locale;
6060
import java.util.Set;
6161

62+
import static org.hamcrest.Matchers.anyOf;
6263
import static org.hamcrest.Matchers.containsString;
6364
import static org.hamcrest.Matchers.equalTo;
6465
import static org.hamcrest.Matchers.instanceOf;
@@ -114,7 +115,17 @@ public void testDecryptKeyStoreWithWrongPassword() throws Exception {
114115
SecurityException.class,
115116
() -> loadedkeystore.decrypt(new char[] { 'i', 'n', 'v', 'a', 'l', 'i', 'd' })
116117
);
117-
assertThat(exception.getMessage(), containsString("Provided keystore password was incorrect"));
118+
if (inFipsJvm()) {
119+
assertThat(
120+
exception.getMessage(),
121+
anyOf(
122+
containsString("Provided keystore password was incorrect"),
123+
containsString("Keystore has been corrupted or tampered with")
124+
)
125+
);
126+
} else {
127+
assertThat(exception.getMessage(), containsString("Provided keystore password was incorrect"));
128+
}
118129
}
119130

120131
public void testCannotReadStringFromClosedKeystore() throws Exception {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.cli.UserException;
2727
import org.elasticsearch.env.Environment;
2828

29+
import static org.hamcrest.Matchers.anyOf;
2930
import static org.hamcrest.Matchers.containsString;
3031

3132
public class ListKeyStoreCommandTests extends KeyStoreCommandTestCase {
@@ -76,7 +77,17 @@ public void testListWithIncorrectPassword() throws Exception {
7677
terminal.addSecretInput("thewrongkeystorepassword");
7778
UserException e = expectThrows(UserException.class, this::execute);
7879
assertEquals(e.getMessage(), ExitCodes.DATA_ERROR, e.exitCode);
79-
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
80+
if (inFipsJvm()) {
81+
assertThat(
82+
e.getMessage(),
83+
anyOf(
84+
containsString("Provided keystore password was incorrect"),
85+
containsString("Keystore has been corrupted or tampered with")
86+
)
87+
);
88+
} else {
89+
assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
90+
}
8091
}
8192

8293
public void testListWithUnprotectedKeystore() throws Exception {

0 commit comments

Comments
 (0)