getPreConfiguredTokenFilters() {
filters.add(PreConfiguredTokenFilter.singleton("indic_normalization", true, IndicNormalizationFilter::new));
filters.add(PreConfiguredTokenFilter.singleton("keyword_repeat", false, false, KeywordRepeatFilter::new));
filters.add(PreConfiguredTokenFilter.singleton("kstem", false, KStemFilter::new));
- filters.add(PreConfiguredTokenFilter.singleton("length", false, input ->
- new LengthFilter(input, 0, Integer.MAX_VALUE))); // TODO this one seems useless
+ // TODO this one seems useless
+ filters.add(PreConfiguredTokenFilter.singleton("length", false, input -> new LengthFilter(input, 0, Integer.MAX_VALUE)));
filters.add(PreConfiguredTokenFilter.singleton("limit", false, input ->
new LimitTokenCountFilter(input,
LimitTokenCountFilterFactory.DEFAULT_MAX_TOKEN_COUNT,
diff --git a/server/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java b/server/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java
index d12ecacbdc7d3..0c3de3b7ed2b6 100644
--- a/server/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java
+++ b/server/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java
@@ -145,25 +145,31 @@ public enum QueryType {
INTERSECTS {
@Override
boolean matches(BytesRef from, BytesRef to, BytesRef otherFrom, BytesRef otherTo) {
- // part of the other range must touch this range
- // this: |---------------|
- // other: |------|
+ /*
+ * part of the other range must touch this range
+ * this: |---------------|
+ * other: |------|
+ */
return from.compareTo(otherTo) <= 0 && to.compareTo(otherFrom) >= 0;
}
}, WITHIN {
@Override
boolean matches(BytesRef from, BytesRef to, BytesRef otherFrom, BytesRef otherTo) {
- // other range must entirely lie within this range
- // this: |---------------|
- // other: |------|
+ /*
+ * other range must entirely lie within this range
+ * this: |---------------|
+ * other: |------|
+ */
return from.compareTo(otherFrom) <= 0 && to.compareTo(otherTo) >= 0;
}
}, CONTAINS {
@Override
boolean matches(BytesRef from, BytesRef to, BytesRef otherFrom, BytesRef otherTo) {
- // this and other range must overlap
- // this: |------|
- // other: |---------------|
+ /*
+ * this and other range must overlap
+ * this: |------|
+ * other: |---------------|
+ */
return from.compareTo(otherFrom) >= 0 && to.compareTo(otherTo) <= 0;
}
}, CROSSES {
diff --git a/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java b/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java
index 759acd86765e5..7ed5efda7e30e 100644
--- a/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java
+++ b/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java
@@ -111,10 +111,12 @@ private void innerRun() throws IOException {
} else {
ScoreDoc[] scoreDocs = reducedQueryPhase.sortedTopDocs.scoreDocs;
final IntArrayList[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(numShards, scoreDocs);
- if (scoreDocs.length == 0) { // no docs to fetch -- sidestep everything and return
+ // no docs to fetch -- sidestep everything and return
+ if (scoreDocs.length == 0) {
+ // we have to release contexts here to free up resources
phaseResults.stream()
.map(SearchPhaseResult::queryResult)
- .forEach(this::releaseIrrelevantSearchContext); // we have to release contexts here to free up resources
+ .forEach(this::releaseIrrelevantSearchContext);
finishPhase.run();
} else {
final ScoreDoc[] lastEmittedDocPerShard = isScrollSearch ?
diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java
index 4750476805d88..3c68bc362f004 100644
--- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java
+++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java
@@ -117,10 +117,11 @@ public RoutingNodes(ClusterState clusterState, boolean readOnly) {
assignedShardsAdd(shard);
if (shard.relocating()) {
relocatingShards++;
- entries = nodesToShards.computeIfAbsent(shard.relocatingNodeId(),
- k -> new LinkedHashMap<>()); // LinkedHashMap to preserve order
- // add the counterpart shard with relocatingNodeId reflecting the source from which
+ // LinkedHashMap to preserve order.
+ // Add the counterpart shard with relocatingNodeId reflecting the source from which
// it's relocating from.
+ entries = nodesToShards.computeIfAbsent(shard.relocatingNodeId(),
+ k -> new LinkedHashMap<>());
ShardRouting targetShardRouting = shard.getTargetRelocatingShard();
addInitialRecovery(targetShardRouting, indexShard.primary);
previousValue = entries.put(targetShardRouting.shardId(), targetShardRouting);
diff --git a/server/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/server/src/main/java/org/elasticsearch/common/lucene/Lucene.java
index 4b0ec9ea08773..f05e28c342e00 100644
--- a/server/src/main/java/org/elasticsearch/common/lucene/Lucene.java
+++ b/server/src/main/java/org/elasticsearch/common/lucene/Lucene.java
@@ -256,7 +256,8 @@ public static void cleanLuceneIndex(Directory directory) throws IOException {
.setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
.setMergePolicy(NoMergePolicy.INSTANCE) // no merges
.setCommitOnClose(false) // no commits
- .setOpenMode(IndexWriterConfig.OpenMode.CREATE))) // force creation - don't append...
+ .setOpenMode(IndexWriterConfig.OpenMode.CREATE) // force creation - don't append...
+ ))
{
// do nothing and close this will kick of IndexFileDeleter which will remove all pending files
}
diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java
index d193cfd510823..fa0f153da4431 100644
--- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java
+++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java
@@ -22,6 +22,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
+import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.compress.Compressor;
@@ -161,6 +162,17 @@ public static String convertToJson(BytesReference bytes, boolean reformatJson, X
return convertToJson(bytes, reformatJson, false, xContentType);
}
+ /**
+ * Accepts a JSON string and reformats it. This is useful where a piece of JSON is formatted for legibility, but needs
+ * to be stripped of unnecessary whitespace e.g. for comparison in a test.
+ * @param json the JSON to format
+ * @return reformatted JSON
+ * @throws IOException if the reformatting fails, e.g. because the JSON is not well-formed
+ */
+ public static String reformatJson(String json) throws IOException {
+ return convertToJson(new BytesArray(json), true, XContentType.JSON);
+ }
+
public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint, XContentType xContentType)
throws IOException {
Objects.requireNonNull(xContentType);
diff --git a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
index 77395c389847e..bbbe83c5e5368 100644
--- a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
+++ b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
@@ -458,14 +458,14 @@ public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Item)) return false;
Item other = (Item) o;
- return Objects.equals(index, other.index) &&
- Objects.equals(id, other.id) &&
- Objects.equals(doc, other.doc) &&
- Arrays.equals(fields, other.fields) && // otherwise we are comparing pointers
- Objects.equals(perFieldAnalyzer, other.perFieldAnalyzer) &&
- Objects.equals(routing, other.routing) &&
- Objects.equals(version, other.version) &&
- Objects.equals(versionType, other.versionType);
+ return Objects.equals(index, other.index)
+ && Objects.equals(id, other.id)
+ && Objects.equals(doc, other.doc)
+ && Arrays.equals(fields, other.fields) // otherwise we are comparing pointers
+ && Objects.equals(perFieldAnalyzer, other.perFieldAnalyzer)
+ && Objects.equals(routing, other.routing)
+ && Objects.equals(version, other.version)
+ && Objects.equals(versionType, other.versionType);
}
}
@@ -1139,23 +1139,23 @@ protected int doHashCode() {
@Override
protected boolean doEquals(MoreLikeThisQueryBuilder other) {
- return Arrays.equals(fields, other.fields) &&
- Arrays.equals(likeTexts, other.likeTexts) &&
- Arrays.equals(unlikeTexts, other.unlikeTexts) &&
- Arrays.equals(likeItems, other.likeItems) &&
- Arrays.equals(unlikeItems, other.unlikeItems) &&
- Objects.equals(maxQueryTerms, other.maxQueryTerms) &&
- Objects.equals(minTermFreq, other.minTermFreq) &&
- Objects.equals(minDocFreq, other.minDocFreq) &&
- Objects.equals(maxDocFreq, other.maxDocFreq) &&
- Objects.equals(minWordLength, other.minWordLength) &&
- Objects.equals(maxWordLength, other.maxWordLength) &&
- Arrays.equals(stopWords, other.stopWords) && // otherwise we are comparing pointers
- Objects.equals(analyzer, other.analyzer) &&
- Objects.equals(minimumShouldMatch, other.minimumShouldMatch) &&
- Objects.equals(boostTerms, other.boostTerms) &&
- Objects.equals(include, other.include) &&
- Objects.equals(failOnUnsupportedField, other.failOnUnsupportedField);
+ return Arrays.equals(fields, other.fields)
+ && Arrays.equals(likeTexts, other.likeTexts)
+ && Arrays.equals(unlikeTexts, other.unlikeTexts)
+ && Arrays.equals(likeItems, other.likeItems)
+ && Arrays.equals(unlikeItems, other.unlikeItems)
+ && Objects.equals(maxQueryTerms, other.maxQueryTerms)
+ && Objects.equals(minTermFreq, other.minTermFreq)
+ && Objects.equals(minDocFreq, other.minDocFreq)
+ && Objects.equals(maxDocFreq, other.maxDocFreq)
+ && Objects.equals(minWordLength, other.minWordLength)
+ && Objects.equals(maxWordLength, other.maxWordLength)
+ && Arrays.equals(stopWords, other.stopWords) // otherwise we are comparing pointers
+ && Objects.equals(analyzer, other.analyzer)
+ && Objects.equals(minimumShouldMatch, other.minimumShouldMatch)
+ && Objects.equals(boostTerms, other.boostTerms)
+ && Objects.equals(include, other.include)
+ && Objects.equals(failOnUnsupportedField, other.failOnUnsupportedField);
}
@Override
diff --git a/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
index d189dfd33395b..4be112096c8bf 100644
--- a/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
+++ b/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
@@ -229,8 +229,8 @@ public synchronized void applyClusterState(final ClusterChangedEvent event) {
// TODO: feels hacky, a block disables state persistence, and then we clean the allocated shards, maybe another flag in blocks?
if (state.blocks().disableStatePersistence()) {
for (AllocatedIndex extends Shard> indexService : indicesService) {
- indicesService.removeIndex(indexService.index(), NO_LONGER_ASSIGNED,
- "cleaning index (disabled block persistence)"); // also cleans shards
+ // also cleans shards
+ indicesService.removeIndex(indexService.index(), NO_LONGER_ASSIGNED, "cleaning index (disabled block persistence)");
}
return;
}
diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java
index 2bd30a677a0af..94cda1630f4d5 100644
--- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java
+++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java
@@ -79,6 +79,8 @@ public static long memoryUsage(int precision) {
return 1L << precision;
}
+ // tag::hyperloglog-data-tables
+
// these static tables come from the appendix of the paper
private static final double[][] RAW_ESTIMATE_DATA = {
// precision 4
@@ -751,6 +753,8 @@ public static long memoryUsage(int precision) {
private static final long[] THRESHOLDS = new long[] { 10, 20, 40, 80, 220, 400, 900, 1800, 3100, 6500, 11500, 20000, 50000, 120000,
350000 };
+ // end::hyperloglog-data-tables
+
private final BigArrays bigArrays;
private final OpenBitSet algorithm;
private ByteArray runLens;
diff --git a/server/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java b/server/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java
index cc4a44590e79e..adee76e8a170e 100644
--- a/server/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java
+++ b/server/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java
@@ -62,8 +62,8 @@ public WordScorer(IndexReader reader, Terms terms, String field, double realWord
// division by zero, by scoreUnigram.
final long nTerms = terms.size();
this.numTerms = nTerms == -1 ? reader.maxDoc() : nTerms;
- this.termsEnum = new FreqTermsEnum(reader, field, !useTotalTermFreq, useTotalTermFreq, null,
- BigArrays.NON_RECYCLING_INSTANCE); // non recycling for now
+ // non recycling for now
+ this.termsEnum = new FreqTermsEnum(reader, field, !useTotalTermFreq, useTotalTermFreq, null, BigArrays.NON_RECYCLING_INSTANCE);
this.reader = reader;
this.realWordLikelihood = realWordLikelihood;
this.separator = separator;
diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java
index e6c1ca1c84b91..ec179e9883cff 100644
--- a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java
+++ b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java
@@ -782,15 +782,15 @@ private static int readHeaderBuffer(BytesReference headerBuffer) throws IOExcept
}
private static boolean appearsToBeHTTPRequest(BytesReference headerBuffer) {
- return bufferStartsWith(headerBuffer, "GET") ||
- bufferStartsWith(headerBuffer, "POST") ||
- bufferStartsWith(headerBuffer, "PUT") ||
- bufferStartsWith(headerBuffer, "HEAD") ||
- bufferStartsWith(headerBuffer, "DELETE") ||
+ return bufferStartsWith(headerBuffer, "GET")
+ || bufferStartsWith(headerBuffer, "POST")
+ || bufferStartsWith(headerBuffer, "PUT")
+ || bufferStartsWith(headerBuffer, "HEAD")
+ || bufferStartsWith(headerBuffer, "DELETE")
// Actually 'OPTIONS'. But we are only guaranteed to have read six bytes at this point.
- bufferStartsWith(headerBuffer, "OPTION") ||
- bufferStartsWith(headerBuffer, "PATCH") ||
- bufferStartsWith(headerBuffer, "TRACE");
+ || bufferStartsWith(headerBuffer, "OPTION")
+ || bufferStartsWith(headerBuffer, "PATCH")
+ || bufferStartsWith(headerBuffer, "TRACE");
}
private static boolean appearsToBeHTTPResponse(BytesReference headerBuffer) {
diff --git a/server/src/main/java/org/joda/time/format/StrictISODateTimeFormat.java b/server/src/main/java/org/joda/time/format/StrictISODateTimeFormat.java
index aacb7cf330687..a373c3862cd8b 100644
--- a/server/src/main/java/org/joda/time/format/StrictISODateTimeFormat.java
+++ b/server/src/main/java/org/joda/time/format/StrictISODateTimeFormat.java
@@ -34,6 +34,7 @@
* In case you compare this with the original ISODateTimeFormat, make sure you use a diff
* call, that ignores whitespaces/tabs/indentations like 'diff -b'
*/
+
/**
* Factory that creates instances of DateTimeFormatter based on the ISO8601 standard.
*
@@ -1720,7 +1721,8 @@ private static DateTimeFormatter basicOrdinalDateTimeNoMillis() {
private static DateTimeFormatter basicWeekDate() {
if (bwd == null) {
return new DateTimeFormatterBuilder()
- .appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4) // ES change, was .appendWeekyear(4, 4)
+ // ES change, was .appendWeekyear(4, 4)
+ .appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4)
.appendLiteral('W')
.appendFixedDecimal(DateTimeFieldType.weekOfWeekyear(), 2)
.appendFixedDecimal(DateTimeFieldType.dayOfWeek(), 1)
@@ -1897,7 +1899,8 @@ private static DateTimeFormatter dateHourMinuteSecondFraction() {
private static DateTimeFormatter yearElement() {
if (ye == null) {
return new DateTimeFormatterBuilder()
- .appendFixedSignedDecimal(DateTimeFieldType.year(), 4) // ES change, was .appendYear(4, 9)
+ // ES change, was .appendYear(4, 9)
+ .appendFixedSignedDecimal(DateTimeFieldType.year(), 4)
.toFormatter();
}
return ye;
@@ -1907,7 +1910,8 @@ private static DateTimeFormatter monthElement() {
if (mye == null) {
return new DateTimeFormatterBuilder()
.appendLiteral('-')
- .appendFixedSignedDecimal(DateTimeFieldType.monthOfYear(), 2) // ES change, was .appendMonthOfYear(2)
+ // ES change, was .appendMonthOfYear(2)
+ .appendFixedSignedDecimal(DateTimeFieldType.monthOfYear(), 2)
.toFormatter();
}
return mye;
@@ -1917,7 +1921,8 @@ private static DateTimeFormatter dayOfMonthElement() {
if (dme == null) {
return new DateTimeFormatterBuilder()
.appendLiteral('-')
- .appendFixedSignedDecimal(DateTimeFieldType.dayOfMonth(), 2) // ES change, was .appendDayOfMonth(2)
+ // ES change, was .appendDayOfMonth(2)
+ .appendFixedSignedDecimal(DateTimeFieldType.dayOfMonth(), 2)
.toFormatter();
}
return dme;
@@ -1926,7 +1931,8 @@ private static DateTimeFormatter dayOfMonthElement() {
private static DateTimeFormatter weekyearElement() {
if (we == null) {
return new DateTimeFormatterBuilder()
- .appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4) // ES change, was .appendWeekyear(4, 9)
+ // ES change, was .appendWeekyear(4, 9)
+ .appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4)
.toFormatter();
}
return we;
@@ -1936,7 +1942,8 @@ private static DateTimeFormatter weekElement() {
if (wwe == null) {
return new DateTimeFormatterBuilder()
.appendLiteral("-W")
- .appendFixedSignedDecimal(DateTimeFieldType.weekOfWeekyear(), 2) // ES change, was .appendWeekOfWeekyear(2)
+ // ES change, was .appendWeekOfWeekyear(2)
+ .appendFixedSignedDecimal(DateTimeFieldType.weekOfWeekyear(), 2)
.toFormatter();
}
return wwe;
@@ -1956,7 +1963,8 @@ private static DateTimeFormatter dayOfYearElement() {
if (dye == null) {
return new DateTimeFormatterBuilder()
.appendLiteral('-')
- .appendFixedSignedDecimal(DateTimeFieldType.dayOfYear(), 3) // ES change, was .appendDayOfYear(3)
+ // ES change, was .appendDayOfYear(3)
+ .appendFixedSignedDecimal(DateTimeFieldType.dayOfYear(), 3)
.toFormatter();
}
return dye;
@@ -1974,7 +1982,8 @@ private static DateTimeFormatter literalTElement() {
private static DateTimeFormatter hourElement() {
if (hde == null) {
return new DateTimeFormatterBuilder()
- .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2) // ES change, was .appendHourOfDay(2)
+ // ES change, was .appendHourOfDay(2)
+ .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
.toFormatter();
}
return hde;
@@ -1984,7 +1993,8 @@ private static DateTimeFormatter minuteElement() {
if (mhe == null) {
return new DateTimeFormatterBuilder()
.appendLiteral(':')
- .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2) // ES change, was .appendMinuteOfHour(2)
+ // ES change, was .appendMinuteOfHour(2)
+ .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
.toFormatter();
}
return mhe;
@@ -1994,7 +2004,8 @@ private static DateTimeFormatter secondElement() {
if (sme == null) {
return new DateTimeFormatterBuilder()
.appendLiteral(':')
- .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2) // ES change, was .appendSecondOfMinute(2)
+ // ES change, was .appendSecondOfMinute(2)
+ .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
.toFormatter();
}
return sme;
diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchPhaseExecutionExceptionTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchPhaseExecutionExceptionTests.java
index 74005f681d6d9..4901e21a570fc 100644
--- a/server/src/test/java/org/elasticsearch/action/search/SearchPhaseExecutionExceptionTests.java
+++ b/server/src/test/java/org/elasticsearch/action/search/SearchPhaseExecutionExceptionTests.java
@@ -28,6 +28,7 @@
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContent;
+import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.shard.IndexShardClosedException;
@@ -56,36 +57,40 @@ public void testToXContent() throws IOException {
});
// Failures are grouped (by default)
- assertEquals("{" +
- "\"type\":\"search_phase_execution_exception\"," +
- "\"reason\":\"all shards failed\"," +
- "\"phase\":\"test\"," +
- "\"grouped\":true," +
- "\"failed_shards\":[" +
- "{" +
- "\"shard\":0," +
- "\"index\":\"foo\"," +
- "\"node\":\"node_1\"," +
- "\"reason\":{" +
- "\"type\":\"parsing_exception\"," +
- "\"reason\":\"foobar\"," +
- "\"line\":1," +
- "\"col\":2" +
- "}" +
- "}," +
- "{" +
- "\"shard\":1," +
- "\"index\":\"foo\"," +
- "\"node\":\"node_2\"," +
- "\"reason\":{" +
- "\"type\":\"index_shard_closed_exception\"," +
- "\"reason\":\"CurrentState[CLOSED] Closed\"," +
- "\"index_uuid\":\"_na_\"," +
- "\"shard\":\"1\"," +
- "\"index\":\"foo\"" +
- "}" +
- "}" +
- "]}", Strings.toString(exception));
+ final String expectedJson = XContentHelper.reformatJson(
+ "{"
+ + " \"type\": \"search_phase_execution_exception\","
+ + " \"reason\": \"all shards failed\","
+ + " \"phase\": \"test\","
+ + " \"grouped\": true,"
+ + " \"failed_shards\": ["
+ + " {"
+ + " \"shard\": 0,"
+ + " \"index\": \"foo\","
+ + " \"node\": \"node_1\","
+ + " \"reason\": {"
+ + " \"type\": \"parsing_exception\","
+ + " \"reason\": \"foobar\","
+ + " \"line\": 1,"
+ + " \"col\": 2"
+ + " }"
+ + " },"
+ + " {"
+ + " \"shard\": 1,"
+ + " \"index\": \"foo\","
+ + " \"node\": \"node_2\","
+ + " \"reason\": {"
+ + " \"type\": \"index_shard_closed_exception\","
+ + " \"reason\": \"CurrentState[CLOSED] Closed\","
+ + " \"index_uuid\": \"_na_\","
+ + " \"shard\": \"1\","
+ + " \"index\": \"foo\""
+ + " }"
+ + " }"
+ + " ]"
+ + "}"
+ );
+ assertEquals(expectedJson, Strings.toString(exception));
}
public void testToAndFromXContent() throws IOException {
diff --git a/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java b/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java
index 51ea048a96cc7..cea57fa8f4e21 100644
--- a/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java
+++ b/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java
@@ -375,8 +375,11 @@ public void testDelegateToFailingMaster() throws ExecutionException, Interrupted
boolean rejoinSameMaster = failsWithConnectTransportException && randomBoolean();
Request request = new Request().masterNodeTimeout(TimeValue.timeValueSeconds(failsWithConnectTransportException ? 60 : 0));
DiscoveryNode masterNode = this.remoteNode;
- setState(clusterService, ClusterState.builder(ClusterStateCreationUtils.state(localNode, masterNode, allNodes))
- .version(randomIntBetween(0, 10))); // use a random base version so it can go down when simulating a restart.
+ setState(
+ clusterService,
+ // use a random base version so it can go down when simulating a restart.
+ ClusterState.builder(ClusterStateCreationUtils.state(localNode, masterNode, allNodes)).version(randomIntBetween(0, 10))
+ );
PlainActionFuture listener = new PlainActionFuture<>();
ActionTestUtils.execute(new Action("internal:testAction", transportService, clusterService, threadPool), null, request, listener);
diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/LeaderCheckerTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/LeaderCheckerTests.java
index 496a25e180262..b5681d4d486e3 100644
--- a/server/src/test/java/org/elasticsearch/cluster/coordination/LeaderCheckerTests.java
+++ b/server/src/test/java/org/elasticsearch/cluster/coordination/LeaderCheckerTests.java
@@ -194,7 +194,8 @@ public String toString() {
assertThat(deterministicTaskQueue.getCurrentTimeMillis() - failureTime,
lessThanOrEqualTo((leaderCheckIntervalMillis + leaderCheckTimeoutMillis) * leaderCheckRetryCount
- + leaderCheckTimeoutMillis // needed because a successful check response might be in flight at the time of failure
+ // needed because a successful check response might be in flight at the time of failure
+ + leaderCheckTimeoutMillis
));
}
leaderChecker.updateLeader(null);
diff --git a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java
index 74d72edf71f31..6911e9891cc50 100644
--- a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java
+++ b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java
@@ -149,7 +149,8 @@ public void testCorruptFileAndRecover() throws ExecutionException, InterruptedEx
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1")
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, "1")
.put(MergePolicyConfig.INDEX_MERGE_ENABLED, false)
- .put(MockFSIndexStore.INDEX_CHECK_INDEX_ON_CLOSE_SETTING.getKey(), false) // no checkindex - we corrupt shards on purpose
+ // no checkindex - we corrupt shards on purpose
+ .put(MockFSIndexStore.INDEX_CHECK_INDEX_ON_CLOSE_SETTING.getKey(), false)
// no translog based flush - it might change the .liv / segments.N files
.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.PB))
));
diff --git a/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java
index deafe203ac8dc..89b8cf1a2f193 100644
--- a/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java
+++ b/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java
@@ -93,10 +93,11 @@ public void testAdditionalSettings() {
Settings newSettings = service.updatedSettings();
assertEquals("test", newSettings.get("my.setting")); // previous settings still exist
assertEquals("1", newSettings.get("foo.bar")); // added setting exists
+ // does not override pre existing settings
assertEquals(
IndexModule.Type.SIMPLEFS.getSettingsKey(),
newSettings.get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey())
- ); // does not override pre existing settings
+ );
}
public void testAdditionalSettingsClash() {
diff --git a/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java b/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java
index a448736ed55ad..e315a1531ebfb 100644
--- a/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java
+++ b/server/src/test/java/org/elasticsearch/recovery/RelocationIT.java
@@ -280,7 +280,8 @@ public void testRelocationWhileRefreshing() throws Exception {
Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", numberOfReplicas)
- .put("index.refresh_interval", -1) // we want to control refreshes
+ // we want to control refreshes
+ .put("index.refresh_interval", -1)
).get();
for (int i = 1; i < numberOfNodes; i++) {
diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java
index 1f295fc33570e..d390982c6e3e0 100644
--- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java
+++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java
@@ -97,7 +97,8 @@ public void setupSuiteScopeCluster() throws Exception {
indexDoc(2, 15, 3), // Feb 15
indexDoc(3, 2, 4), // Mar 2
indexDoc(3, 15, 5), // Mar 15
- indexDoc(3, 23, 6))); // Mar 23
+ indexDoc(3, 23, 6) // Mar 23
+ ));
// dummy docs
for (int i = docs.size(); i < numDocs; ++i) {
diff --git a/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java b/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java
index 23c29ce9f4674..f5ed9a89e31a7 100644
--- a/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java
+++ b/server/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java
@@ -147,8 +147,8 @@ public void testNodesOnlyRandom() {
refresh();
final Client client = internalCluster().smartClient();
- SearchRequestBuilder request = client.prepareSearch("test")
- .setQuery(matchAllQuery()).setPreference("_only_nodes:*,nodes*"); // multiple wildchar to cover multi-param usecase
+ // multiple wildchar to cover multi-param usecase
+ SearchRequestBuilder request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference("_only_nodes:*,nodes*");
assertSearchOnRandomNodes(request);
request = client.prepareSearch("test")
diff --git a/server/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java b/server/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java
index 1d3b71bbf40db..2384d697e38dc 100644
--- a/server/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java
+++ b/server/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java
@@ -165,18 +165,19 @@ public void testScriptSortTypeIllegalArgument() {
}
public void testParseJson() throws IOException {
- String scriptSort = "{\n" +
- "\"_script\" : {\n" +
- "\"type\" : \"number\",\n" +
- "\"script\" : {\n" +
- "\"source\": \"doc['field_name'].value * factor\",\n" +
- "\"params\" : {\n" +
- "\"factor\" : 1.1\n" +
- "}\n" +
- "},\n" +
- "\"mode\" : \"max\",\n" +
- "\"order\" : \"asc\"\n" +
- "} }\n";
+ String scriptSort = "{"
+ + " \"_script\": {"
+ + " \"type\": \"number\","
+ + " \"script\": {"
+ + " \"source\": \"doc['field_name'].value * factor\","
+ + " \"params\": {"
+ + " \"factor\": 1.1"
+ + " }"
+ + " },"
+ + " \"mode\": \"max\","
+ + " \"order\": \"asc\""
+ + " }"
+ + "}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort)) {
parser.nextToken();
parser.nextToken();
diff --git a/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java b/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java
index 9a1480c8d8807..739ea65fe5acf 100644
--- a/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java
+++ b/server/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java
@@ -1069,11 +1069,12 @@ public void testPrunedSegments() throws IOException {
.startArray("input").value("The Beatles").endArray()
.endObject().endObject()
).get();
+ // we have 2 docs in a segment...
client().prepareIndex(INDEX, TYPE, "2").setSource(jsonBuilder()
.startObject()
.field("somefield", "somevalue")
.endObject()
- ).get(); // we have 2 docs in a segment...
+ ).get();
ForceMergeResponse actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).get();
assertAllSuccessful(actionGet);
refresh();
diff --git a/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java b/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java
index 5c247630d6b7f..8df25c1cbf10e 100644
--- a/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java
+++ b/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java
@@ -131,19 +131,21 @@ public void testToXContent() throws IOException {
Suggest suggest = new Suggest(Collections.singletonList(suggestion));
BytesReference xContent = toXContent(suggest, XContentType.JSON, randomBoolean());
assertEquals(
- "{\"suggest\":"
- + "{\"suggestionName\":"
- + "[{\"text\":\"entryText\","
- + "\"offset\":42,"
- + "\"length\":313,"
- + "\"options\":[{\"text\":\"someText\","
- + "\"highlighted\":\"somethingHighlighted\","
- + "\"score\":1.3,"
- + "\"collate_match\":true}]"
- + "}]"
- + "}"
- +"}",
- xContent.utf8ToString());
+ // @formatter:off
+ "{\"suggest\":"
+ + "{\"suggestionName\":"
+ + "[{\"text\":\"entryText\","
+ + "\"offset\":42,"
+ + "\"length\":313,"
+ + "\"options\":[{\"text\":\"someText\","
+ + "\"highlighted\":\"somethingHighlighted\","
+ + "\"score\":1.3,"
+ + "\"collate_match\":true}]"
+ + "}]"
+ + "}"
+ +"}",
+ // @formatter:on
+ xContent.utf8ToString());
}
public void testFilter() throws Exception {
diff --git a/server/src/test/java/org/elasticsearch/search/suggest/SuggestionOptionTests.java b/server/src/test/java/org/elasticsearch/search/suggest/SuggestionOptionTests.java
index 37d886fd5d825..a045a1b6fa569 100644
--- a/server/src/test/java/org/elasticsearch/search/suggest/SuggestionOptionTests.java
+++ b/server/src/test/java/org/elasticsearch/search/suggest/SuggestionOptionTests.java
@@ -81,11 +81,14 @@ private void doTestFromXContent(boolean addRandomFields) throws IOException {
public void testToXContent() throws IOException {
Option option = new PhraseSuggestion.Entry.Option(new Text("someText"), new Text("somethingHighlighted"), 1.3f, true);
BytesReference xContent = toXContent(option, XContentType.JSON, randomBoolean());
- assertEquals("{\"text\":\"someText\","
- + "\"highlighted\":\"somethingHighlighted\","
- + "\"score\":1.3,"
- + "\"collate_match\":true"
- + "}"
- , xContent.utf8ToString());
+ assertEquals(
+ "{"
+ + " \"text\": \"someText\","
+ + " \"highlighted\": \"somethingHighlighted\","
+ + " \"score\": 1.3,"
+ + " \"collate_match\": true"
+ + "}",
+ xContent.utf8ToString()
+ );
}
}
diff --git a/server/src/test/java/org/elasticsearch/search/suggest/SuggestionTests.java b/server/src/test/java/org/elasticsearch/search/suggest/SuggestionTests.java
index e05b42c102a75..78a1300402cc9 100644
--- a/server/src/test/java/org/elasticsearch/search/suggest/SuggestionTests.java
+++ b/server/src/test/java/org/elasticsearch/search/suggest/SuggestionTests.java
@@ -164,17 +164,23 @@ public void testFromXContentWithoutTypeParam() throws IOException {
public void testUnknownSuggestionTypeThrows() throws IOException {
XContent xContent = JsonXContent.jsonXContent;
- String suggestionString =
- "{\"unknownType#suggestionName\":"
- + "[{\"text\":\"entryText\","
- + "\"offset\":42,"
- + "\"length\":313,"
- + "\"options\":[{\"text\":\"someText\","
- + "\"highlighted\":\"somethingHighlighted\","
- + "\"score\":1.3,"
- + "\"collate_match\":true}]"
- + "}]"
- + "}";
+ String suggestionString = "{"
+ + " \"unknownType#suggestionName\": ["
+ + " {"
+ + " \"text\": \"entryText\","
+ + " \"offset\": 42,"
+ + " \"length\": 313,"
+ + " \"options\": ["
+ + " {"
+ + " \"text\": \"someText\","
+ + " \"highlighted\": \"somethingHighlighted\","
+ + " \"score\": 1.3,"
+ + " \"collate_match\": true"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + "}";
try (XContentParser parser = xContent.createParser(xContentRegistry(),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, suggestionString)) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
@@ -196,17 +202,25 @@ public void testToXContent() throws IOException {
suggestion.addTerm(entry);
BytesReference xContent = toXContent(suggestion, XContentType.JSON, params, randomBoolean());
assertEquals(
- "{\"phrase#suggestionName\":[{"
- + "\"text\":\"entryText\","
- + "\"offset\":42,"
- + "\"length\":313,"
- + "\"options\":[{"
- + "\"text\":\"someText\","
- + "\"highlighted\":\"somethingHighlighted\","
- + "\"score\":1.3,"
- + "\"collate_match\":true}]"
- + "}]"
- + "}", xContent.utf8ToString());
+ "{"
+ + " \"phrase#suggestionName\": ["
+ + " {"
+ + " \"text\": \"entryText\","
+ + " \"offset\": 42,"
+ + " \"length\": 313,"
+ + " \"options\": ["
+ + " {"
+ + " \"text\": \"someText\","
+ + " \"highlighted\": \"somethingHighlighted\","
+ + " \"score\": 1.3,"
+ + " \"collate_match\": true"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + "}",
+ xContent.utf8ToString()
+ );
}
{
PhraseSuggestion.Entry.Option option = new PhraseSuggestion.Entry.Option(new Text("someText"), new Text("somethingHighlighted"),
@@ -217,17 +231,25 @@ public void testToXContent() throws IOException {
suggestion.addTerm(entry);
BytesReference xContent = toXContent(suggestion, XContentType.JSON, params, randomBoolean());
assertEquals(
- "{\"phrase#suggestionName\":[{"
- + "\"text\":\"entryText\","
- + "\"offset\":42,"
- + "\"length\":313,"
- + "\"options\":[{"
- + "\"text\":\"someText\","
- + "\"highlighted\":\"somethingHighlighted\","
- + "\"score\":1.3,"
- + "\"collate_match\":true}]"
- + "}]"
- + "}", xContent.utf8ToString());
+ "{"
+ + " \"phrase#suggestionName\": ["
+ + " {"
+ + " \"text\": \"entryText\","
+ + " \"offset\": 42,"
+ + " \"length\": 313,"
+ + " \"options\": ["
+ + " {"
+ + " \"text\": \"someText\","
+ + " \"highlighted\": \"somethingHighlighted\","
+ + " \"score\": 1.3,"
+ + " \"collate_match\": true"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + "}",
+ xContent.utf8ToString()
+ );
}
{
TermSuggestion.Entry.Option option = new TermSuggestion.Entry.Option(new Text("someText"), 10, 1.3f);
@@ -237,16 +259,24 @@ public void testToXContent() throws IOException {
suggestion.addTerm(entry);
BytesReference xContent = toXContent(suggestion, XContentType.JSON, params, randomBoolean());
assertEquals(
- "{\"term#suggestionName\":[{"
- + "\"text\":\"entryText\","
- + "\"offset\":42,"
- + "\"length\":313,"
- + "\"options\":[{"
- + "\"text\":\"someText\","
- + "\"score\":1.3,"
- + "\"freq\":10}]"
- + "}]"
- + "}", xContent.utf8ToString());
+ "{"
+ + " \"term#suggestionName\": ["
+ + " {"
+ + " \"text\": \"entryText\","
+ + " \"offset\": 42,"
+ + " \"length\": 313,"
+ + " \"options\": ["
+ + " {"
+ + " \"text\": \"someText\","
+ + " \"score\": 1.3,"
+ + " \"freq\": 10"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + "}",
+ xContent.utf8ToString()
+ );
}
{
Map> contexts = Collections.singletonMap("key", Collections.singleton("value"));
@@ -257,16 +287,28 @@ public void testToXContent() throws IOException {
suggestion.addTerm(entry);
BytesReference xContent = toXContent(suggestion, XContentType.JSON, params, randomBoolean());
assertEquals(
- "{\"completion#suggestionName\":[{"
- + "\"text\":\"entryText\","
- + "\"offset\":42,"
- + "\"length\":313,"
- + "\"options\":[{"
- + "\"text\":\"someText\","
- + "\"score\":1.3,"
- + "\"contexts\":{\"key\":[\"value\"]}"
- + "}]"
- + "}]}", xContent.utf8ToString());
+ "{"
+ + " \"completion#suggestionName\": ["
+ + " {"
+ + " \"text\": \"entryText\","
+ + " \"offset\": 42,"
+ + " \"length\": 313,"
+ + " \"options\": ["
+ + " {"
+ + " \"text\": \"someText\","
+ + " \"score\": 1.3,"
+ + " \"contexts\": {"
+ + " \"key\": ["
+ + " \"value\""
+ + " ]"
+ + " }"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + "}",
+ xContent.utf8ToString()
+ );
}
}
}
diff --git a/server/src/test/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilderTests.java b/server/src/test/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilderTests.java
index d4292151a710e..5a135a0ab4cc9 100644
--- a/server/src/test/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilderTests.java
+++ b/server/src/test/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilderTests.java
@@ -210,14 +210,16 @@ public void testDefaultValuesSet() {
public void testMalformedJson() {
final String field = RandomStrings.randomAsciiOfLength(random(), 10).toLowerCase(Locale.ROOT);
- String suggest = "{\n" +
- " \"bad-payload\" : {\n" +
- " \"text\" : \"the amsterdma meetpu\",\n" +
- " \"term\" : {\n" +
- " \"field\" : { \"" + field + "\" : \"bad-object\" }\n" +
- " }\n" +
- " }\n" +
- "}";
+ String suggest = "{\n"
+ + " \"bad-payload\" : {\n"
+ + " \"text\" : \"the amsterdma meetpu\",\n"
+ + " \"term\" : {\n"
+ + " \"field\" : { \""
+ + field
+ + "\" : \"bad-object\" }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, suggest)) {
final SuggestBuilder suggestBuilder = SuggestBuilder.fromXContent(parser);
fail("Should not have been able to create SuggestBuilder from malformed JSON: " + suggestBuilder);
diff --git a/server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java b/server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java
index 649b94099cc74..0be9858269af0 100644
--- a/server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java
+++ b/server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java
@@ -59,8 +59,8 @@ public void testAbsoluteTime() throws Exception {
long currentTime = System.currentTimeMillis();
long gotTime = threadPool.absoluteTimeInMillis();
long delta = Math.abs(gotTime - currentTime);
- assertTrue("thread pool cached absolute time " + gotTime + " is too far from real current time " + currentTime,
- delta < 10000); // the delta can be large, we just care it is the same order of magnitude
+ // the delta can be large, we just care it is the same order of magnitude
+ assertTrue("thread pool cached absolute time " + gotTime + " is too far from real current time " + currentTime, delta < 10000);
} finally {
threadPool.shutdown();
threadPool.close();
diff --git a/test/framework/src/main/java/org/elasticsearch/common/util/NamedFormatter.java b/test/framework/src/main/java/org/elasticsearch/common/util/NamedFormatter.java
new file mode 100644
index 0000000000000..819ac4c69c4c7
--- /dev/null
+++ b/test/framework/src/main/java/org/elasticsearch/common/util/NamedFormatter.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.common.util;
+
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * A formatter that allows named placeholders e.g. "%(param)" to be replaced.
+ */
+public class NamedFormatter {
+ private static final Pattern PARAM_REGEX = Pattern
+ .compile(
+ // Match either any backlash-escaped characters, or a "%(param)" pattern.
+ // COMMENTS is specified to allow whitespace in this pattern, for clarity
+ "\\\\(.) | (% \\( ([^)]+) \\) )",
+ Pattern.COMMENTS
+ );
+
+ private NamedFormatter() {}
+
+ /**
+ * Replaces named parameters of the form %(param)
in format strings. For example:
+ *
+ *
+ * NamedFormatter.format("Hello, %(name)!", Map.of("name", "world"))
→ "Hello, world!"
+ * NamedFormatter.format("Hello, \%(name)!", Map.of("name", "world"))
→ "Hello, %(world)!"
+ * NamedFormatter.format("Hello, %(oops)!", Map.of("name", "world"))
→ {@link IllegalArgumentException}
+ *
+ *
+ * @param fmt The format string. Any %(param)
is replaced by its corresponding value in the values
map.
+ * Parameter patterns can be escaped by prefixing with a backslash.
+ * @param values a map of parameter names to values.
+ * @return The formatted string.
+ * @throws IllegalArgumentException if a parameter is found in the format string with no corresponding value
+ */
+ public static String format(String fmt, Map values) {
+ return PARAM_REGEX.matcher(fmt).replaceAll(match -> {
+ // Escaped characters are unchanged
+ if (match.group(1) != null) {
+ return match.group(1);
+ }
+
+ final String paramName = match.group(3);
+ if (values.containsKey(paramName) == true) {
+ return values.get(paramName).toString();
+ }
+
+ throw new IllegalArgumentException("No parameter value for %(" + paramName + ")");
+ });
+ }
+}
diff --git a/test/framework/src/test/java/org/elasticsearch/common/util/NamedFormatterTests.java b/test/framework/src/test/java/org/elasticsearch/common/util/NamedFormatterTests.java
new file mode 100644
index 0000000000000..06662adf0cd27
--- /dev/null
+++ b/test/framework/src/test/java/org/elasticsearch/common/util/NamedFormatterTests.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.common.util;
+
+import org.elasticsearch.test.ESTestCase;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+
+import java.util.Map;
+
+import static org.hamcrest.Matchers.equalTo;
+
+public class NamedFormatterTests extends ESTestCase {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ public void testPatternAreFormatted() {
+ assertThat(NamedFormatter.format("Hello, %(name)!", Map.of("name", "world")), equalTo("Hello, world!"));
+ }
+
+ public void testDuplicatePatternsAreFormatted() {
+ assertThat(NamedFormatter.format("Hello, %(name) and %(name)!", Map.of("name", "world")), equalTo("Hello, world and world!"));
+ }
+
+ public void testMultiplePatternsAreFormatted() {
+ assertThat(
+ NamedFormatter.format("Hello, %(name) and %(second_name)!", Map.of("name", "world", "second_name", "fred")),
+ equalTo("Hello, world and fred!")
+ );
+ }
+
+ public void testEscapedPatternsAreNotFormatted() {
+ assertThat(NamedFormatter.format("Hello, \\%(name)!", Map.of("name", "world")), equalTo("Hello, %(name)!"));
+ }
+
+ public void testUnknownPatternsThrowException() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("No parameter value for %(name)");
+ NamedFormatter.format("Hello, %(name)!", Map.of("foo", "world"));
+ }
+}
diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java
index 4ad0fb1dfd0d6..3d7b189476a6b 100644
--- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java
+++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java
@@ -536,18 +536,18 @@ static boolean shouldRetry(String remoteCluster, Exception e) {
}
final Throwable actual = ExceptionsHelper.unwrapCause(e);
- return actual instanceof ShardNotFoundException ||
- actual instanceof IllegalIndexShardStateException ||
- actual instanceof NoShardAvailableActionException ||
- actual instanceof UnavailableShardsException ||
- actual instanceof AlreadyClosedException ||
- actual instanceof ElasticsearchSecurityException || // If user does not have sufficient privileges
- actual instanceof ClusterBlockException || // If leader index is closed or no elected master
- actual instanceof IndexClosedException || // If follow index is closed
- actual instanceof ConnectTransportException ||
- actual instanceof NodeClosedException ||
- actual instanceof NoSuchRemoteClusterException ||
- (actual.getMessage() != null && actual.getMessage().contains("TransportService is closed"));
+ return actual instanceof ShardNotFoundException
+ || actual instanceof IllegalIndexShardStateException
+ || actual instanceof NoShardAvailableActionException
+ || actual instanceof UnavailableShardsException
+ || actual instanceof AlreadyClosedException
+ || actual instanceof ElasticsearchSecurityException // If user does not have sufficient privileges
+ || actual instanceof ClusterBlockException // If leader index is closed or no elected master
+ || actual instanceof IndexClosedException // If follow index is closed
+ || actual instanceof ConnectTransportException
+ || actual instanceof NodeClosedException
+ || actual instanceof NoSuchRemoteClusterException
+ || (actual.getMessage() != null && actual.getMessage().contains("TransportService is closed"));
}
// These methods are protected for testing purposes:
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AutoFollowStatsMonitoringDocTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AutoFollowStatsMonitoringDocTests.java
index eebed6de676ec..c9a50047b5915 100644
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AutoFollowStatsMonitoringDocTests.java
+++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AutoFollowStatsMonitoringDocTests.java
@@ -26,6 +26,7 @@
import java.time.ZoneOffset;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
@@ -92,45 +93,59 @@ public void testToXContent() throws IOException {
assertThat(
xContent.utf8ToString(),
equalTo(
- "{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"" + DATE_TIME_FORMATTER.formatMillis(timestamp) + "\","
- + "\"interval_ms\":" + intervalMillis + ","
- + "\"type\":\"ccr_auto_follow_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"" + DATE_TIME_FORMATTER.formatMillis(nodeTimestamp) + "\""
- + "},"
- + "\"ccr_auto_follow_stats\":{"
- + "\"number_of_failed_follow_indices\":" + autoFollowStats.getNumberOfFailedFollowIndices() + ","
- + "\"number_of_failed_remote_cluster_state_requests\":" +
- autoFollowStats.getNumberOfFailedRemoteClusterStateRequests() + ","
- + "\"number_of_successful_follow_indices\":" + autoFollowStats.getNumberOfSuccessfulFollowIndices() + ","
- + "\"recent_auto_follow_errors\":["
- + "{"
- + "\"leader_index\":\"" + recentAutoFollowExceptions.keySet().iterator().next() + "\","
- + "\"timestamp\":1,"
- + "\"auto_follow_exception\":{"
- + "\"type\":\"exception\","
- + "\"reason\":\"cannot follow index\""
- + "}"
- + "}"
- + "],"
- + "\"auto_followed_clusters\":["
- + "{"
- + "\"cluster_name\":\"" + trackingClusters.keySet().iterator().next() + "\","
- + "\"time_since_last_check_millis\":" +
- trackingClusters.values().iterator().next().getTimeSinceLastCheckMillis() + ","
- + "\"last_seen_metadata_version\":" +
- trackingClusters.values().iterator().next().getLastSeenMetadataVersion()
- + "}"
- + "]"
- + "}"
- + "}"));
+ XContentHelper.reformatJson(
+ String.format(
+ Locale.ROOT,
+ "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"%s\","
+ + " \"interval_ms\": %d,"
+ + " \"type\": \"ccr_auto_follow_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"%s\""
+ + " },"
+ + " \"ccr_auto_follow_stats\": {"
+ + " \"number_of_failed_follow_indices\": %d,"
+ + " \"number_of_failed_remote_cluster_state_requests\": %d,"
+ + " \"number_of_successful_follow_indices\": %d,"
+ + " \"recent_auto_follow_errors\": ["
+ + " {"
+ + " \"leader_index\": \"%s\","
+ + " \"timestamp\": 1,"
+ + " \"auto_follow_exception\": {"
+ + " \"type\": \"exception\","
+ + " \"reason\": \"cannot follow index\""
+ + " }"
+ + " }"
+ + " ],"
+ + " \"auto_followed_clusters\": ["
+ + " {"
+ + " \"cluster_name\": \"%s\","
+ + " \"time_since_last_check_millis\": %d,"
+ + " \"last_seen_metadata_version\": %d"
+ + " }"
+ + " ]"
+ + " }"
+ + "}",
+ DATE_TIME_FORMATTER.formatMillis(timestamp),
+ intervalMillis,
+ DATE_TIME_FORMATTER.formatMillis(nodeTimestamp),
+ autoFollowStats.getNumberOfFailedFollowIndices(),
+ autoFollowStats.getNumberOfFailedRemoteClusterStateRequests(),
+ autoFollowStats.getNumberOfSuccessfulFollowIndices(),
+ recentAutoFollowExceptions.keySet().iterator().next(),
+ trackingClusters.keySet().iterator().next(),
+ trackingClusters.values().iterator().next().getTimeSinceLastCheckMillis(),
+ trackingClusters.values().iterator().next().getLastSeenMetadataVersion()
+ )
+ )
+ )
+ );
}
public void testShardFollowNodeTaskStatusFieldsMapped() throws IOException {
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsMonitoringDocTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsMonitoringDocTests.java
index 12c251bb9d775..c509e5598699f 100644
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsMonitoringDocTests.java
+++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsMonitoringDocTests.java
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.time.ZoneOffset;
import java.util.Collections;
+import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
@@ -144,62 +145,101 @@ public void testToXContent() throws IOException {
final FollowStatsMonitoringDoc document = new FollowStatsMonitoringDoc("_cluster", timestamp, intervalMillis, node, status);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertThat(
- xContent.utf8ToString(),
- equalTo(
+ xContent.utf8ToString(),
+ equalTo(
+ XContentHelper.reformatJson(
+ String.format(
+ Locale.ROOT,
"{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"" + DATE_TIME_FORMATTER.formatMillis(timestamp) + "\","
- + "\"interval_ms\":" + intervalMillis + ","
- + "\"type\":\"ccr_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"" + DATE_TIME_FORMATTER.formatMillis(nodeTimestamp) + "\""
- + "},"
- + "\"ccr_stats\":{"
- + "\"remote_cluster\":\"leader_cluster\","
- + "\"leader_index\":\"leader_index\","
- + "\"follower_index\":\"follower_index\","
- + "\"shard_id\":" + shardId + ","
- + "\"leader_global_checkpoint\":" + leaderGlobalCheckpoint + ","
- + "\"leader_max_seq_no\":" + leaderMaxSeqNo + ","
- + "\"follower_global_checkpoint\":" + followerGlobalCheckpoint + ","
- + "\"follower_max_seq_no\":" + followerMaxSeqNo + ","
- + "\"last_requested_seq_no\":" + lastRequestedSeqNo + ","
- + "\"outstanding_read_requests\":" + numberOfConcurrentReads + ","
- + "\"outstanding_write_requests\":" + numberOfConcurrentWrites + ","
- + "\"write_buffer_operation_count\":" + writeBufferOperationCount + ","
- + "\"write_buffer_size_in_bytes\":" + writeBufferSizeInBytes + ","
- + "\"follower_mapping_version\":" + followerMappingVersion + ","
- + "\"follower_settings_version\":" + followerSettingsVersion + ","
- + "\"follower_aliases_version\":" + followerAliasesVersion + ","
- + "\"total_read_time_millis\":" + totalReadTimeMillis + ","
- + "\"total_read_remote_exec_time_millis\":" + totalReadRemoteExecTimeMillis + ","
- + "\"successful_read_requests\":" + successfulReadRequests + ","
- + "\"failed_read_requests\":" + failedReadRequests + ","
- + "\"operations_read\":" + operationsRead + ","
- + "\"bytes_read\":" + bytesRead + ","
- + "\"total_write_time_millis\":" + totalWriteTimeMillis +","
- + "\"successful_write_requests\":" + successfulWriteRequests + ","
- + "\"failed_write_requests\":" + failedWriteRequests + ","
- + "\"operations_written\":" + operationWritten + ","
- + "\"read_exceptions\":["
- + "{"
- + "\"from_seq_no\":" + fetchExceptions.keySet().iterator().next() + ","
- + "\"retries\":" + fetchExceptions.values().iterator().next().v1() + ","
- + "\"exception\":{"
- + "\"type\":\"exception\","
- + "\"reason\":\"shard is sad\""
- + "}"
- + "}"
- + "],"
- + "\"time_since_last_read_millis\":" + timeSinceLastReadMillis + ","
- + "\"fatal_exception\":{\"type\":\"exception\",\"reason\":\"fatal error\"}"
- + "}"
- + "}"));
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"%s\","
+ + " \"interval_ms\": %d,"
+ + " \"type\": \"ccr_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"%s\""
+ + " },"
+ + " \"ccr_stats\": {"
+ + " \"remote_cluster\": \"leader_cluster\","
+ + " \"leader_index\": \"leader_index\","
+ + " \"follower_index\": \"follower_index\","
+ + " \"shard_id\": %d,"
+ + " \"leader_global_checkpoint\": %d,"
+ + " \"leader_max_seq_no\": %d,"
+ + " \"follower_global_checkpoint\": %d,"
+ + " \"follower_max_seq_no\": %d,"
+ + " \"last_requested_seq_no\": %d,"
+ + " \"outstanding_read_requests\": %d,"
+ + " \"outstanding_write_requests\": %d,"
+ + " \"write_buffer_operation_count\": %d,"
+ + " \"write_buffer_size_in_bytes\": %d,"
+ + " \"follower_mapping_version\": %d,"
+ + " \"follower_settings_version\": %d,"
+ + " \"follower_aliases_version\": %d,"
+ + " \"total_read_time_millis\": %d,"
+ + " \"total_read_remote_exec_time_millis\": %d,"
+ + " \"successful_read_requests\": %d,"
+ + " \"failed_read_requests\": %d,"
+ + " \"operations_read\": %d,"
+ + " \"bytes_read\": %d,"
+ + " \"total_write_time_millis\": %d,"
+ + " \"successful_write_requests\": %d,"
+ + " \"failed_write_requests\": %d,"
+ + " \"operations_written\": %d,"
+ + " \"read_exceptions\": ["
+ + " {"
+ + " \"from_seq_no\": %d,"
+ + " \"retries\": %d,"
+ + " \"exception\": {"
+ + " \"type\": \"exception\","
+ + " \"reason\": \"shard is sad\""
+ + " }"
+ + " }"
+ + " ],"
+ + " \"time_since_last_read_millis\": %d,"
+ + " \"fatal_exception\": {"
+ + " \"type\": \"exception\","
+ + " \"reason\": \"fatal error\""
+ + " }"
+ + " }"
+ + "}",
+ DATE_TIME_FORMATTER.formatMillis(timestamp),
+ intervalMillis,
+ DATE_TIME_FORMATTER.formatMillis(nodeTimestamp),
+ shardId,
+ leaderGlobalCheckpoint,
+ leaderMaxSeqNo,
+ followerGlobalCheckpoint,
+ followerMaxSeqNo,
+ lastRequestedSeqNo,
+ numberOfConcurrentReads,
+ numberOfConcurrentWrites,
+ writeBufferOperationCount,
+ writeBufferSizeInBytes,
+ followerMappingVersion,
+ followerSettingsVersion,
+ followerAliasesVersion,
+ totalReadTimeMillis,
+ totalReadRemoteExecTimeMillis,
+ successfulReadRequests,
+ failedReadRequests,
+ operationsRead,
+ bytesRead,
+ totalWriteTimeMillis,
+ successfulWriteRequests,
+ failedWriteRequests,
+ operationWritten,
+ fetchExceptions.keySet().iterator().next(),
+ fetchExceptions.values().iterator().next().v1(),
+ timeSinceLastReadMillis
+ )
+ )
+ )
+ );
}
public void testShardFollowNodeTaskStatusFieldsMapped() throws IOException {
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java
index d5d1b5440daea..44126526d8245 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java
@@ -136,30 +136,75 @@ private XPackSettings() {
* but instead parse based on a prefix (eg *.ssl.*)
*/
private static final List JDK11_CIPHERS = List.of(
- "TLS_AES_256_GCM_SHA384", "TLS_AES_128_GCM_SHA256", // TLSv1.3 cipher has PFS, AEAD, hardware support
- "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", // PFS, AEAD, hardware support
- "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", // PFS, AEAD, hardware support
- "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", // PFS, hardware support
- "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", // PFS, hardware support
- "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", // PFS, hardware support
- "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", // PFS, hardware support
- "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256", // AEAD, hardware support
- "TLS_RSA_WITH_AES_256_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA256", // hardware support
- "TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA"); // hardware support
+ // TLSv1.3 cipher has PFS, AEAD, hardware support
+ "TLS_AES_256_GCM_SHA384",
+ "TLS_AES_128_GCM_SHA256",
+ // PFS, AEAD, hardware support
+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
+ // PFS, AEAD, hardware support
+ "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
+ "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
+ // PFS, hardware support
+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
+ // PFS, hardware support
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
+ // PFS, hardware support
+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
+ // PFS, hardware support
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
+ // AEAD, hardware support
+ "TLS_RSA_WITH_AES_256_GCM_SHA384",
+ "TLS_RSA_WITH_AES_128_GCM_SHA256",
+ // hardware support
+ "TLS_RSA_WITH_AES_256_CBC_SHA256",
+ "TLS_RSA_WITH_AES_128_CBC_SHA256",
+ // hardware support
+ "TLS_RSA_WITH_AES_256_CBC_SHA",
+ "TLS_RSA_WITH_AES_128_CBC_SHA"
+ );
private static final List JDK12_CIPHERS = List.of(
- "TLS_AES_256_GCM_SHA384", "TLS_AES_128_GCM_SHA256", // TLSv1.3 cipher has PFS, AEAD, hardware support
- "TLS_CHACHA20_POLY1305_SHA256", // TLSv1.3 cipher has PFS, AEAD
- "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", // PFS, AEAD, hardware support
- "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", // PFS, AEAD, hardware support
- "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", // PFS, AEAD
- "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", // PFS, hardware support
- "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", // PFS, hardware support
- "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", // PFS, hardware support
- "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", // PFS, hardware support
- "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256", // AEAD, hardware support
- "TLS_RSA_WITH_AES_256_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA256", // hardware support
- "TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA"); // hardware support
+ // TLSv1.3 cipher has PFS, AEAD, hardware support
+ "TLS_AES_256_GCM_SHA384",
+ "TLS_AES_128_GCM_SHA256",
+ // TLSv1.3 cipher has PFS, AEAD
+ "TLS_CHACHA20_POLY1305_SHA256",
+ // PFS, AEAD, hardware support
+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
+ // PFS, AEAD, hardware support
+ "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
+ "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
+ // PFS, AEAD
+ "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
+ "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
+ // PFS, hardware support
+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
+ // PFS, hardware support
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
+ // PFS, hardware support
+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
+ // PFS, hardware support
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
+ // AEAD, hardware support
+ "TLS_RSA_WITH_AES_256_GCM_SHA384",
+ "TLS_RSA_WITH_AES_128_GCM_SHA256",
+ // hardware support
+ "TLS_RSA_WITH_AES_256_CBC_SHA256",
+ "TLS_RSA_WITH_AES_128_CBC_SHA256",
+ // hardware support
+ "TLS_RSA_WITH_AES_256_CBC_SHA",
+ "TLS_RSA_WITH_AES_128_CBC_SHA"
+ );
public static final List DEFAULT_CIPHERS =
JavaVersion.current().compareTo(JavaVersion.parse("12")) > -1 ? JDK12_CIPHERS : JDK11_CIPHERS;
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java
index 2bddfe6771317..8c92847a44d66 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java
@@ -52,8 +52,8 @@ public void performAction(IndexMetaData indexMetaData, ClusterState currentState
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, indexMetaData.getNumberOfReplicas())
.put(LifecycleSettings.LIFECYCLE_NAME, lifecycle)
- .put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", (String) null) // need to remove the single shard
- // allocation so replicas can be allocated
+ // need to remove the single shard allocation so replicas can be allocated
+ .put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", (String) null)
.build();
String shrunkenIndexName = shrunkIndexPrefix + indexMetaData.getIndex().getName();
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java
index 3aba5df62c51c..68c3de13eb00e 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java
@@ -68,11 +68,13 @@ public void evaluateCondition(IndexMetaData indexMetaData, Listener listener) {
Boolean isWriteIndex = null;
if (aliasPointsToThisIndex) {
- // The writeIndex() call returns a tri-state boolean:
- // true -> this index is the write index for this alias
- // false -> this index is not the write index for this alias
- // null -> this alias is a "classic-style" alias and does not have a write index configured, but only points to one index
- // and is thus the write index by default
+ /*
+ * The writeIndex() call returns a tri-state boolean:
+ * true -> this index is the write index for this alias
+ * false -> this index is not the write index for this alias
+ * null -> this alias is a "classic-style" alias and does not have a write index configured, but only points to one index
+ * and is thus the write index by default
+ */
isWriteIndex = indexMetaData.getAliases().get(rolloverAlias).writeIndex();
}
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformCheckpoint.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformCheckpoint.java
index 06586b60e1c34..699d3e6c1b4a0 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformCheckpoint.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformCheckpoint.java
@@ -230,10 +230,11 @@ public boolean matches (TransformCheckpoint that) {
}
return Objects.equals(this.transformId, that.transformId)
- && this.indicesCheckpoints.size() == that.indicesCheckpoints.size() // quick check
- // do the expensive deep equal operation last
- && this.indicesCheckpoints.entrySet().stream()
- .allMatch(e -> Arrays.equals(e.getValue(), that.indicesCheckpoints.get(e.getKey())));
+ // quick check
+ && this.indicesCheckpoints.size() == that.indicesCheckpoints.size()
+ // do the expensive deep equal operation last
+ && this.indicesCheckpoints.entrySet().stream()
+ .allMatch(e -> Arrays.equals(e.getValue(), that.indicesCheckpoints.get(e.getKey())));
}
@Override
diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/ExpirationCallbackTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/ExpirationCallbackTests.java
index 1aff695546268..3ecf38f4b0543 100644
--- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/ExpirationCallbackTests.java
+++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/ExpirationCallbackTests.java
@@ -23,7 +23,8 @@ public void testPostExpirationDelay() throws Exception {
long now = System.currentTimeMillis();
long expiryDate = now + expiryDuration.getMillis();
assertThat(post.delay(expiryDate, now),
- equalTo(TimeValue.timeValueMillis(expiryDuration.getMillis() + min.getMillis()))); // before license expiry
+ // before license expiry
+ equalTo(TimeValue.timeValueMillis(expiryDuration.getMillis() + min.getMillis())));
assertThat(post.delay(expiryDate, expiryDate), equalTo(min)); // on license expiry
int latestValidTriggerDelay = (int) (expiryDuration.getMillis() + max.getMillis());
int earliestValidTriggerDelay = (int) (expiryDuration.getMillis() + min.getMillis());
@@ -151,4 +152,4 @@ private static class NoopPreExpirationCallback extends ExpirationCallback.Pre {
@Override
public void on(License license) {}
}
-}
\ No newline at end of file
+}
diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java
index 467a859b6c2d6..95533ae3f4163 100644
--- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java
+++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java
@@ -40,9 +40,10 @@ protected boolean addMockHttpTransport() {
private Settings.Builder nodeSettingsBuilder(int nodeOrdinal) {
return Settings.builder()
- .put(super.nodeSettings(nodeOrdinal))
- .put("node.data", true)
- .put("resource.reload.interval.high", "500ms"); // for license mode file watcher
+ .put(super.nodeSettings(nodeOrdinal))
+ .put("node.data", true)
+ // for license mode file watcher
+ .put("resource.reload.interval.high", "500ms");
}
@Override
diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/DataFrameAnalyticsConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/DataFrameAnalyticsConfigTests.java
index 4f6af0e5dda3c..3f9eef45bb38e 100644
--- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/DataFrameAnalyticsConfigTests.java
+++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/DataFrameAnalyticsConfigTests.java
@@ -135,21 +135,20 @@ public static String randomValidId() {
return generator.ofCodePointsLength(random(), 10, 10);
}
- private static final String ANACHRONISTIC_QUERY_DATA_FRAME_ANALYTICS = "{\n" +
- " \"id\": \"old-data-frame\",\n" +
- //query:match:type stopped being supported in 6.x
- " \"source\": {\"index\":\"my-index\", \"query\": {\"match\" : {\"query\":\"fieldName\", \"type\": \"phrase\"}}},\n" +
- " \"dest\": {\"index\":\"dest-index\"},\n" +
- " \"analysis\": {\"outlier_detection\": {\"n_neighbors\": 10}}\n" +
- "}";
-
- private static final String MODERN_QUERY_DATA_FRAME_ANALYTICS = "{\n" +
- " \"id\": \"data-frame\",\n" +
- // match_all if parsed, adds default values in the options
- " \"source\": {\"index\":\"my-index\", \"query\": {\"match_all\" : {}}},\n" +
- " \"dest\": {\"index\":\"dest-index\"},\n" +
- " \"analysis\": {\"outlier_detection\": {\"n_neighbors\": 10}}\n" +
- "}";
+ // query:match:type stopped being supported in 6.x
+ private static final String ANACHRONISTIC_QUERY_DATA_FRAME_ANALYTICS = "{\n"
+ + " \"id\": \"old-data-frame\",\n"
+ + " \"source\": {\"index\":\"my-index\", \"query\": {\"match\" : {\"query\":\"fieldName\", \"type\": \"phrase\"}}},\n"
+ + " \"dest\": {\"index\":\"dest-index\"},\n"
+ + " \"analysis\": {\"outlier_detection\": {\"n_neighbors\": 10}}\n"
+ + "}";
+
+ private static final String MODERN_QUERY_DATA_FRAME_ANALYTICS = "{\n"
+ + " \"id\": \"data-frame\",\n"
+ + " \"source\": {\"index\":\"my-index\", \"query\": {\"match_all\" : {}}},\n" // match_all if parsed, adds default values in
+ + " \"dest\": {\"index\":\"dest-index\"},\n" // the options
+ + " \"analysis\": {\"outlier_detection\": {\"n_neighbors\": 10}}\n"
+ + "}";
private boolean lenient;
@@ -327,11 +326,7 @@ public void testPreventCreateTimeInjection() throws IOException {
}
public void testPreventVersionInjection() throws IOException {
- String json = "{"
- + " \"version\" : \"7.3.0\","
- + " \"source\" : {\"index\":\"src\"},"
- + " \"dest\" : {\"index\": \"dest\"},"
- + "}";
+ String json = "{ \"version\" : \"7.3.0\", \"source\" : {\"index\":\"src\"}, \"dest\" : {\"index\": \"dest\"}}";
try (XContentParser parser =
XContentFactory.xContent(XContentType.JSON).createParser(
diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfigTests.java
index 30c310fe3e412..5593a31ea9b17 100644
--- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfigTests.java
+++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfigTests.java
@@ -71,12 +71,7 @@ public void testAggsAbbreviations() throws IOException {
}
public void testMissingAggs() throws IOException {
- String pivot = "{"
- + " \"group_by\": {"
- + " \"id\": {"
- + " \"terms\": {"
- + " \"field\": \"id\""
- + "} } } }";
+ String pivot = "{ \"group_by\": { \"id\": { \"terms\": { \"field\": \"id\"} } } }";
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
}
@@ -115,12 +110,7 @@ public void testEmptyGroupBy() throws IOException {
}
public void testMissingGroupBy() {
- String pivot = "{"
- + " \"aggs\": {"
- + " \"avg\": {"
- + " \"avg\": {"
- + " \"field\": \"points\""
- + "} } } }";
+ String pivot = "{ \"aggs\": { \"avg\": { \"avg\": { \"field\": \"points\"} } } }";
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
}
diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java
index c0c8822ac232f..e43abb448f3f7 100644
--- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java
+++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java
@@ -219,10 +219,11 @@ synchronized void expand() {
rootBool.must(sourceTermsOrClause);
-
- //Now build the agg tree that will channel the content ->
- // base agg is terms agg for terms from last wave (one per field),
- // under each is a sig_terms agg to find next candidates (again, one per field)...
+ /*
+ * Now build the agg tree that will channel the content ->
+ * base agg is terms agg for terms from last wave (one per field),
+ * under each is a sig_terms agg to find next candidates (again, one per field)...
+ */
for (int fieldNum = 0; fieldNum < lastHop.getNumberVertexRequests(); fieldNum++) {
VertexRequest lastVr = lastHop.getVertexRequest(fieldNum);
Set lastWaveVerticesForField = lastHopFindings.get(lastVr.fieldName());
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java
index a4e76d60f041c..7d0b2fac0656e 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java
@@ -57,6 +57,7 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import static java.util.Collections.emptyList;
@@ -343,240 +344,250 @@ public void testToXContent() throws IOException {
needToEnableTLS);
final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"cluster_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"cluster_name\":\"_cluster_name\","
- + "\"version\":\"_version\","
- + "\"license\":{"
- + "\"status\":\"expired\","
- + "\"uid\":\"442ca961-9c00-4bb2-b5c9-dfaacd547403\","
- + "\"type\":\"trial\","
- + "\"issue_date\":\"2016-01-01T00:00:00.000Z\","
- + "\"issue_date_in_millis\":1451606400000,"
- + "\"expiry_date\":\"2017-08-07T12:03:22.133Z\","
- + "\"expiry_date_in_millis\":1502107402133,"
- + "\"max_nodes\":2,"
- + "\"issued_to\":\"customer\","
- + "\"issuer\":\"elasticsearch\","
- + "\"start_date_in_millis\":-1"
- + (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "")
- + "},"
- + "\"cluster_stats\":{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":1451606400000,"
- + "\"status\":\"red\","
- + "\"indices\":{"
- + "\"count\":1,"
- + "\"shards\":{"
- + "\"total\":1,"
- + "\"primaries\":1,"
- + "\"replication\":0.0,"
- + "\"index\":{"
- + "\"shards\":{"
- + "\"min\":1,"
- + "\"max\":1,"
- + "\"avg\":1.0"
- + "},"
- + "\"primaries\":{"
- + "\"min\":1,"
- + "\"max\":1,"
- + "\"avg\":1.0"
- + "},"
- + "\"replication\":{"
- + "\"min\":0.0,"
- + "\"max\":0.0,"
- + "\"avg\":0.0"
- + "}"
- + "}"
- + "},"
- + "\"docs\":{"
- + "\"count\":0,"
- + "\"deleted\":0"
- + "},"
- + "\"store\":{"
- + "\"size_in_bytes\":0"
- + "},"
- + "\"fielddata\":{"
- + "\"memory_size_in_bytes\":0,"
- + "\"evictions\":0"
- + "},"
- + "\"query_cache\":{"
- + "\"memory_size_in_bytes\":0,"
- + "\"total_count\":0,"
- + "\"hit_count\":0,"
- + "\"miss_count\":0,"
- + "\"cache_size\":0,"
- + "\"cache_count\":0,"
- + "\"evictions\":0"
- + "},"
- + "\"completion\":{"
- + "\"size_in_bytes\":0"
- + "},"
- + "\"segments\":{"
- + "\"count\":0,"
- + "\"memory_in_bytes\":0,"
- + "\"terms_memory_in_bytes\":0,"
- + "\"stored_fields_memory_in_bytes\":0,"
- + "\"term_vectors_memory_in_bytes\":0,"
- + "\"norms_memory_in_bytes\":0,"
- + "\"points_memory_in_bytes\":0,"
- + "\"doc_values_memory_in_bytes\":0,"
- + "\"index_writer_memory_in_bytes\":0,"
- + "\"version_map_memory_in_bytes\":0,"
- + "\"fixed_bit_set_memory_in_bytes\":0,"
- + "\"max_unsafe_auto_id_timestamp\":-9223372036854775808,"
- + "\"file_sizes\":{}"
- + "}"
- + "},"
- + "\"nodes\":{"
- + "\"count\":{"
- + "\"total\":1,"
- + "\"coordinating_only\":0,"
- + "\"data\":0,"
- + "\"ingest\":0,"
- + "\"master\":1"
- + "},"
- + "\"versions\":["
- + "\"" + mockNodeVersion + "\""
- + "],"
- + "\"os\":{"
- + "\"available_processors\":32,"
- + "\"allocated_processors\":16,"
- + "\"names\":["
- + "{"
- + "\"name\":\"_os_name\","
- + "\"count\":1"
- + "}"
- + "],"
- + "\"pretty_names\":["
- + "{"
- + "\"pretty_name\":\"_pretty_os_name\","
- + "\"count\":1"
- + "}"
- + "],"
- + "\"mem\":{"
- + "\"total_in_bytes\":100,"
- + "\"free_in_bytes\":79,"
- + "\"used_in_bytes\":21,"
- + "\"free_percent\":79,"
- + "\"used_percent\":21"
- + "}"
- + "},"
- + "\"process\":{"
- + "\"cpu\":{"
- + "\"percent\":3"
- + "},"
- + "\"open_file_descriptors\":{"
- + "\"min\":42,"
- + "\"max\":42,"
- + "\"avg\":42"
- + "}"
- + "},"
- + "\"jvm\":{"
- + "\"max_uptime_in_millis\":10800000,"
- + "\"versions\":["
- + "{"
- + "\"version\":\"_jvm_version\","
- + "\"vm_name\":\"_jvm_vm_name\","
- + "\"vm_version\":\"_jvm_vm_version\","
- + "\"vm_vendor\":\"_jvm_vm_vendor\","
- + "\"bundled_jdk\":true,"
- + "\"using_bundled_jdk\":true,"
- + "\"count\":1"
- + "}"
- + "],"
- + "\"mem\":{"
- + "\"heap_used_in_bytes\":536870912,"
- + "\"heap_max_in_bytes\":25769803776"
- + "},"
- + "\"threads\":9"
- + "},"
- + "\"fs\":{"
- + "\"total_in_bytes\":100,"
- + "\"free_in_bytes\":49,"
- + "\"available_in_bytes\":51"
- + "},"
- + "\"plugins\":["
- + "{"
- + "\"name\":\"_plugin\","
- + "\"version\":\"_plugin_version\","
- + "\"elasticsearch_version\":\"" + Version.CURRENT + "\","
- + "\"java_version\":\"1.8\","
- + "\"description\":\"_plugin_desc\","
- + "\"classname\":\"_plugin_class\","
- + "\"extended_plugins\":[],"
- + "\"has_native_controller\":false"
- + "}"
- + "],"
- + "\"network_types\":{"
- + "\"transport_types\":{"
- + "\"_transport\":1"
- + "},"
- + "\"http_types\":{"
- + "\"_http\":1"
- + "}"
- + "},"
- + "\"discovery_types\":{"
- + "\"_disco\":1"
- + "},"
- + "\"packaging_types\":["
- + "{"
- + "\"flavor\":\"default\","
- + "\"type\":\"docker\","
- + "\"count\":1"
- + "}"
- + "]"
- + "}"
- + "},"
- + "\"cluster_state\":{"
- + "\"nodes_hash\":1314980060,"
- + "\"status\":\"green\","
- + "\"cluster_uuid\":\"_cluster\","
- + "\"version\":12,"
- + "\"state_uuid\":\"_state_uuid\","
- + "\"master_node\":\"_node\","
- + "\"nodes\":{"
- + "\"_node_id\":{"
- + "\"name\":\"_node_name\","
- + "\"ephemeral_id\":\"_ephemeral_id\","
- + "\"transport_address\":\"0.0.0.0:9300\","
- + "\"attributes\":{"
- + "\"attr\":\"value\""
- + "}"
- + "}"
- + "}"
- + "},"
- + "\"cluster_settings\":{"
- + "\"cluster\":{"
- + "\"metadata\":{"
- + "\"display_name\":\"my_prod_cluster\""
- + "}"
- + "}"
- + "},"
- + "\"stack_stats\":{"
- + "\"apm\":{"
- + "\"found\":" + apmIndicesExist
- + "},"
- + "\"xpack\":{"
- + "\"monitoring\":{"
- + "\"available\":false,"
- + "\"enabled\":true,"
- + "\"collection_enabled\":false"
- + "}"
- + "}"
- + "}"
- + "}" , xContent.utf8ToString());
+ final String expected = XContentHelper.reformatJson(
+ String.format(
+ Locale.ROOT,
+ "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-07T12:03:22.133Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"cluster_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"cluster_name\": \"_cluster_name\","
+ + " \"version\": \"_version\","
+ + " \"license\": {"
+ + " \"status\": \"expired\","
+ + " \"uid\": \"442ca961-9c00-4bb2-b5c9-dfaacd547403\","
+ + " \"type\": \"trial\","
+ + " \"issue_date\": \"2016-01-01T00:00:00.000Z\","
+ + " \"issue_date_in_millis\": 1451606400000,"
+ + " \"expiry_date\": \"2017-08-07T12:03:22.133Z\","
+ + " \"expiry_date_in_millis\": 1502107402133,"
+ + " \"max_nodes\": 2,"
+ + " \"issued_to\": \"customer\","
+ + " \"issuer\": \"elasticsearch\","
+ + " \"start_date_in_millis\": -1"
+ + " %s" // optional field: `cluster_needs_tls`
+ + " },"
+ + " \"cluster_stats\": {"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": 1451606400000,"
+ + " \"status\": \"red\","
+ + " \"indices\": {"
+ + " \"count\": 1,"
+ + " \"shards\": {"
+ + " \"total\": 1,"
+ + " \"primaries\": 1,"
+ + " \"replication\": 0.0,"
+ + " \"index\": {"
+ + " \"shards\": {"
+ + " \"min\": 1,"
+ + " \"max\": 1,"
+ + " \"avg\": 1.0"
+ + " },"
+ + " \"primaries\": {"
+ + " \"min\": 1,"
+ + " \"max\": 1,"
+ + " \"avg\": 1.0"
+ + " },"
+ + " \"replication\": {"
+ + " \"min\": 0.0,"
+ + " \"max\": 0.0,"
+ + " \"avg\": 0.0"
+ + " }"
+ + " }"
+ + " },"
+ + " \"docs\": {"
+ + " \"count\": 0,"
+ + " \"deleted\": 0"
+ + " },"
+ + " \"store\": {"
+ + " \"size_in_bytes\": 0"
+ + " },"
+ + " \"fielddata\": {"
+ + " \"memory_size_in_bytes\": 0,"
+ + " \"evictions\": 0"
+ + " },"
+ + " \"query_cache\": {"
+ + " \"memory_size_in_bytes\": 0,"
+ + " \"total_count\": 0,"
+ + " \"hit_count\": 0,"
+ + " \"miss_count\": 0,"
+ + " \"cache_size\": 0,"
+ + " \"cache_count\": 0,"
+ + " \"evictions\": 0"
+ + " },"
+ + " \"completion\": {"
+ + " \"size_in_bytes\": 0"
+ + " },"
+ + " \"segments\": {"
+ + " \"count\": 0,"
+ + " \"memory_in_bytes\": 0,"
+ + " \"terms_memory_in_bytes\": 0,"
+ + " \"stored_fields_memory_in_bytes\": 0,"
+ + " \"term_vectors_memory_in_bytes\": 0,"
+ + " \"norms_memory_in_bytes\": 0,"
+ + " \"points_memory_in_bytes\": 0,"
+ + " \"doc_values_memory_in_bytes\": 0,"
+ + " \"index_writer_memory_in_bytes\": 0,"
+ + " \"version_map_memory_in_bytes\": 0,"
+ + " \"fixed_bit_set_memory_in_bytes\": 0,"
+ + " \"max_unsafe_auto_id_timestamp\": -9223372036854775808,"
+ + " \"file_sizes\": {}"
+ + " }"
+ + " },"
+ + " \"nodes\": {"
+ + " \"count\": {"
+ + " \"total\": 1,"
+ + " \"coordinating_only\": 0,"
+ + " \"data\": 0,"
+ + " \"ingest\": 0,"
+ + " \"master\": 1"
+ + " },"
+ + " \"versions\": ["
+ + " \"%s\""
+ + " ],"
+ + " \"os\": {"
+ + " \"available_processors\": 32,"
+ + " \"allocated_processors\": 16,"
+ + " \"names\": ["
+ + " {"
+ + " \"name\": \"_os_name\","
+ + " \"count\": 1"
+ + " }"
+ + " ],"
+ + " \"pretty_names\": ["
+ + " {"
+ + " \"pretty_name\": \"_pretty_os_name\","
+ + " \"count\": 1"
+ + " }"
+ + " ],"
+ + " \"mem\": {"
+ + " \"total_in_bytes\": 100,"
+ + " \"free_in_bytes\": 79,"
+ + " \"used_in_bytes\": 21,"
+ + " \"free_percent\": 79,"
+ + " \"used_percent\": 21"
+ + " }"
+ + " },"
+ + " \"process\": {"
+ + " \"cpu\": {"
+ + " \"percent\": 3"
+ + " },"
+ + " \"open_file_descriptors\": {"
+ + " \"min\": 42,"
+ + " \"max\": 42,"
+ + " \"avg\": 42"
+ + " }"
+ + " },"
+ + " \"jvm\": {"
+ + " \"max_uptime_in_millis\": 10800000,"
+ + " \"versions\": ["
+ + " {"
+ + " \"version\": \"_jvm_version\","
+ + " \"vm_name\": \"_jvm_vm_name\","
+ + " \"vm_version\": \"_jvm_vm_version\","
+ + " \"vm_vendor\": \"_jvm_vm_vendor\","
+ + " \"bundled_jdk\": true,"
+ + " \"using_bundled_jdk\": true,"
+ + " \"count\": 1"
+ + " }"
+ + " ],"
+ + " \"mem\": {"
+ + " \"heap_used_in_bytes\": 536870912,"
+ + " \"heap_max_in_bytes\": 25769803776"
+ + " },"
+ + " \"threads\": 9"
+ + " },"
+ + " \"fs\": {"
+ + " \"total_in_bytes\": 100,"
+ + " \"free_in_bytes\": 49,"
+ + " \"available_in_bytes\": 51"
+ + " },"
+ + " \"plugins\": ["
+ + " {"
+ + " \"name\": \"_plugin\","
+ + " \"version\": \"_plugin_version\","
+ + " \"elasticsearch_version\": \"%s\","
+ + " \"java_version\": \"1.8\","
+ + " \"description\": \"_plugin_desc\","
+ + " \"classname\": \"_plugin_class\","
+ + " \"extended_plugins\": [],"
+ + " \"has_native_controller\": false"
+ + " }"
+ + " ],"
+ + " \"network_types\": {"
+ + " \"transport_types\": {"
+ + " \"_transport\": 1"
+ + " },"
+ + " \"http_types\": {"
+ + " \"_http\": 1"
+ + " }"
+ + " },"
+ + " \"discovery_types\": {"
+ + " \"_disco\": 1"
+ + " },"
+ + " \"packaging_types\": ["
+ + " {"
+ + " \"flavor\": \"default\","
+ + " \"type\": \"docker\","
+ + " \"count\": 1"
+ + " }"
+ + " ]"
+ + " }"
+ + " },"
+ + " \"cluster_state\": {"
+ + " \"nodes_hash\": 1314980060,"
+ + " \"status\": \"green\","
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"version\": 12,"
+ + " \"state_uuid\": \"_state_uuid\","
+ + " \"master_node\": \"_node\","
+ + " \"nodes\": {"
+ + " \"_node_id\": {"
+ + " \"name\": \"_node_name\","
+ + " \"ephemeral_id\": \"_ephemeral_id\","
+ + " \"transport_address\": \"0.0.0.0:9300\","
+ + " \"attributes\": {"
+ + " \"attr\": \"value\""
+ + " }"
+ + " }"
+ + " }"
+ + " },"
+ + " \"cluster_settings\": {"
+ + " \"cluster\": {"
+ + " \"metadata\": {"
+ + " \"display_name\": \"my_prod_cluster\""
+ + " }"
+ + " }"
+ + " },"
+ + " \"stack_stats\": {"
+ + " \"apm\": {"
+ + " \"found\": %s"
+ + " },"
+ + " \"xpack\": {"
+ + " \"monitoring\": {"
+ + " \"available\": false,"
+ + " \"enabled\": true,"
+ + " \"collection_enabled\": false"
+ + " }"
+ + " }"
+ + " }"
+ + "}",
+ needToEnableTLS ? ",\"cluster_needs_tls\":true" : "",
+ mockNodeVersion,
+ Version.CURRENT,
+ apmIndicesExist
+ )
+ );
+ assertEquals(expected, xContent.utf8ToString());
}
private DiscoveryNode masterNode() {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java
index f018828c3a46d..633cb608a8a4e 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import static java.util.Collections.singleton;
@@ -115,75 +116,84 @@ public void testToXContent() throws IOException {
new IndexRecoveryMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, recoveryResponse);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"index_recovery\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"index_recovery\":{"
- + "\"shards\":["
- + "{"
- + "\"index_name\":\"_shard_0\","
- + "\"id\":0,"
- + "\"type\":\"PEER\","
- + "\"stage\":\"INIT\","
- + "\"primary\":true,"
- + "\"start_time_in_millis\":" + timer.startTime() + ","
- + "\"stop_time_in_millis\":" + timer.stopTime() + ","
- + "\"total_time_in_millis\":" + timer.time() + ","
- + "\"source\":{"
- + "\"id\":\"_node_id_1\","
- + "\"host\":\"_host_name_1\","
- + "\"transport_address\":\"0.0.0.0:9301\","
- + "\"ip\":\"_host_address_1\","
- + "\"name\":\"_node_1\""
- + "},"
- + "\"target\":{"
- + "\"id\":\"_node_id_1\","
- + "\"host\":\"_host_name_1\","
- + "\"transport_address\":\"0.0.0.0:9301\","
- + "\"ip\":\"_host_address_1\","
- + "\"name\":\"_node_1\""
- + "},"
- + "\"index\":{"
- + "\"size\":{"
- + "\"total_in_bytes\":0,"
- + "\"reused_in_bytes\":0,"
- + "\"recovered_in_bytes\":0,"
- + "\"percent\":\"0.0%\""
- + "},"
- + "\"files\":{"
- + "\"total\":0,"
- + "\"reused\":0,"
- + "\"recovered\":0,"
- + "\"percent\":\"0.0%\""
- + "},"
- + "\"total_time_in_millis\":0,"
- + "\"source_throttle_time_in_millis\":0,"
- + "\"target_throttle_time_in_millis\":0"
- + "},"
- + "\"translog\":{"
- + "\"recovered\":0,"
- + "\"total\":-1,"
- + "\"percent\":\"-1.0%\","
- + "\"total_on_start\":-1,"
- + "\"total_time_in_millis\":0"
- + "},"
- + "\"verify_index\":{"
- + "\"check_index_time_in_millis\":0,"
- + "\"total_time_in_millis\":0"
- + "}"
- + "}"
- + "]"
- + "}"
- + "}", xContent.utf8ToString());
+ final String expected = XContentHelper.reformatJson(
+ String.format(
+ Locale.ROOT,
+ "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-09T08:18:59.402Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"index_recovery\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"index_recovery\": {"
+ + " \"shards\": ["
+ + " {"
+ + " \"index_name\": \"_shard_0\","
+ + " \"id\": 0,"
+ + " \"type\": \"PEER\","
+ + " \"stage\": \"INIT\","
+ + " \"primary\": true,"
+ + " \"start_time_in_millis\": %d,"
+ + " \"stop_time_in_millis\": %d,"
+ + " \"total_time_in_millis\": %d,"
+ + " \"source\": {"
+ + " \"id\": \"_node_id_1\","
+ + " \"host\": \"_host_name_1\","
+ + " \"transport_address\": \"0.0.0.0:9301\","
+ + " \"ip\": \"_host_address_1\","
+ + " \"name\": \"_node_1\""
+ + " },"
+ + " \"target\": {"
+ + " \"id\": \"_node_id_1\","
+ + " \"host\": \"_host_name_1\","
+ + " \"transport_address\": \"0.0.0.0:9301\","
+ + " \"ip\": \"_host_address_1\","
+ + " \"name\": \"_node_1\""
+ + " },"
+ + " \"index\": {"
+ + " \"size\": {"
+ + " \"total_in_bytes\": 0,"
+ + " \"reused_in_bytes\": 0,"
+ + " \"recovered_in_bytes\": 0,"
+ + " \"percent\": \"0.0%%\""
+ + " },"
+ + " \"files\": {"
+ + " \"total\": 0,"
+ + " \"reused\": 0,"
+ + " \"recovered\": 0,"
+ + " \"percent\": \"0.0%%\""
+ + " },"
+ + " \"total_time_in_millis\": 0,"
+ + " \"source_throttle_time_in_millis\": 0,"
+ + " \"target_throttle_time_in_millis\": 0"
+ + " },"
+ + " \"translog\": {"
+ + " \"recovered\": 0,"
+ + " \"total\": -1,"
+ + " \"percent\": \"-1.0%%\","
+ + " \"total_on_start\": -1,"
+ + " \"total_time_in_millis\": 0"
+ + " },"
+ + " \"verify_index\": {"
+ + " \"check_index_time_in_millis\": 0,"
+ + " \"total_time_in_millis\": 0"
+ + " }"
+ + " }"
+ + " ]"
+ + " }"
+ + "}",
+ timer.startTime(),
+ timer.stopTime(),
+ timer.time()
+ )
+ );
+ assertEquals(expected, xContent.utf8ToString());
}
}
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsMonitoringDocTests.java
index 7f6a22e954c35..2ce4d41f8ede6 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsMonitoringDocTests.java
@@ -126,130 +126,130 @@ public void testToXContent() throws IOException {
new IndexStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, indexStats, metaData, routingTable);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
- assertThat(xContent.utf8ToString(), equalTo(
- "{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"index_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"index_stats\":{"
- + indexStatsSummary() + ","
- + "\"total\":{"
- + "\"docs\":{"
- + "\"count\":1"
- + "},"
- + "\"store\":{"
- + "\"size_in_bytes\":13"
- + "},"
- + "\"indexing\":{"
- + "\"index_total\":16,"
- + "\"index_time_in_millis\":17,"
- + "\"throttle_time_in_millis\":18"
- + "},"
- + "\"search\":{"
- + "\"query_total\":19,"
- + "\"query_time_in_millis\":20"
- + "},"
- + "\"merges\":{"
- + "\"total_size_in_bytes\":4"
- + "},"
- + "\"refresh\":{"
- + "\"total_time_in_millis\":14,"
- + "\"external_total_time_in_millis\":15"
- + "},"
- + "\"query_cache\":{"
- + "\"memory_size_in_bytes\":5,"
- + "\"hit_count\":6,"
- + "\"miss_count\":7,"
- + "\"evictions\":9"
- + "},"
- + "\"fielddata\":{"
- + "\"memory_size_in_bytes\":2,"
- + "\"evictions\":3"
- + "},"
- + "\"segments\":{"
- + "\"count\":21,"
- + "\"memory_in_bytes\":22,"
- + "\"terms_memory_in_bytes\":23,"
- + "\"stored_fields_memory_in_bytes\":24,"
- + "\"term_vectors_memory_in_bytes\":25,"
- + "\"norms_memory_in_bytes\":26,"
- + "\"points_memory_in_bytes\":27,"
- + "\"doc_values_memory_in_bytes\":28,"
- + "\"index_writer_memory_in_bytes\":29,"
- + "\"version_map_memory_in_bytes\":30,"
- + "\"fixed_bit_set_memory_in_bytes\":31"
- + "},"
- + "\"request_cache\":{"
- + "\"memory_size_in_bytes\":9,"
- + "\"evictions\":10,"
- + "\"hit_count\":11,"
- + "\"miss_count\":12"
- + "}"
- + "},"
- + "\"primaries\":{"
- + "\"docs\":{"
- + "\"count\":1"
- + "},"
- + "\"store\":{"
- + "\"size_in_bytes\":13"
- + "},"
- + "\"indexing\":{"
- + "\"index_total\":16,"
- + "\"index_time_in_millis\":17,"
- + "\"throttle_time_in_millis\":18"
- + "},"
- + "\"search\":{"
- + "\"query_total\":19,"
- + "\"query_time_in_millis\":20"
- + "},"
- + "\"merges\":{"
- + "\"total_size_in_bytes\":4"
- + "},"
- + "\"refresh\":{"
- + "\"total_time_in_millis\":14,"
- + "\"external_total_time_in_millis\":15"
- + "},"
- + "\"query_cache\":{"
- + "\"memory_size_in_bytes\":5,"
- + "\"hit_count\":6,"
- + "\"miss_count\":7,"
- + "\"evictions\":9"
- + "},"
- + "\"fielddata\":{"
- + "\"memory_size_in_bytes\":2,"
- + "\"evictions\":3"
- + "},"
- + "\"segments\":{"
- + "\"count\":21,"
- + "\"memory_in_bytes\":22,"
- + "\"terms_memory_in_bytes\":23,"
- + "\"stored_fields_memory_in_bytes\":24,"
- + "\"term_vectors_memory_in_bytes\":25,"
- + "\"norms_memory_in_bytes\":26,"
- + "\"points_memory_in_bytes\":27,"
- + "\"doc_values_memory_in_bytes\":28,"
- + "\"index_writer_memory_in_bytes\":29,"
- + "\"version_map_memory_in_bytes\":30,"
- + "\"fixed_bit_set_memory_in_bytes\":31"
- + "},"
- + "\"request_cache\":{"
- + "\"memory_size_in_bytes\":9,"
- + "\"evictions\":10,"
- + "\"hit_count\":11,"
- + "\"miss_count\":12"
- + "}"
- + "}"
- + "}"
- + "}"));
+ final String expected = XContentHelper.reformatJson(String.format(Locale.ROOT, "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-09T08:18:59.402Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"index_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"index_stats\": {"
+ + " %s," // indexStatsSummary()
+ + " \"total\": {"
+ + " \"docs\": {"
+ + " \"count\": 1"
+ + " },"
+ + " \"store\": {"
+ + " \"size_in_bytes\": 13"
+ + " },"
+ + " \"indexing\": {"
+ + " \"index_total\": 16,"
+ + " \"index_time_in_millis\": 17,"
+ + " \"throttle_time_in_millis\": 18"
+ + " },"
+ + " \"search\": {"
+ + " \"query_total\": 19,"
+ + " \"query_time_in_millis\": 20"
+ + " },"
+ + " \"merges\": {"
+ + " \"total_size_in_bytes\": 4"
+ + " },"
+ + " \"refresh\": {"
+ + " \"total_time_in_millis\": 14,"
+ + " \"external_total_time_in_millis\": 15"
+ + " },"
+ + " \"query_cache\": {"
+ + " \"memory_size_in_bytes\": 5,"
+ + " \"hit_count\": 6,"
+ + " \"miss_count\": 7,"
+ + " \"evictions\": 9"
+ + " },"
+ + " \"fielddata\": {"
+ + " \"memory_size_in_bytes\": 2,"
+ + " \"evictions\": 3"
+ + " },"
+ + " \"segments\": {"
+ + " \"count\": 21,"
+ + " \"memory_in_bytes\": 22,"
+ + " \"terms_memory_in_bytes\": 23,"
+ + " \"stored_fields_memory_in_bytes\": 24,"
+ + " \"term_vectors_memory_in_bytes\": 25,"
+ + " \"norms_memory_in_bytes\": 26,"
+ + " \"points_memory_in_bytes\": 27,"
+ + " \"doc_values_memory_in_bytes\": 28,"
+ + " \"index_writer_memory_in_bytes\": 29,"
+ + " \"version_map_memory_in_bytes\": 30,"
+ + " \"fixed_bit_set_memory_in_bytes\": 31"
+ + " },"
+ + " \"request_cache\": {"
+ + " \"memory_size_in_bytes\": 9,"
+ + " \"evictions\": 10,"
+ + " \"hit_count\": 11,"
+ + " \"miss_count\": 12"
+ + " }"
+ + " },"
+ + " \"primaries\": {"
+ + " \"docs\": {"
+ + " \"count\": 1"
+ + " },"
+ + " \"store\": {"
+ + " \"size_in_bytes\": 13"
+ + " },"
+ + " \"indexing\": {"
+ + " \"index_total\": 16,"
+ + " \"index_time_in_millis\": 17,"
+ + " \"throttle_time_in_millis\": 18"
+ + " },"
+ + " \"search\": {"
+ + " \"query_total\": 19,"
+ + " \"query_time_in_millis\": 20"
+ + " },"
+ + " \"merges\": {"
+ + " \"total_size_in_bytes\": 4"
+ + " },"
+ + " \"refresh\": {"
+ + " \"total_time_in_millis\": 14,"
+ + " \"external_total_time_in_millis\": 15"
+ + " },"
+ + " \"query_cache\": {"
+ + " \"memory_size_in_bytes\": 5,"
+ + " \"hit_count\": 6,"
+ + " \"miss_count\": 7,"
+ + " \"evictions\": 9"
+ + " },"
+ + " \"fielddata\": {"
+ + " \"memory_size_in_bytes\": 2,"
+ + " \"evictions\": 3"
+ + " },"
+ + " \"segments\": {"
+ + " \"count\": 21,"
+ + " \"memory_in_bytes\": 22,"
+ + " \"terms_memory_in_bytes\": 23,"
+ + " \"stored_fields_memory_in_bytes\": 24,"
+ + " \"term_vectors_memory_in_bytes\": 25,"
+ + " \"norms_memory_in_bytes\": 26,"
+ + " \"points_memory_in_bytes\": 27,"
+ + " \"doc_values_memory_in_bytes\": 28,"
+ + " \"index_writer_memory_in_bytes\": 29,"
+ + " \"version_map_memory_in_bytes\": 30,"
+ + " \"fixed_bit_set_memory_in_bytes\": 31"
+ + " },"
+ + " \"request_cache\": {"
+ + " \"memory_size_in_bytes\": 9,"
+ + " \"evictions\": 10,"
+ + " \"hit_count\": 11,"
+ + " \"miss_count\": 12"
+ + " }"
+ + " }"
+ + " }"
+ + "}", indexStatsSummary()));
+ assertThat(xContent.utf8ToString(), equalTo(expected));
}
public void testToXContentWithNullStats() throws IOException {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndicesStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndicesStatsMonitoringDocTests.java
index e7408557ec72d..7e85f32eb474f 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndicesStatsMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndicesStatsMonitoringDocTests.java
@@ -85,60 +85,63 @@ public void testToXContent() throws IOException {
new IndicesStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, indicesStats);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"indices_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"indices_stats\":{"
- + "\"_all\":{"
- + "\"primaries\":{"
- + "\"docs\":{"
- + "\"count\":2"
- + "},"
- + "\"store\":{"
- + "\"size_in_bytes\":4"
- + "},"
- + "\"indexing\":{"
- + "\"index_total\":6,"
- + "\"index_time_in_millis\":8,"
- + "\"is_throttled\":true,"
- + "\"throttle_time_in_millis\":10"
- + "},"
- + "\"search\":{"
- + "\"query_total\":12,"
- + "\"query_time_in_millis\":14"
- + "}"
- + "},"
- + "\"total\":{"
- + "\"docs\":{"
- + "\"count\":3"
- + "},"
- + "\"store\":{"
- + "\"size_in_bytes\":6"
- + "},"
- + "\"indexing\":{"
- + "\"index_total\":9,"
- + "\"index_time_in_millis\":12,"
- + "\"is_throttled\":true,"
- + "\"throttle_time_in_millis\":15"
- + "},"
- + "\"search\":{"
- + "\"query_total\":18,"
- + "\"query_time_in_millis\":21"
- + "}"
- + "}"
- + "}"
+ final String expected = XContentHelper.reformatJson(
+ "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-09T08:18:59.402Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"indices_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"indices_stats\": {"
+ + " \"_all\": {"
+ + " \"primaries\": {"
+ + " \"docs\": {"
+ + " \"count\": 2"
+ + " },"
+ + " \"store\": {"
+ + " \"size_in_bytes\": 4"
+ + " },"
+ + " \"indexing\": {"
+ + " \"index_total\": 6,"
+ + " \"index_time_in_millis\": 8,"
+ + " \"is_throttled\": true,"
+ + " \"throttle_time_in_millis\": 10"
+ + " },"
+ + " \"search\": {"
+ + " \"query_total\": 12,"
+ + " \"query_time_in_millis\": 14"
+ + " }"
+ + " },"
+ + " \"total\": {"
+ + " \"docs\": {"
+ + " \"count\": 3"
+ + " },"
+ + " \"store\": {"
+ + " \"size_in_bytes\": 6"
+ + " },"
+ + " \"indexing\": {"
+ + " \"index_total\": 9,"
+ + " \"index_time_in_millis\": 12,"
+ + " \"is_throttled\": true,"
+ + " \"throttle_time_in_millis\": 15"
+ + " },"
+ + " \"search\": {"
+ + " \"query_total\": 18,"
+ + " \"query_time_in_millis\": 21"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ "}"
- + "}", xContent.utf8ToString());
+ );
+ assertEquals(expected, xContent.utf8ToString());
}
private CommonStats mockCommonStats() {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java
index 23de6258b3fe0..7814034bdf7d1 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java
@@ -113,78 +113,82 @@ public void testToXContent() throws IOException {
final JobStatsMonitoringDoc document = new JobStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, jobStats);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"job_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"job_stats\":{"
- + "\"job_id\":\"_job\","
- + "\"data_counts\":{"
- + "\"job_id\":\"_job_id\","
- + "\"processed_record_count\":0,"
- + "\"processed_field_count\":1,"
- + "\"input_bytes\":2,"
- + "\"input_field_count\":3,"
- + "\"invalid_date_count\":4,"
- + "\"missing_field_count\":5,"
- + "\"out_of_order_timestamp_count\":6,"
- + "\"empty_bucket_count\":7,"
- + "\"sparse_bucket_count\":8,"
- + "\"bucket_count\":9,"
- + "\"earliest_record_timestamp\":1483401783003,"
- + "\"latest_record_timestamp\":1483488244004,"
- + "\"last_data_time\":1483574705005,"
- + "\"latest_empty_bucket_timestamp\":1483661166006,"
- + "\"latest_sparse_bucket_timestamp\":1483747627007,"
- + "\"input_record_count\":10"
- + "},"
- + "\"model_size_stats\":{"
- + "\"job_id\":\"_model\","
- + "\"result_type\":\"model_size_stats\","
- + "\"model_bytes\":100,"
- + "\"total_by_field_count\":101,"
- + "\"total_over_field_count\":102,"
- + "\"total_partition_field_count\":103,"
- + "\"bucket_allocation_failures_count\":104,"
- + "\"memory_status\":\"ok\","
- + "\"log_time\":1483315322002,"
- + "\"timestamp\":1483228861001"
- + "},"
- + "\"forecasts_stats\":{"
- + "\"total\":0,\"forecasted_jobs\":0"
- + "},"
- + "\"state\":\"opened\","
- + "\"node\":{"
- + "\"id\":\"_node_id\","
- + "\"name\":\"_node_name\","
- + "\"ephemeral_id\":\"_ephemeral_id\","
- + "\"transport_address\":\"0.0.0.0:9300\","
- + "\"attributes\":{"
- + "\"attr\":\"value\""
- + "}"
- + "},"
- + "\"assignment_explanation\":\"_explanation\","
- + "\"open_time\":\"13h\","
- + "\"timing_stats\":{"
- + "\"job_id\":\"_job_id\","
- + "\"bucket_count\":100,"
- + "\"total_bucket_processing_time_ms\":2000.0,"
- + "\"minimum_bucket_processing_time_ms\":10.0,"
- + "\"maximum_bucket_processing_time_ms\":30.0,"
- + "\"average_bucket_processing_time_ms\":20.0,"
- + "\"exponential_average_bucket_processing_time_ms\":25.0,"
- + "\"exponential_average_bucket_processing_time_per_hour_ms\":50.0"
- + "}"
- + "}"
- + "}", xContent.utf8ToString());
+ final String expected = XContentHelper.reformatJson(
+ "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-09T08:18:59.402Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"job_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"job_stats\": {"
+ + " \"job_id\": \"_job\","
+ + " \"data_counts\": {"
+ + " \"job_id\": \"_job_id\","
+ + " \"processed_record_count\": 0,"
+ + " \"processed_field_count\": 1,"
+ + " \"input_bytes\": 2,"
+ + " \"input_field_count\": 3,"
+ + " \"invalid_date_count\": 4,"
+ + " \"missing_field_count\": 5,"
+ + " \"out_of_order_timestamp_count\": 6,"
+ + " \"empty_bucket_count\": 7,"
+ + " \"sparse_bucket_count\": 8,"
+ + " \"bucket_count\": 9,"
+ + " \"earliest_record_timestamp\": 1483401783003,"
+ + " \"latest_record_timestamp\": 1483488244004,"
+ + " \"last_data_time\": 1483574705005,"
+ + " \"latest_empty_bucket_timestamp\": 1483661166006,"
+ + " \"latest_sparse_bucket_timestamp\": 1483747627007,"
+ + " \"input_record_count\": 10"
+ + " },"
+ + " \"model_size_stats\": {"
+ + " \"job_id\": \"_model\","
+ + " \"result_type\": \"model_size_stats\","
+ + " \"model_bytes\": 100,"
+ + " \"total_by_field_count\": 101,"
+ + " \"total_over_field_count\": 102,"
+ + " \"total_partition_field_count\": 103,"
+ + " \"bucket_allocation_failures_count\": 104,"
+ + " \"memory_status\": \"ok\","
+ + " \"log_time\": 1483315322002,"
+ + " \"timestamp\": 1483228861001"
+ + " },"
+ + " \"forecasts_stats\": {"
+ + " \"total\": 0,"
+ + " \"forecasted_jobs\": 0"
+ + " },"
+ + " \"state\": \"opened\","
+ + " \"node\": {"
+ + " \"id\": \"_node_id\","
+ + " \"name\": \"_node_name\","
+ + " \"ephemeral_id\": \"_ephemeral_id\","
+ + " \"transport_address\": \"0.0.0.0:9300\","
+ + " \"attributes\": {"
+ + " \"attr\": \"value\""
+ + " }"
+ + " },"
+ + " \"assignment_explanation\": \"_explanation\","
+ + " \"open_time\": \"13h\","
+ + " \"timing_stats\": {"
+ + " \"job_id\": \"_job_id\","
+ + " \"bucket_count\": 100,"
+ + " \"total_bucket_processing_time_ms\": 2000.0,"
+ + " \"minimum_bucket_processing_time_ms\": 10.0,"
+ + " \"maximum_bucket_processing_time_ms\": 30.0,"
+ + " \"average_bucket_processing_time_ms\": 20.0,"
+ + " \"exponential_average_bucket_processing_time_ms\": 25.0,"
+ + " \"exponential_average_bucket_processing_time_per_hour_ms\": 50.0"
+ + " }"
+ + " }"
+ + "}"
+ );
+ assertEquals(expected, xContent.utf8ToString());
}
}
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java
index 425f1046ac82b..59fbf1cb07f1d 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java
@@ -105,175 +105,178 @@ public void testToXContent() throws IOException {
new NodeStatsMonitoringDoc("_cluster", 1502107402133L, 1506593717631L, node, "_node_id", true, nodeStats, false);
final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"node_stats\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"node_stats\":{"
- + "\"node_id\":\"_node_id\","
- + "\"node_master\":true,"
- + "\"mlockall\":false,"
- + "\"indices\":{"
- + "\"docs\":{"
- + "\"count\":1"
- + "},"
- + "\"store\":{"
- + "\"size_in_bytes\":4"
- + "},"
- + "\"indexing\":{"
- + "\"index_total\":5,"
- + "\"index_time_in_millis\":6,"
- + "\"throttle_time_in_millis\":8"
- + "},"
- + "\"search\":{"
- + "\"query_total\":17,"
- + "\"query_time_in_millis\":18"
- + "},"
- + "\"query_cache\":{"
- + "\"memory_size_in_bytes\":9,"
- + "\"hit_count\":10,"
- + "\"miss_count\":11,"
- + "\"evictions\":13"
- + "},"
- + "\"fielddata\":{"
- + "\"memory_size_in_bytes\":2,"
- + "\"evictions\":3"
- + "},"
- + "\"segments\":{"
- + "\"count\":19,"
- + "\"memory_in_bytes\":20,"
- + "\"terms_memory_in_bytes\":21,"
- + "\"stored_fields_memory_in_bytes\":22,"
- + "\"term_vectors_memory_in_bytes\":23,"
- + "\"norms_memory_in_bytes\":24,"
- + "\"points_memory_in_bytes\":25,"
- + "\"doc_values_memory_in_bytes\":26,"
- + "\"index_writer_memory_in_bytes\":27,"
- + "\"version_map_memory_in_bytes\":28,"
- + "\"fixed_bit_set_memory_in_bytes\":29"
- + "},"
- + "\"request_cache\":{"
- + "\"memory_size_in_bytes\":13,"
- + "\"evictions\":14,"
- + "\"hit_count\":15,"
- + "\"miss_count\":16"
- + "}"
- + "},"
- + "\"os\":{"
- + "\"cpu\":{"
- + "\"load_average\":{"
- + "\"1m\":41.0,"
- + "\"5m\":42.0,"
- + "\"15m\":43.0"
- + "}"
- + "},"
- + "\"cgroup\":{"
- + "\"cpuacct\":{"
- + "\"control_group\":\"_cpu_acct_ctrl_group\","
- + "\"usage_nanos\":47"
- + "},"
- + "\"cpu\":{"
- + "\"control_group\":\"_cpu_ctrl_group\","
- + "\"cfs_period_micros\":48,"
- + "\"cfs_quota_micros\":49,"
- + "\"stat\":{"
- + "\"number_of_elapsed_periods\":44,"
- + "\"number_of_times_throttled\":45,"
- + "\"time_throttled_nanos\":46"
- + "}"
- + "},"
- + "\"memory\":{"
- + "\"control_group\":\"_memory_ctrl_group\","
- + "\"limit_in_bytes\":\"2000000000\","
- + "\"usage_in_bytes\":\"1000000000\""
- + "}"
- + "}"
- + "},"
- + "\"process\":{"
- + "\"open_file_descriptors\":51,"
- + "\"max_file_descriptors\":52,"
- + "\"cpu\":{"
- + "\"percent\":50"
- + "}"
- + "},"
- + "\"jvm\":{"
- + "\"mem\":{"
- + "\"heap_used_in_bytes\":53,"
- + "\"heap_used_percent\":98,"
- + "\"heap_max_in_bytes\":54"
- + "},"
- + "\"gc\":{"
- + "\"collectors\":{"
- + "\"young\":{"
- + "\"collection_count\":55,"
- + "\"collection_time_in_millis\":56"
- + "},"
- + "\"old\":{"
- + "\"collection_count\":57,"
- + "\"collection_time_in_millis\":58"
- + "}"
- + "}"
- + "}"
- + "},"
- + "\"thread_pool\":{"
- + "\"generic\":{"
- + "\"threads\":59,"
- + "\"queue\":60,"
- + "\"rejected\":61"
- + "},"
- + "\"get\":{"
- + "\"threads\":62,"
- + "\"queue\":63,"
- + "\"rejected\":64"
- + "},"
- + "\"management\":{"
- + "\"threads\":65,"
- + "\"queue\":66,"
- + "\"rejected\":67"
- + "},"
- + "\"search\":{"
- + "\"threads\":68,"
- + "\"queue\":69,"
- + "\"rejected\":70"
- + "},"
- + "\"watcher\":{"
- + "\"threads\":71,"
- + "\"queue\":72,"
- + "\"rejected\":73"
- + "},"
- + "\"write\":{"
- + "\"threads\":74,"
- + "\"queue\":75,"
- + "\"rejected\":76"
- + "}"
- + "},"
- + "\"fs\":{"
- + "\"total\":{"
- + "\"total_in_bytes\":38,"
- + "\"free_in_bytes\":39,"
- + "\"available_in_bytes\":40"
- + "},"
- + "\"io_stats\":{"
- + "\"total\":{"
- + "\"operations\":8,"
- + "\"read_operations\":4,"
- + "\"write_operations\":4,"
- + "\"read_kilobytes\":2,"
- + "\"write_kilobytes\":2"
- + "}"
- + "}"
- + "}"
- + "}"
- + "}", xContent.utf8ToString());
+ final String expected = XContentHelper.reformatJson(
+ "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-07T12:03:22.133Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"node_stats\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"node_stats\": {"
+ + " \"node_id\": \"_node_id\","
+ + " \"node_master\": true,"
+ + " \"mlockall\": false,"
+ + " \"indices\": {"
+ + " \"docs\": {"
+ + " \"count\": 1"
+ + " },"
+ + " \"store\": {"
+ + " \"size_in_bytes\": 4"
+ + " },"
+ + " \"indexing\": {"
+ + " \"index_total\": 5,"
+ + " \"index_time_in_millis\": 6,"
+ + " \"throttle_time_in_millis\": 8"
+ + " },"
+ + " \"search\": {"
+ + " \"query_total\": 17,"
+ + " \"query_time_in_millis\": 18"
+ + " },"
+ + " \"query_cache\": {"
+ + " \"memory_size_in_bytes\": 9,"
+ + " \"hit_count\": 10,"
+ + " \"miss_count\": 11,"
+ + " \"evictions\": 13"
+ + " },"
+ + " \"fielddata\": {"
+ + " \"memory_size_in_bytes\": 2,"
+ + " \"evictions\": 3"
+ + " },"
+ + " \"segments\": {"
+ + " \"count\": 19,"
+ + " \"memory_in_bytes\": 20,"
+ + " \"terms_memory_in_bytes\": 21,"
+ + " \"stored_fields_memory_in_bytes\": 22,"
+ + " \"term_vectors_memory_in_bytes\": 23,"
+ + " \"norms_memory_in_bytes\": 24,"
+ + " \"points_memory_in_bytes\": 25,"
+ + " \"doc_values_memory_in_bytes\": 26,"
+ + " \"index_writer_memory_in_bytes\": 27,"
+ + " \"version_map_memory_in_bytes\": 28,"
+ + " \"fixed_bit_set_memory_in_bytes\": 29"
+ + " },"
+ + " \"request_cache\": {"
+ + " \"memory_size_in_bytes\": 13,"
+ + " \"evictions\": 14,"
+ + " \"hit_count\": 15,"
+ + " \"miss_count\": 16"
+ + " }"
+ + " },"
+ + " \"os\": {"
+ + " \"cpu\": {"
+ + " \"load_average\": {"
+ + " \"1m\": 41.0,"
+ + " \"5m\": 42.0,"
+ + " \"15m\": 43.0"
+ + " }"
+ + " },"
+ + " \"cgroup\": {"
+ + " \"cpuacct\": {"
+ + " \"control_group\": \"_cpu_acct_ctrl_group\","
+ + " \"usage_nanos\": 47"
+ + " },"
+ + " \"cpu\": {"
+ + " \"control_group\": \"_cpu_ctrl_group\","
+ + " \"cfs_period_micros\": 48,"
+ + " \"cfs_quota_micros\": 49,"
+ + " \"stat\": {"
+ + " \"number_of_elapsed_periods\": 44,"
+ + " \"number_of_times_throttled\": 45,"
+ + " \"time_throttled_nanos\": 46"
+ + " }"
+ + " },"
+ + " \"memory\": {"
+ + " \"control_group\": \"_memory_ctrl_group\","
+ + " \"limit_in_bytes\": \"2000000000\","
+ + " \"usage_in_bytes\": \"1000000000\""
+ + " }"
+ + " }"
+ + " },"
+ + " \"process\": {"
+ + " \"open_file_descriptors\": 51,"
+ + " \"max_file_descriptors\": 52,"
+ + " \"cpu\": {"
+ + " \"percent\": 50"
+ + " }"
+ + " },"
+ + " \"jvm\": {"
+ + " \"mem\": {"
+ + " \"heap_used_in_bytes\": 53,"
+ + " \"heap_used_percent\": 98,"
+ + " \"heap_max_in_bytes\": 54"
+ + " },"
+ + " \"gc\": {"
+ + " \"collectors\": {"
+ + " \"young\": {"
+ + " \"collection_count\": 55,"
+ + " \"collection_time_in_millis\": 56"
+ + " },"
+ + " \"old\": {"
+ + " \"collection_count\": 57,"
+ + " \"collection_time_in_millis\": 58"
+ + " }"
+ + " }"
+ + " }"
+ + " },"
+ + " \"thread_pool\": {"
+ + " \"generic\": {"
+ + " \"threads\": 59,"
+ + " \"queue\": 60,"
+ + " \"rejected\": 61"
+ + " },"
+ + " \"get\": {"
+ + " \"threads\": 62,"
+ + " \"queue\": 63,"
+ + " \"rejected\": 64"
+ + " },"
+ + " \"management\": {"
+ + " \"threads\": 65,"
+ + " \"queue\": 66,"
+ + " \"rejected\": 67"
+ + " },"
+ + " \"search\": {"
+ + " \"threads\": 68,"
+ + " \"queue\": 69,"
+ + " \"rejected\": 70"
+ + " },"
+ + " \"watcher\": {"
+ + " \"threads\": 71,"
+ + " \"queue\": 72,"
+ + " \"rejected\": 73"
+ + " },"
+ + " \"write\": {"
+ + " \"threads\": 74,"
+ + " \"queue\": 75,"
+ + " \"rejected\": 76"
+ + " }"
+ + " },"
+ + " \"fs\": {"
+ + " \"total\": {"
+ + " \"total_in_bytes\": 38,"
+ + " \"free_in_bytes\": 39,"
+ + " \"available_in_bytes\": 40"
+ + " },"
+ + " \"io_stats\": {"
+ + " \"total\": {"
+ + " \"operations\": 8,"
+ + " \"read_operations\": 4,"
+ + " \"write_operations\": 4,"
+ + " \"read_kilobytes\": 2,"
+ + " \"write_kilobytes\": 2"
+ + " }"
+ + " }"
+ + " }"
+ + " }"
+ + "}"
+ );
+ assertEquals(expected, xContent.utf8ToString());
}
private static NodeStats mockNodeStats() {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsMonitoringDocTests.java
index ccec3421cd926..6a567d8052d59 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsMonitoringDocTests.java
@@ -107,28 +107,29 @@ public void testToXContent() throws IOException {
new ShardMonitoringDoc("_cluster", 1502107402133L, 1506593717631L, node, shardRouting, "_state_uuid");
final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, randomBoolean());
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"shards\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"state_uuid\":\"_state_uuid\","
- + "\"shard\":{"
- + "\"state\":\"INITIALIZING\","
- + "\"primary\":true,"
- + "\"node\":\"_index_uuid\","
- + "\"relocating_node\":\"_node_uuid\","
- + "\"shard\":1,"
- + "\"index\":\"_index\""
- + "}"
- + "}" , xContent.utf8ToString());
+ final String expected = "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-07T12:03:22.133Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"shards\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"state_uuid\": \"_state_uuid\","
+ + " \"shard\": {"
+ + " \"state\": \"INITIALIZING\","
+ + " \"primary\": true,"
+ + " \"node\": \"_index_uuid\","
+ + " \"relocating_node\": \"_node_uuid\","
+ + " \"shard\": 1,"
+ + " \"index\": \"_index\""
+ + " }"
+ + "}";
+ assertEquals(XContentHelper.reformatJson(expected), xContent.utf8ToString());
}
}
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BaseFilteredMonitoringDocTestCase.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BaseFilteredMonitoringDocTestCase.java
index d81467677091a..d4d18a0738a1d 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BaseFilteredMonitoringDocTestCase.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BaseFilteredMonitoringDocTestCase.java
@@ -80,29 +80,32 @@ public void testFilteredMonitoringDocToXContent() throws IOException {
node, MonitoredSystem.ES, "_type", "_id", filters);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"_type\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"_type\":{"
- + "\"field_1\":1,"
- + "\"field_3\":{"
- + "\"sub_field_3\":3"
- + "},"
- + "\"field_5\":["
- + "{\"sub_field_5\":5}"
- + "]"
- + "}"
- + "}", xContent.utf8ToString());
+ final String expected = "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-09T08:18:59.402Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"_type\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"_type\": {"
+ + " \"field_1\": 1,"
+ + " \"field_3\": {"
+ + " \"sub_field_3\": 3"
+ + " },"
+ + " \"field_5\": ["
+ + " {"
+ + " \"sub_field_5\": 5"
+ + " }"
+ + " ]"
+ + " }"
+ + "}";
+ assertEquals(XContentHelper.reformatJson(expected), xContent.utf8ToString());
}
class TestFilteredMonitoringDoc extends FilteredMonitoringDoc {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BytesReferenceMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BytesReferenceMonitoringDocTests.java
index 68e5c5b657b5c..9afc6324a7532 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BytesReferenceMonitoringDocTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/BytesReferenceMonitoringDocTests.java
@@ -91,23 +91,24 @@ public void testToXContent() throws IOException {
node, KIBANA, "_type", "_id", xContentType, BytesReference.bytes(builder));
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
- assertEquals("{"
- + "\"cluster_uuid\":\"_cluster\","
- + "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
- + "\"interval_ms\":1506593717631,"
- + "\"type\":\"_type\","
- + "\"source_node\":{"
- + "\"uuid\":\"_uuid\","
- + "\"host\":\"_host\","
- + "\"transport_address\":\"_addr\","
- + "\"ip\":\"_ip\","
- + "\"name\":\"_name\","
- + "\"timestamp\":\"2017-08-31T08:46:30.855Z\""
- + "},"
- + "\"_type\":{"
- + "\"field\":\"value\""
- + "}"
- + "}", xContent.utf8ToString());
+ final String expected = "{"
+ + " \"cluster_uuid\": \"_cluster\","
+ + " \"timestamp\": \"2017-08-09T08:18:59.402Z\","
+ + " \"interval_ms\": 1506593717631,"
+ + " \"type\": \"_type\","
+ + " \"source_node\": {"
+ + " \"uuid\": \"_uuid\","
+ + " \"host\": \"_host\","
+ + " \"transport_address\": \"_addr\","
+ + " \"ip\": \"_ip\","
+ + " \"name\": \"_name\","
+ + " \"timestamp\": \"2017-08-31T08:46:30.855Z\""
+ + " },"
+ + " \"_type\": {"
+ + " \"field\": \"value\""
+ + " }"
+ + "}";
+ assertEquals(XContentHelper.reformatJson(expected), xContent.utf8ToString());
}
public void testEqualsAndHashcode() {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulkResponseListenerTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulkResponseListenerTests.java
index 5c5d0daa8086b..e915e35b51fd1 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulkResponseListenerTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulkResponseListenerTests.java
@@ -112,26 +112,29 @@ public void testOnSuccessParsingWithInnerErrors() throws IOException {
when(xContent.createParser(Mockito.any(NamedXContentRegistry.class),
Mockito.any(DeprecationHandler.class), Mockito.eq(stream))).thenReturn(parser);
- // {, "took", 4, "errors", false nextToken, currentName
- when(parser.nextToken()).thenReturn(Token.START_OBJECT, // 1
- Token.FIELD_NAME, Token.VALUE_NUMBER, // 3, 1
- Token.FIELD_NAME, Token.VALUE_BOOLEAN, // 5, 2
- Token.FIELD_NAME, Token.START_ARRAY, // 7, 3
- // no error:
- Token.START_OBJECT, // 8
- Token.FIELD_NAME, Token.START_OBJECT, // 10, 4
- Token.FIELD_NAME, Token.VALUE_STRING, // 12, 5
- Token.FIELD_NAME, Token.VALUE_STRING, // 14, 6
- Token.FIELD_NAME, Token.VALUE_STRING, // 16, 7
- Token.END_OBJECT, // 17
- Token.START_OBJECT, // 18
- Token.FIELD_NAME, Token.START_OBJECT, // 20, 8
- Token.FIELD_NAME, Token.VALUE_STRING, // 22, 9
- Token.FIELD_NAME, Token.VALUE_STRING, // 24, 10
- Token.FIELD_NAME, Token.VALUE_STRING, // 26, 11
- Token.FIELD_NAME, Token.VALUE_STRING, // 28, 12 ("error")
- Token.END_OBJECT, // 29
- Token.END_ARRAY); // 30
+ // tag::disable-formatting
+ // {, "took", 4, "errors", false
+ when(parser.nextToken()).thenReturn( // nextToken, currentName
+ Token.START_OBJECT, // 1
+ Token.FIELD_NAME, Token.VALUE_NUMBER, // 3, 1
+ Token.FIELD_NAME, Token.VALUE_BOOLEAN, // 5, 2
+ Token.FIELD_NAME, Token.START_ARRAY, // 7, 3
+ // no error:
+ Token.START_OBJECT, // 8
+ Token.FIELD_NAME, Token.START_OBJECT, // 10, 4
+ Token.FIELD_NAME, Token.VALUE_STRING, // 12, 5
+ Token.FIELD_NAME, Token.VALUE_STRING, // 14, 6
+ Token.FIELD_NAME, Token.VALUE_STRING, // 16, 7
+ Token.END_OBJECT, // 17
+ Token.START_OBJECT, // 18
+ Token.FIELD_NAME, Token.START_OBJECT, // 20, 8
+ Token.FIELD_NAME, Token.VALUE_STRING, // 22, 9
+ Token.FIELD_NAME, Token.VALUE_STRING, // 24, 10
+ Token.FIELD_NAME, Token.VALUE_STRING, // 26, 11
+ Token.FIELD_NAME, Token.VALUE_STRING, // 28, 12 ("error")
+ Token.END_OBJECT, // 29
+ Token.END_ARRAY); // 30
+ // end::disable-formatting
when(parser.currentName()).thenReturn("took", "errors", "items",
"index", "_index", "_type", "_id",
"index", "_index", "_type", "_id", "error");
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java
index 1bed5f1c7fff9..4b75a6a075f4d 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java
@@ -769,8 +769,8 @@ private void enqueueWatcherResponses(final MockWebServer webServer,
} else {
enqueueClusterAlertResponsesDoesNotExistYet(webServer);
}
- // otherwise we need to delete them from the remote cluster
} else {
+ // otherwise we need to delete them from the remote cluster
enqueueDeleteClusterAlertResponses(webServer);
}
} else {
@@ -783,8 +783,8 @@ private void enqueueWatcherResponses(final MockWebServer webServer,
);
enqueueResponse(webServer, 200, responseBody);
- // X-Pack is not installed
} else {
+ // X-Pack is not installed
enqueueResponse(webServer, 404, "{}");
}
}
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java
index e6f896a2aa050..c0804ad2060b5 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java
@@ -383,8 +383,8 @@ public void testWatchCheckBlocksAfterSuccessfulWatcherCheck() {
// +1 for the "first"
expectedGets += 1 + successful + unsuccessful;
expectedPuts = (successfulFirst ? 0 : 1) + unsuccessful;
- // deleting watches
} else {
+ // deleting watches
// - 1 from necessary failure after it!
final int successful = randomIntBetween(1, EXPECTED_WATCHES - 1);
diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java
index 9f8e26d425f5d..0009a74886776 100644
--- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java
+++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java
@@ -561,7 +561,8 @@ public void testTimezone() throws IOException {
= new DateHistogramValuesSourceBuilder("the_histo." + DateHistogramAggregationBuilder.NAME)
.field(timestampField)
.calendarInterval(new DateHistogramInterval("1d"))
- .timeZone(ZoneId.of("-01:00", ZoneId.SHORT_IDS)); // adds a timezone so that we aren't on default UTC
+ // adds a timezone so that we aren't on default UTC
+ .timeZone(ZoneId.of("-01:00", ZoneId.SHORT_IDS));
CompositeAggregationBuilder compositeBuilder = new CompositeAggregationBuilder(RollupIndexer.AGGREGATION_NAME,
singletonList(dateHisto));
diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java
index 773272548dda1..824030beb49d9 100644
--- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java
+++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java
@@ -21,6 +21,7 @@
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.util.NamedFormatter;
import org.elasticsearch.test.MockLogAppender;
import org.elasticsearch.xpack.core.watcher.watch.ClockMock;
import org.hamcrest.Matchers;
@@ -209,13 +210,30 @@ public void testParseEmptyContentIsRejected() throws Exception {
public void testParseContentWithNoAssertionsIsRejected() throws Exception {
Instant now = clock.instant();
- SamlToken token = token("\n" +
- "" +
- "" +
- IDP_ENTITY_ID + "" +
- "" +
- "");
+ final String xml = "\n"
+ + ""
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("now", now);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+
+ SamlToken token = token(NamedFormatter.format(xml, replacements));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("No assertions found in SAML response"));
assertThat(exception.getCause(), nullValue());
@@ -227,38 +245,57 @@ public void testSuccessfullyParseContentWithASingleValidAssertion() throws Excep
Instant validUntil = now.plusSeconds(30);
final String nameId = randomAlphaOfLengthBetween(12, 24);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" + nameId + "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " %(nameId)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("nameId", nameId);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final SamlAttributes attributes = authenticator.authenticate(token);
assertThat(attributes, notNullValue());
assertThat(attributes.attributes(), iterableWithSize(1));
@@ -409,38 +446,54 @@ public void testIncorrectResponseIssuerIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "xxx" + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)xxx"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("Issuer"));
assertThat(exception.getCause(), nullValue());
@@ -451,38 +504,54 @@ public void testIncorrectAssertionIssuerIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "_" + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)_"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("Issuer"));
assertThat(exception.getCause(), nullValue());
@@ -493,38 +562,61 @@ public void testIncorrectDestinationIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = randomBoolean() ? token(signDoc(xml)) : token(signAssertions(xml, idpSigningCertificatePair));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ final String xmlWithReplacements = NamedFormatter.format(xml, replacements);
+
+ SamlToken token = randomBoolean()
+ ? token(signDoc(xmlWithReplacements))
+ : token(signAssertions(xmlWithReplacements, idpSigningCertificatePair));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("destination"));
assertThat(exception.getCause(), nullValue());
@@ -535,38 +627,54 @@ public void testMissingDestinationIsNotRejectedForNotSignedResponse() throws Exc
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signAssertions(xml, idpSigningCertificatePair));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signAssertions(NamedFormatter.format(xml, replacements), idpSigningCertificatePair));
final SamlAttributes attributes = authenticator.authenticate(token);
assertThat(attributes, notNullValue());
assertThat(attributes.attributes(), iterableWithSize(1));
@@ -582,38 +690,58 @@ public void testIncorrectRequestIdIsRejected() throws Exception {
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
final String incorrectId = "_012345";
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("incorrectId", incorrectId);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("in-response-to"));
assertThat(exception.getMessage(), containsString(requestId));
@@ -626,38 +754,60 @@ public void testIncorrectRecipientIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("SAML Assertion SubjectConfirmationData Recipient"));
assertThat(exception.getMessage(), containsString(SP_ACS_URL + "/fake"));
@@ -667,25 +817,45 @@ public void testIncorrectRecipientIsRejected() throws Exception {
public void testAssertionWithoutSubjectIsRejected() throws Exception {
Instant now = clock.instant();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("randomId2", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("has no Subject"));
assertThat(exception.getCause(), nullValue());
@@ -695,32 +865,52 @@ public void testAssertionWithoutSubjectIsRejected() throws Exception {
public void testAssertionWithoutAuthnStatementIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("randomId2", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("Authn Statements while exactly one was expected."));
assertThat(exception.getCause(), nullValue());
@@ -733,39 +923,59 @@ public void testExpiredAuthnStatementSessionIsRejected() throws Exception {
Instant sessionValidUntil = now.plusSeconds(60);
final String nameId = randomAlphaOfLengthBetween(12, 24);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" + nameId + "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " %(nameId)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("nameId", nameId);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("sessionValidUntil", sessionValidUntil);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
// check that the content is valid "now"
- final SamlToken token = token(signDoc(xml));
+ final SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
assertThat(authenticator.authenticate(token), notNullValue());
// and still valid if we advance partway through the session expiry time
@@ -790,40 +1000,59 @@ public void testIncorrectAuthnContextClassRefIsRejected() throws Exception {
Instant validUntil = now.plusSeconds(30);
final String nameId = randomAlphaOfLengthBetween(12, 24);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" + nameId + "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " %(nameId)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("nameId", nameId);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
SamlAuthenticator authenticatorWithReqAuthnCtx = buildAuthenticator(() -> buildOpenSamlCredential(idpSigningCertificatePair),
Arrays.asList(X509_AUTHN_CTX, KERBEROS_AUTHN_CTX));
- SamlToken token = token(signDoc(xml));
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticatorWithReqAuthnCtx.authenticate(token));
assertThat(exception.getMessage(), containsString("Rejecting SAML assertion as the AuthnContextClassRef"));
assertThat(SamlUtils.isSamlException(exception), is(true));
@@ -831,28 +1060,46 @@ public void testIncorrectAuthnContextClassRefIsRejected() throws Exception {
public void testAssertionWithoutSubjectConfirmationIsRejected() throws Exception {
Instant now = clock.instant();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("now", now);
+ replacements.put("randomId", randomId());
+ replacements.put("randomId2", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("SAML Assertion subject contains 0 bearer SubjectConfirmation"));
assertThat(exception.getCause(), nullValue());
@@ -861,29 +1108,48 @@ public void testAssertionWithoutSubjectConfirmationIsRejected() throws Exception
public void testAssertionWithoutSubjectConfirmationDataIsRejected() throws Exception {
Instant now = clock.instant();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("randomId", randomId());
+ replacements.put("randomId2", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("bearer SubjectConfirmation, while exactly one was expected."));
assertThat(exception.getCause(), nullValue());
@@ -894,38 +1160,57 @@ public void testAssetionWithoutBearerSubjectConfirmationMethodIsRejected() throw
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_ATTRIB_NAME", METHOD_ATTRIB_NAME);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("bearer SubjectConfirmation, while exactly one was expected."));
assertThat(exception.getCause(), nullValue());
@@ -937,38 +1222,61 @@ public void testIncorrectSubjectConfirmationDataInResponseToIsRejected() throws
Instant validUntil = now.plusSeconds(30);
final String incorrectId = "_123456";
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("incorrectId", incorrectId);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("SAML Assertion SubjectConfirmationData is in-response-to"));
assertThat(exception.getMessage(), containsString(requestId));
@@ -981,40 +1289,58 @@ public void testExpiredSubjectConfirmationDataIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(120);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
// check that the content is valid "now"
- final SamlToken token = token(signDoc(xml));
+ final SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
assertThat(authenticator.authenticate(token), notNullValue());
// and still valid if we advance partway through the expiry time
@@ -1043,37 +1369,56 @@ public void testIdpInitiatedLoginIsAllowed() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
- final SamlToken token = token(signDoc(xml));
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ final SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
final SamlAttributes attributes = authenticator.authenticate(token);
assertThat(attributes, notNullValue());
assertThat(attributes.attributes(), iterableWithSize(1));
@@ -1084,45 +1429,67 @@ public void testIncorrectSigningKeyIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ final String xmlWithReplacements = NamedFormatter.format(xml, replacements);
// check that the content is valid when signed by the correct key-pair
- assertThat(authenticator.authenticate(token(signer.transform(xml, idpSigningCertificatePair))), notNullValue());
+ assertThat(authenticator.authenticate(token(signer.transform(xmlWithReplacements, idpSigningCertificatePair))), notNullValue());
// check is rejected when signed by a different key-pair
final Tuple wrongKey = readKeyPair("RSA_4096_updated");
- final ElasticsearchSecurityException exception = expectThrows(ElasticsearchSecurityException.class,
- () -> authenticator.authenticate(token(signer.transform(xml, wrongKey))));
+ final ElasticsearchSecurityException exception = expectThrows(
+ ElasticsearchSecurityException.class,
+ () -> authenticator.authenticate(token(signer.transform(xmlWithReplacements, wrongKey)))
+ );
assertThat(exception.getMessage(), containsString("SAML Signature"));
assertThat(exception.getMessage(), containsString("could not be validated"));
assertThat(exception.getCause(), nullValue());
@@ -1149,40 +1516,58 @@ public void testParsingRejectsTamperedContent() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
// check that the original signed content is valid
- final String signed = signer.transform(xml, idpSigningCertificatePair);
+ final String signed = signer.transform(NamedFormatter.format(xml, replacements), idpSigningCertificatePair);
assertThat(authenticator.authenticate(token(signed)), notNullValue());
// but altered content is rejected
@@ -1208,41 +1593,61 @@ public void testSigningWhenIdpHasMultipleKeys() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ final String xmlWithReplacements = NamedFormatter.format(xml, replacements);
// check that the content is valid when signed by the each of the key-pairs
for (Tuple key : keys) {
- assertThat(authenticator.authenticate(token(signer.transform(xml, key))), notNullValue());
+ assertThat(authenticator.authenticate(token(signer.transform(xmlWithReplacements, key))), notNullValue());
}
}
@@ -1305,41 +1710,59 @@ public void testExpiredContentIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(120);
final String sessionindex = randomId();
- final String xml = "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "randomopaquestring" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " randomopaquestring"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
// check that the content is valid "now"
- final SamlToken token = token(signDoc(xml));
+ final SamlToken token = token(signDoc(NamedFormatter.format(xml, replacements)));
assertThat(authenticator.authenticate(token), notNullValue());
// and still valid if we advance partway through the expiry time
@@ -2079,19 +2502,31 @@ private Response toResponse(String xml) throws SAXException, IOException, Parser
private String getStatusFailedResponse() {
final Instant now = clock.instant();
- return "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" +
- "";
+ final String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("now", now);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+
+ return NamedFormatter.format(xml, replacements);
}
private String getSimpleResponse(Instant now) {
@@ -2101,43 +2536,66 @@ private String getSimpleResponse(Instant now) {
private String getSimpleResponse(Instant now, String nameId, String sessionindex) {
Instant validUntil = now.plusSeconds(30);
- return "\n" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" +
- "" + IDP_ENTITY_ID + "" +
- "" +
- "" + nameId + "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" + PASSWORD_AUTHN_CTX + "" +
- "" +
- "" +
- "" +
- "daredevil" +
- "" +
- "" +
- "defenders" +
- "netflix" +
- "" +
- "" +
- "";
+ String xml = "\n"
+ + ""
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " "
+ + " %(IDP_ENTITY_ID)"
+ + " "
+ + " %(nameId)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(PASSWORD_AUTHN_CTX)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " daredevil"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " defenders"
+ + " netflix"
+ + " "
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("IDP_ENTITY_ID", IDP_ENTITY_ID);
+ replacements.put("METHOD_BEARER", METHOD_BEARER);
+ replacements.put("nameId", nameId);
+ replacements.put("now", now);
+ replacements.put("PASSWORD_AUTHN_CTX", PASSWORD_AUTHN_CTX);
+ replacements.put("randomId", randomId());
+ replacements.put("requestId", requestId);
+ replacements.put("sessionindex", sessionindex);
+ replacements.put("SP_ACS_URL", SP_ACS_URL);
+ replacements.put("SP_ENTITY_ID", SP_ENTITY_ID);
+ replacements.put("TRANSIENT", TRANSIENT);
+ replacements.put("validUntil", validUntil);
+
+ return NamedFormatter.format(xml, replacements);
}
private String getResponseWithAudienceRestrictions(String... requiredAudiences) {
diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlSpMetadataBuilderTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlSpMetadataBuilderTests.java
index 066de5cfa6092..58d86996dd7c4 100644
--- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlSpMetadataBuilderTests.java
+++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlSpMetadataBuilderTests.java
@@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.security.authc.saml;
+import org.elasticsearch.common.util.NamedFormatter;
import org.elasticsearch.xpack.core.ssl.CertParsingUtils;
import org.hamcrest.Matchers;
import org.junit.Before;
@@ -20,10 +21,14 @@
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.stream.Collectors;
+import static org.hamcrest.Matchers.equalTo;
+
public class SamlSpMetadataBuilderTests extends SamlTestCase {
private X509Certificate certificate;
@@ -67,7 +72,7 @@ public void testBuildMinimalistMetadata() throws Exception {
final Element element = new EntityDescriptorMarshaller().marshall(descriptor);
final String xml = SamlUtils.toString(element);
- assertThat(xml, Matchers.equalTo("" +
+ assertThat(xml, equalTo("" +
"" +
"" +
@@ -100,66 +105,87 @@ public void testBuildFullMetadata() throws Exception {
final Element element = new EntityDescriptorMarshaller().marshall(descriptor);
final String xml = SamlUtils.toString(element);
- assertThat(xml, Matchers.equalTo("" +
- "" +
- "" +
- "" +
- "" +
- "MIIDWDCCAkCgAwIBAgIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA0GCSqGSIb3DQEBCwUAMB0xGzAZ" + System.lineSeparator() +
- "BgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDAeFw0xNzExMjkwMjQ3MjZaFw0yMDExMjgwMjQ3MjZa" + System.lineSeparator() +
- "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC" + System.lineSeparator() +
- "AQoCggEBALHTuPGOieCbD2mZUdYrdH4ofo7qFze6rQUROCLKqf69uBuwvraNWOcwxHUTKVlLMV3d" + System.lineSeparator() +
- "dKzYo+yfC44AMXrrV+79xVWsTCNHu9sxQzcDwiEx2OtOOX9MAk6tJQ3svNrMPNXWh8ftwmmY9XdF" + System.lineSeparator() +
- "ZwMYUdo6FPjSQj5uQTDmGWRgF08f7VRlk6N92d/fzn9DlDm+TFuaOr17OTSR4B6RTrNwKC29AmXQ" + System.lineSeparator() +
- "TwCijCObjLqyMEqP20dZCQeVf2qw8JKUHhW4r6mCLzqmeR+kRTqiHMSWxJddzxDGw6X7fOS7iuzB" + System.lineSeparator() +
- "0+TnsKwgu8nYrEXds9MkGf1Yco7WsM43g+Es+LhNHP+es70CAwEAAaOBjjCBizAdBgNVHQ4EFgQU" + System.lineSeparator() +
- "ILqVKGhIi8p5Xffsow/IKFLhRbIwWQYDVR0jBFIwUIAUILqVKGhIi8p5Xffsow/IKFLhRbKhIaQf" + System.lineSeparator() +
- "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTIIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA8G" + System.lineSeparator() +
- "A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGhl4V9mp4SWSV2E3HAJ1PX+Vmp6k27K" + System.lineSeparator() +
- "d0tkOk1B9fyA13QB30teyiL7RR0vSHRyWFY8rQH1mHD366GKRWLITRG/QPULamGdYXX4h0pFj5ld" + System.lineSeparator() +
- "aubLxM/O9vEAxOgmo/lsdkeIq9tLBqY06r/5A/Mcgo63KGi00AFYBoyvqfOu6nRLPnQr+rKVfdNO" + System.lineSeparator() +
- "pWeIiFY1i2XTNZ3CZjNPSTwiQMUzrCxKXB9lL0vF6QL2Gj2iBhzNfXi88wf7xaR6XKY1wNuv3HLP" + System.lineSeparator() +
- "sL7n+PWby7LRX188dyS1dmKfQcrKL65OssBA5NC8CAYyBiygBmWN+5kVJM5fSb0SwPSoVWrNyz+8" + System.lineSeparator() +
- "IUldQE8=" +
- "" +
- "" +
- "" +
- "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" +
- "" +
- "" +
- "Hydra Kibana" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "Hydra" +
- "Hydra" +
- "https://hail.hydra/" +
- "" +
- "" +
- "Wolfgang" +
- "von Strucker" +
- "baron.strucker@supreme.hydra" +
- "" +
- "" +
- "Paul" +
- "Ebersol" +
- "pne@tech.hydra" +
- "" +
- ""
- ));
+
+ final String expectedCertificate = joinCertificateLines(
+ "MIIDWDCCAkCgAwIBAgIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA0GCSqGSIb3DQEBCwUAMB0xGzAZ",
+ "BgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDAeFw0xNzExMjkwMjQ3MjZaFw0yMDExMjgwMjQ3MjZa",
+ "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC",
+ "AQoCggEBALHTuPGOieCbD2mZUdYrdH4ofo7qFze6rQUROCLKqf69uBuwvraNWOcwxHUTKVlLMV3d",
+ "dKzYo+yfC44AMXrrV+79xVWsTCNHu9sxQzcDwiEx2OtOOX9MAk6tJQ3svNrMPNXWh8ftwmmY9XdF",
+ "ZwMYUdo6FPjSQj5uQTDmGWRgF08f7VRlk6N92d/fzn9DlDm+TFuaOr17OTSR4B6RTrNwKC29AmXQ",
+ "TwCijCObjLqyMEqP20dZCQeVf2qw8JKUHhW4r6mCLzqmeR+kRTqiHMSWxJddzxDGw6X7fOS7iuzB",
+ "0+TnsKwgu8nYrEXds9MkGf1Yco7WsM43g+Es+LhNHP+es70CAwEAAaOBjjCBizAdBgNVHQ4EFgQU",
+ "ILqVKGhIi8p5Xffsow/IKFLhRbIwWQYDVR0jBFIwUIAUILqVKGhIi8p5Xffsow/IKFLhRbKhIaQf",
+ "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTIIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA8G",
+ "A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGhl4V9mp4SWSV2E3HAJ1PX+Vmp6k27K",
+ "d0tkOk1B9fyA13QB30teyiL7RR0vSHRyWFY8rQH1mHD366GKRWLITRG/QPULamGdYXX4h0pFj5ld",
+ "aubLxM/O9vEAxOgmo/lsdkeIq9tLBqY06r/5A/Mcgo63KGi00AFYBoyvqfOu6nRLPnQr+rKVfdNO",
+ "pWeIiFY1i2XTNZ3CZjNPSTwiQMUzrCxKXB9lL0vF6QL2Gj2iBhzNfXi88wf7xaR6XKY1wNuv3HLP",
+ "sL7n+PWby7LRX188dyS1dmKfQcrKL65OssBA5NC8CAYyBiygBmWN+5kVJM5fSb0SwPSoVWrNyz+8",
+ "IUldQE8="
+ );
+
+ final String expectedXml = ""
+ + ""
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(expectedCertificate)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
+ + " "
+ + " "
+ + " Hydra Kibana"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " Hydra"
+ + " Hydra"
+ + " https://hail.hydra/"
+ + " "
+ + " "
+ + " Wolfgang"
+ + " von Strucker"
+ + " baron.strucker@supreme.hydra"
+ + " "
+ + " "
+ + " Paul"
+ + " Ebersol"
+ + " pne@tech.hydra"
+ + " "
+ + "";
+
+ final Map replacements = Map.of("expectedCertificate", expectedCertificate);
+ final String expectedXmlWithCertificate = NamedFormatter.format(expectedXml, replacements);
+
+ assertThat(xml, equalTo(normaliseXml(expectedXmlWithCertificate)));
+
assertValidXml(xml);
}
@@ -184,110 +210,151 @@ public void testBuildFullMetadataWithSigningAndTwoEncryptionCerts() throws Excep
final Element element = new EntityDescriptorMarshaller().marshall(descriptor);
final String xml = SamlUtils.toString(element);
- assertThat(xml, Matchers.equalTo("" +
- "" +
- "" +
- "" +
- "" +
- "MIIDWDCCAkCgAwIBAgIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA0GCSqGSIb3DQEBCwUAMB0xGzAZ" + System.lineSeparator() +
- "BgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDAeFw0xNzExMjkwMjQ3MjZaFw0yMDExMjgwMjQ3MjZa" + System.lineSeparator() +
- "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC" + System.lineSeparator() +
- "AQoCggEBALHTuPGOieCbD2mZUdYrdH4ofo7qFze6rQUROCLKqf69uBuwvraNWOcwxHUTKVlLMV3d" + System.lineSeparator() +
- "dKzYo+yfC44AMXrrV+79xVWsTCNHu9sxQzcDwiEx2OtOOX9MAk6tJQ3svNrMPNXWh8ftwmmY9XdF" + System.lineSeparator() +
- "ZwMYUdo6FPjSQj5uQTDmGWRgF08f7VRlk6N92d/fzn9DlDm+TFuaOr17OTSR4B6RTrNwKC29AmXQ" + System.lineSeparator() +
- "TwCijCObjLqyMEqP20dZCQeVf2qw8JKUHhW4r6mCLzqmeR+kRTqiHMSWxJddzxDGw6X7fOS7iuzB" + System.lineSeparator() +
- "0+TnsKwgu8nYrEXds9MkGf1Yco7WsM43g+Es+LhNHP+es70CAwEAAaOBjjCBizAdBgNVHQ4EFgQU" + System.lineSeparator() +
- "ILqVKGhIi8p5Xffsow/IKFLhRbIwWQYDVR0jBFIwUIAUILqVKGhIi8p5Xffsow/IKFLhRbKhIaQf" + System.lineSeparator() +
- "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTIIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA8G" + System.lineSeparator() +
- "A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGhl4V9mp4SWSV2E3HAJ1PX+Vmp6k27K" + System.lineSeparator() +
- "d0tkOk1B9fyA13QB30teyiL7RR0vSHRyWFY8rQH1mHD366GKRWLITRG/QPULamGdYXX4h0pFj5ld" + System.lineSeparator() +
- "aubLxM/O9vEAxOgmo/lsdkeIq9tLBqY06r/5A/Mcgo63KGi00AFYBoyvqfOu6nRLPnQr+rKVfdNO" + System.lineSeparator() +
- "pWeIiFY1i2XTNZ3CZjNPSTwiQMUzrCxKXB9lL0vF6QL2Gj2iBhzNfXi88wf7xaR6XKY1wNuv3HLP" + System.lineSeparator() +
- "sL7n+PWby7LRX188dyS1dmKfQcrKL65OssBA5NC8CAYyBiygBmWN+5kVJM5fSb0SwPSoVWrNyz+8" + System.lineSeparator() +
- "IUldQE8=" +
- "" +
- "" +
- "" +
- "" +
- "MIID0zCCArugAwIBAgIJALi5bDfjMszLMA0GCSqGSIb3DQEBCwUAMEgxDDAKBgNVBAoTA29yZzEW" + System.lineSeparator() +
- "MBQGA1UECxMNZWxhc3RpY3NlYXJjaDEgMB4GA1UEAxMXRWxhc3RpY3NlYXJjaCBUZXN0IE5vZGUw" + System.lineSeparator() +
- "HhcNMTUwOTIzMTg1MjU3WhcNMTkwOTIyMTg1MjU3WjBIMQwwCgYDVQQKEwNvcmcxFjAUBgNVBAsT" + System.lineSeparator() +
- "DWVsYXN0aWNzZWFyY2gxIDAeBgNVBAMTF0VsYXN0aWNzZWFyY2ggVGVzdCBOb2RlMIIBIjANBgkq" + System.lineSeparator() +
- "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3rGZ1QbsW0+MuyrSLmMfDFKtLBkIFW8V0gRuurFg1PUK" + System.lineSeparator() +
- "KNR1Mq2tMVwjjYETAU/UY0iKZOzjgvYPKhDTYBTte/WHR1ZK4CYVv7TQX/gtFQG/ge/c7u0sLch9" + System.lineSeparator() +
- "p7fbd+/HZiLS/rBEZDIohvgUvzvnA8+OIYnw4kuxKo/5iboAIS41klMg/lATm8V71LMY68inht71" + System.lineSeparator() +
- "/ZkQoAHKgcR9z4yNYvQ1WqKG8DG8KROXltll3sTrKbl5zJhn660es/1ZnR6nvwt6xnSTl/mNHMjk" + System.lineSeparator() +
- "fv1bs4rJ/py3qPxicdoSIn/KyojUcgHVF38fuAy2CQTdjVG5fWj9iz+mQvLm3+qsIYQdFwIDAQAB" + System.lineSeparator() +
- "o4G/MIG8MAkGA1UdEwQCMAAwHQYDVR0OBBYEFEMMWLWQi/g83PzlHYqAVnty5L7HMIGPBgNVHREE" + System.lineSeparator() +
- "gYcwgYSCCWxvY2FsaG9zdIIVbG9jYWxob3N0LmxvY2FsZG9tYWluggpsb2NhbGhvc3Q0ghdsb2Nh" + System.lineSeparator() +
- "bGhvc3Q0LmxvY2FsZG9tYWluNIIKbG9jYWxob3N0NoIXbG9jYWxob3N0Ni5sb2NhbGRvbWFpbjaH" + System.lineSeparator() +
- "BH8AAAGHEAAAAAAAAAAAAAAAAAAAAAEwDQYJKoZIhvcNAQELBQADggEBAMjGGXT8Nt1tbl2GkiKt" + System.lineSeparator() +
- "miuGE2Ej66YuZ37WSJViaRNDVHLlg87TCcHek2rdO+6sFqQbbzEfwQ05T7xGmVu7tm54HwKMRugo" + System.lineSeparator() +
- "Q3wct0bQC5wEWYN+oMDvSyO6M28mZwWb4VtR2IRyWP+ve5DHwTM9mxWa6rBlGzsQqH6YkJpZojzq" + System.lineSeparator() +
- "k/mQTug+Y8aEmVoqRIPMHq9ob+S9qd5lp09+MtYpwPfTPx/NN+xMEooXWW/ARfpGhWPkg/FuCu4z" + System.lineSeparator() +
- "1tFmCqHgNcWirzMm3dQpF78muE9ng6OB2MXQwL4VgnVkxmlZNHbkR2v/t8MyZJxCy4g6cTMM3S/U" + System.lineSeparator() +
- "Mt5/+aIB2JAuMKyuD+A=" +
- "" +
- "" +
- "" +
- "" +
- "MIID1zCCAr+gAwIBAgIJALnUl/KSS74pMA0GCSqGSIb3DQEBCwUAMEoxDDAKBgNVBAoTA29yZzEW" + System.lineSeparator() +
- "MBQGA1UECxMNZWxhc3RpY3NlYXJjaDEiMCAGA1UEAxMZRWxhc3RpY3NlYXJjaCBUZXN0IENsaWVu" + System.lineSeparator() +
- "dDAeFw0xNTA5MjMxODUyNTVaFw0xOTA5MjIxODUyNTVaMEoxDDAKBgNVBAoTA29yZzEWMBQGA1UE" + System.lineSeparator() +
- "CxMNZWxhc3RpY3NlYXJjaDEiMCAGA1UEAxMZRWxhc3RpY3NlYXJjaCBUZXN0IENsaWVudDCCASIw" + System.lineSeparator() +
- "DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMKm+P6vDAff0c6BWKGdhnYoNl9HijLIgfU3d9CQ" + System.lineSeparator() +
- "cqKtwT+yUW3DPSVjIfaLmDIGj6Hl8jTHWPB7ZP4fzhrPi6m4qlRGclJMECBuNASZFiPDtEDv3mso" + System.lineSeparator() +
- "eqOKQet6n7PZvgpWM7hxYZO4P1aMKJtRsFAdvBAdZUnv0spR5G4UZTHzSKmMeanIKFkLaD0XVKiL" + System.lineSeparator() +
- "Qu9/z9M6roDQeAEoCJ/8JsanG8ih2ymfPHIZuNyYIOrVekHN2zU6bnVn8/PCeZSjS6h5xYw+Jl5g" + System.lineSeparator() +
- "zGI/n+F5CZ+THoH8pM4pGp6xRVzpiH12gvERGwgSIDXdn/+uZZj+4lE7n2ENRSOt5KcOGG99r60C" + System.lineSeparator() +
- "AwEAAaOBvzCBvDAJBgNVHRMEAjAAMB0GA1UdDgQWBBSSFhBXNp7AaNrHdlgCV0mCEzt7ajCBjwYD" + System.lineSeparator() +
- "VR0RBIGHMIGEgglsb2NhbGhvc3SCFWxvY2FsaG9zdC5sb2NhbGRvbWFpboIKbG9jYWxob3N0NIIX" + System.lineSeparator() +
- "bG9jYWxob3N0NC5sb2NhbGRvbWFpbjSCCmxvY2FsaG9zdDaCF2xvY2FsaG9zdDYubG9jYWxkb21h" + System.lineSeparator() +
- "aW42hwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMA0GCSqGSIb3DQEBCwUAA4IBAQANvAkddfLxn4/B" + System.lineSeparator() +
- "CY4LY/1ET3d7ZRldjFTyjjHRYJ3CYBXWVahMskLxIcFNca8YjKfXoX8mcK+NQK/dAbGHXqk76yMl" + System.lineSeparator() +
- "krKjh1OQiZ1YAX5ryYerGrZ99N3E9wnbn72bW3iumoLlqmTWlHEpMI0Ql6J75BQLTgKHxCPupVA5" + System.lineSeparator() +
- "sTbWkKwGjXXAi84rUlzhDJOR8jk3/7ct0iZO8Hk6AWMcNix5Wka3IDGUXuEVevYRlxgVyCxcnZWC" + System.lineSeparator() +
- "7JWREpar5aIPQFkY6VCEglxwUyXbHZw5T/u6XaKKnS7gz8RiwRh68ddSQJeEHi5e4onUD7bOCJgf" + System.lineSeparator() +
- "siUwdiCkDbfN9Yum8OIpmBRs" +
- "" +
- "" +
- "" +
- "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" +
- "" +
- "" +
- "Hydra Kibana" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "Hydra" +
- "Hydra" +
- "https://hail.hydra/" +
- "" +
- "" +
- "Wolfgang" +
- "von Strucker" +
- "baron.strucker@supreme.hydra" +
- "" +
- "" +
- "Paul" +
- "Ebersol" +
- "pne@tech.hydra" +
- "" +
- ""
- ));
+
+ final String expectedCertificateOne = joinCertificateLines(
+ "MIIDWDCCAkCgAwIBAgIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA0GCSqGSIb3DQEBCwUAMB0xGzAZ",
+ "BgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDAeFw0xNzExMjkwMjQ3MjZaFw0yMDExMjgwMjQ3MjZa",
+ "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC",
+ "AQoCggEBALHTuPGOieCbD2mZUdYrdH4ofo7qFze6rQUROCLKqf69uBuwvraNWOcwxHUTKVlLMV3d",
+ "dKzYo+yfC44AMXrrV+79xVWsTCNHu9sxQzcDwiEx2OtOOX9MAk6tJQ3svNrMPNXWh8ftwmmY9XdF",
+ "ZwMYUdo6FPjSQj5uQTDmGWRgF08f7VRlk6N92d/fzn9DlDm+TFuaOr17OTSR4B6RTrNwKC29AmXQ",
+ "TwCijCObjLqyMEqP20dZCQeVf2qw8JKUHhW4r6mCLzqmeR+kRTqiHMSWxJddzxDGw6X7fOS7iuzB",
+ "0+TnsKwgu8nYrEXds9MkGf1Yco7WsM43g+Es+LhNHP+es70CAwEAAaOBjjCBizAdBgNVHQ4EFgQU",
+ "ILqVKGhIi8p5Xffsow/IKFLhRbIwWQYDVR0jBFIwUIAUILqVKGhIi8p5Xffsow/IKFLhRbKhIaQf",
+ "MB0xGzAZBgNVBAMTEkVsYXN0aWNzZWFyY2gtU0FNTIIVANRTZaFrK+Pz19O8TZsb3HSJmAWpMA8G",
+ "A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGhl4V9mp4SWSV2E3HAJ1PX+Vmp6k27K",
+ "d0tkOk1B9fyA13QB30teyiL7RR0vSHRyWFY8rQH1mHD366GKRWLITRG/QPULamGdYXX4h0pFj5ld",
+ "aubLxM/O9vEAxOgmo/lsdkeIq9tLBqY06r/5A/Mcgo63KGi00AFYBoyvqfOu6nRLPnQr+rKVfdNO",
+ "pWeIiFY1i2XTNZ3CZjNPSTwiQMUzrCxKXB9lL0vF6QL2Gj2iBhzNfXi88wf7xaR6XKY1wNuv3HLP",
+ "sL7n+PWby7LRX188dyS1dmKfQcrKL65OssBA5NC8CAYyBiygBmWN+5kVJM5fSb0SwPSoVWrNyz+8",
+ "IUldQE8="
+ );
+
+ final String expectedCertificateTwo = joinCertificateLines(
+ "MIID0zCCArugAwIBAgIJALi5bDfjMszLMA0GCSqGSIb3DQEBCwUAMEgxDDAKBgNVBAoTA29yZzEW",
+ "MBQGA1UECxMNZWxhc3RpY3NlYXJjaDEgMB4GA1UEAxMXRWxhc3RpY3NlYXJjaCBUZXN0IE5vZGUw",
+ "HhcNMTUwOTIzMTg1MjU3WhcNMTkwOTIyMTg1MjU3WjBIMQwwCgYDVQQKEwNvcmcxFjAUBgNVBAsT",
+ "DWVsYXN0aWNzZWFyY2gxIDAeBgNVBAMTF0VsYXN0aWNzZWFyY2ggVGVzdCBOb2RlMIIBIjANBgkq",
+ "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3rGZ1QbsW0+MuyrSLmMfDFKtLBkIFW8V0gRuurFg1PUK",
+ "KNR1Mq2tMVwjjYETAU/UY0iKZOzjgvYPKhDTYBTte/WHR1ZK4CYVv7TQX/gtFQG/ge/c7u0sLch9",
+ "p7fbd+/HZiLS/rBEZDIohvgUvzvnA8+OIYnw4kuxKo/5iboAIS41klMg/lATm8V71LMY68inht71",
+ "/ZkQoAHKgcR9z4yNYvQ1WqKG8DG8KROXltll3sTrKbl5zJhn660es/1ZnR6nvwt6xnSTl/mNHMjk",
+ "fv1bs4rJ/py3qPxicdoSIn/KyojUcgHVF38fuAy2CQTdjVG5fWj9iz+mQvLm3+qsIYQdFwIDAQAB",
+ "o4G/MIG8MAkGA1UdEwQCMAAwHQYDVR0OBBYEFEMMWLWQi/g83PzlHYqAVnty5L7HMIGPBgNVHREE",
+ "gYcwgYSCCWxvY2FsaG9zdIIVbG9jYWxob3N0LmxvY2FsZG9tYWluggpsb2NhbGhvc3Q0ghdsb2Nh",
+ "bGhvc3Q0LmxvY2FsZG9tYWluNIIKbG9jYWxob3N0NoIXbG9jYWxob3N0Ni5sb2NhbGRvbWFpbjaH",
+ "BH8AAAGHEAAAAAAAAAAAAAAAAAAAAAEwDQYJKoZIhvcNAQELBQADggEBAMjGGXT8Nt1tbl2GkiKt",
+ "miuGE2Ej66YuZ37WSJViaRNDVHLlg87TCcHek2rdO+6sFqQbbzEfwQ05T7xGmVu7tm54HwKMRugo",
+ "Q3wct0bQC5wEWYN+oMDvSyO6M28mZwWb4VtR2IRyWP+ve5DHwTM9mxWa6rBlGzsQqH6YkJpZojzq",
+ "k/mQTug+Y8aEmVoqRIPMHq9ob+S9qd5lp09+MtYpwPfTPx/NN+xMEooXWW/ARfpGhWPkg/FuCu4z",
+ "1tFmCqHgNcWirzMm3dQpF78muE9ng6OB2MXQwL4VgnVkxmlZNHbkR2v/t8MyZJxCy4g6cTMM3S/U",
+ "Mt5/+aIB2JAuMKyuD+A="
+ );
+
+ final String expectedCertificateThree = joinCertificateLines(
+ "MIID1zCCAr+gAwIBAgIJALnUl/KSS74pMA0GCSqGSIb3DQEBCwUAMEoxDDAKBgNVBAoTA29yZzEW",
+ "MBQGA1UECxMNZWxhc3RpY3NlYXJjaDEiMCAGA1UEAxMZRWxhc3RpY3NlYXJjaCBUZXN0IENsaWVu",
+ "dDAeFw0xNTA5MjMxODUyNTVaFw0xOTA5MjIxODUyNTVaMEoxDDAKBgNVBAoTA29yZzEWMBQGA1UE",
+ "CxMNZWxhc3RpY3NlYXJjaDEiMCAGA1UEAxMZRWxhc3RpY3NlYXJjaCBUZXN0IENsaWVudDCCASIw",
+ "DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMKm+P6vDAff0c6BWKGdhnYoNl9HijLIgfU3d9CQ",
+ "cqKtwT+yUW3DPSVjIfaLmDIGj6Hl8jTHWPB7ZP4fzhrPi6m4qlRGclJMECBuNASZFiPDtEDv3mso",
+ "eqOKQet6n7PZvgpWM7hxYZO4P1aMKJtRsFAdvBAdZUnv0spR5G4UZTHzSKmMeanIKFkLaD0XVKiL",
+ "Qu9/z9M6roDQeAEoCJ/8JsanG8ih2ymfPHIZuNyYIOrVekHN2zU6bnVn8/PCeZSjS6h5xYw+Jl5g",
+ "zGI/n+F5CZ+THoH8pM4pGp6xRVzpiH12gvERGwgSIDXdn/+uZZj+4lE7n2ENRSOt5KcOGG99r60C",
+ "AwEAAaOBvzCBvDAJBgNVHRMEAjAAMB0GA1UdDgQWBBSSFhBXNp7AaNrHdlgCV0mCEzt7ajCBjwYD",
+ "VR0RBIGHMIGEgglsb2NhbGhvc3SCFWxvY2FsaG9zdC5sb2NhbGRvbWFpboIKbG9jYWxob3N0NIIX",
+ "bG9jYWxob3N0NC5sb2NhbGRvbWFpbjSCCmxvY2FsaG9zdDaCF2xvY2FsaG9zdDYubG9jYWxkb21h",
+ "aW42hwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMA0GCSqGSIb3DQEBCwUAA4IBAQANvAkddfLxn4/B",
+ "CY4LY/1ET3d7ZRldjFTyjjHRYJ3CYBXWVahMskLxIcFNca8YjKfXoX8mcK+NQK/dAbGHXqk76yMl",
+ "krKjh1OQiZ1YAX5ryYerGrZ99N3E9wnbn72bW3iumoLlqmTWlHEpMI0Ql6J75BQLTgKHxCPupVA5",
+ "sTbWkKwGjXXAi84rUlzhDJOR8jk3/7ct0iZO8Hk6AWMcNix5Wka3IDGUXuEVevYRlxgVyCxcnZWC",
+ "7JWREpar5aIPQFkY6VCEglxwUyXbHZw5T/u6XaKKnS7gz8RiwRh68ddSQJeEHi5e4onUD7bOCJgf",
+ "siUwdiCkDbfN9Yum8OIpmBRs"
+ );
+
+ final String expectedXml = ""
+ + ""
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(expectedCertificateOne)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(expectedCertificateTwo)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " %(expectedCertificateThree)"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
+ + " "
+ + " "
+ + " Hydra Kibana"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " Hydra"
+ + " Hydra"
+ + " https://hail.hydra/"
+ + " "
+ + " "
+ + " Wolfgang"
+ + " von Strucker"
+ + " baron.strucker@supreme.hydra"
+ + " "
+ + " "
+ + " Paul"
+ + " Ebersol"
+ + " pne@tech.hydra"
+ + " "
+ + "";
+
+ final Map replacements = new HashMap<>();
+ replacements.put("expectedCertificateOne", expectedCertificateOne);
+ replacements.put("expectedCertificateTwo", expectedCertificateTwo);
+ replacements.put("expectedCertificateThree", expectedCertificateThree);
+
+ final String expectedXmlWithCertificate = NamedFormatter.format(expectedXml, replacements);
+
+ assertThat(xml, equalTo(normaliseXml(expectedXmlWithCertificate)));
+
assertValidXml(xml);
}
@@ -306,4 +373,14 @@ public void testAttributeNameIsRequired() {
private void assertValidXml(String xml) throws Exception {
SamlUtils.validate(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)), SamlMetadataCommand.METADATA_SCHEMA);
}
+
+ private String joinCertificateLines(String... lines) {
+ return Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator()));
+ }
+
+ private String normaliseXml(String input) {
+ // Remove spaces between elements, and compress other spaces. These patterns don't use \s because
+ // that would match newlines.
+ return input.replaceAll("> +<", "><").replaceAll(" +", " ");
+ }
}
diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/DataType.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/DataType.java
index 22f2a596e3515..69d72c674e991 100644
--- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/DataType.java
+++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/DataType.java
@@ -24,7 +24,10 @@
*/
public enum DataType {
- // @formatter:off
+ // The following code is more clearly expressed in a tabular formatter,
+ // so we disable automatic formatting with 'tag' and 'end'.
+ //
+ // tag::xpack-sql-datatypes-disable-formatting
// esType jdbc type, size, defPrecision,dispSize, int, rat, docvals
NULL( "null", JDBCType.NULL, 0, 0, 0, false, false, false),
UNSUPPORTED( JDBCType.OTHER, 0, 0, 0, false, false, false),
@@ -79,7 +82,7 @@ public enum DataType {
INTERVAL_HOUR_TO_MINUTE( ExtTypes.INTERVAL_HOUR_TO_MINUTE, Long.BYTES, 23, 23, false, false, false),
INTERVAL_HOUR_TO_SECOND( ExtTypes.INTERVAL_HOUR_TO_SECOND, Long.BYTES, 23, 23, false, false, false),
INTERVAL_MINUTE_TO_SECOND(ExtTypes.INTERVAL_MINUTE_TO_SECOND,Long.BYTES, 23, 23, false, false, false);
- // @formatter:on
+ // end::xpack-sql-datatypes-disable-formatting
private static final Map ODBC_TO_ES = new HashMap<>(36);
static {
@@ -285,7 +288,7 @@ public boolean isDayTimeInterval() {
return (ordinal >= INTERVAL_DAY.ordinal() && ordinal <= INTERVAL_SECOND.ordinal())
|| (ordinal >= INTERVAL_DAY_TO_HOUR.ordinal() && ordinal <= INTERVAL_MINUTE_TO_SECOND.ordinal());
}
-
+
// data type extract-able from _source or from docvalue_fields
public boolean isFromDocValuesOnly() {
return this == KEYWORD // because of ignore_above. Extracting this from _source wouldn't make sense if it wasn't indexed at all.
diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java
index 68dbf0bbc9279..b430d26caa4bb 100644
--- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java
+++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java
@@ -651,19 +651,21 @@ public void testFoldNullDateTrunc() {
}
public void testSimplifyCaseConditionsFoldWhenFalse() {
- // CASE WHEN a = 1 THEN 'foo1'
- // WHEN 1 = 2 THEN 'bar1'
- // WHEN 2 = 1 THEN 'bar2'
- // WHEN a > 1 THEN 'foo2'
- // ELSE 'default'
- // END
- //
- // ==>
- //
- // CASE WHEN a = 1 THEN 'foo1'
- // WHEN a > 1 THEN 'foo2'
- // ELSE 'default'
- // END
+ /*
+ * CASE WHEN a = 1 THEN 'foo1'
+ * WHEN 1 = 2 THEN 'bar1'
+ * WHEN 2 = 1 THEN 'bar2'
+ * WHEN a > 1 THEN 'foo2'
+ * ELSE 'default'
+ * END
+ *
+ * ==>
+ *
+ * CASE WHEN a = 1 THEN 'foo1'
+ * WHEN a > 1 THEN 'foo2'
+ * ELSE 'default'
+ * END
+ */
Case c = new Case(EMPTY, Arrays.asList(
new IfConditional(EMPTY, new Equals(EMPTY, getFieldAttribute(), ONE), Literal.of(EMPTY, "foo1")),
@@ -682,19 +684,21 @@ public void testSimplifyCaseConditionsFoldWhenFalse() {
}
public void testSimplifyCaseConditionsFoldWhenTrue() {
- // CASE WHEN a = 1 THEN 'foo1'
- // WHEN 1 = 1 THEN 'bar1'
- // WHEN 2 = 1 THEN 'bar2'
- // WHEN a > 1 THEN 'foo2'
- // ELSE 'default'
- // END
- //
- // ==>
- //
- // CASE WHEN a = 1 THEN 'foo1'
- // WHEN 1 = 1 THEN 'bar1'
- // ELSE 'default'
- // END
+ /*
+ * CASE WHEN a = 1 THEN 'foo1'
+ * WHEN 1 = 1 THEN 'bar1'
+ * WHEN 2 = 1 THEN 'bar2'
+ * WHEN a > 1 THEN 'foo2'
+ * ELSE 'default'
+ * END
+ *
+ * ==>
+ *
+ * CASE WHEN a = 1 THEN 'foo1'
+ * WHEN 1 = 1 THEN 'bar1'
+ * ELSE 'default'
+ * END
+ */
SimplifyCase rule = new SimplifyCase();
Case c = new Case(EMPTY, Arrays.asList(
@@ -714,14 +718,16 @@ public void testSimplifyCaseConditionsFoldWhenTrue() {
}
public void testSimplifyCaseConditionsFoldCompletely() {
- // CASE WHEN 1 = 2 THEN 'foo1'
- // WHEN 1 = 1 THEN 'foo2'
- // ELSE 'default'
- // END
- //
- // ==>
- //
- // 'foo2'
+ /*
+ * CASE WHEN 1 = 2 THEN 'foo1'
+ * WHEN 1 = 1 THEN 'foo2'
+ * ELSE 'default'
+ * END
+ *
+ * ==>
+ *
+ * 'foo2'
+ */
SimplifyCase rule = new SimplifyCase();
Case c = new Case(EMPTY, Arrays.asList(
diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java
index 6b99a60e10c1b..764506036c3d0 100644
--- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java
+++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java
@@ -90,7 +90,8 @@ public void testParseSearchAggs() {
7, // indexTotal
8, // searchTotal
9, // indexFailures
- 10); // searchFailures
+ 10 // searchFailures
+ );
int currentStat = 1;
List aggs = new ArrayList<>(PROVIDED_STATS.length);