diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java index 1d518dd8417..cfd68f10af1 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java @@ -90,7 +90,7 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { public void testSendMessageV1Account() throws Exception { HipChatService service = getInstanceFromMaster(HipChatService.class); HipChatMessage hipChatMessage = new HipChatMessage( - "/code HipChatServiceTests#testSendMessage_V1Account", + "HipChatServiceTests#testSendMessage_V1Account", new String[] { "test-watcher", "test-watcher-2" }, null, // users are unsupported in v1 "watcher-tests", @@ -108,7 +108,7 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { HipChatService service = getInstanceFromMaster(HipChatService.class); HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values()); HipChatMessage hipChatMessage = new HipChatMessage( - "/code HipChatServiceTests#testSendMessage_IntegrationAccount colored " + color.value(), + "HipChatServiceTests#testSendMessage_IntegrationAccount colored " + color.value(), null, // custom rooms are unsupported by integration profiles null, // users are unsupported by integration profiles null, // custom "from" is not supported by integration profiles @@ -126,7 +126,7 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { HipChatService service = getInstanceFromMaster(HipChatService.class); HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values()); HipChatMessage hipChatMessage = new HipChatMessage( - "/code HipChatServiceTests#testSendMessage_UserAccount colored " + color.value(), + "HipChatServiceTests#testSendMessage_UserAccount colored " + color.value(), new String[] { "test-watcher", "test-watcher-2" }, new String[] { "watcher@elastic.co" }, null, // custom "from" is not supported by integration profiles @@ -148,7 +148,7 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { switch (profile) { case USER: account = "user_account"; - actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}") + actionBuilder = hipchatAction(account, "{{ctx.payload.ref}}") .addRooms("test-watcher", "test-watcher-2") .addUsers("watcher@elastic.co") .setFormat(HipChatMessage.Format.TEXT) @@ -158,7 +158,7 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { case INTEGRATION: account = "integration_account"; - actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}") + actionBuilder = hipchatAction(account, "{{ctx.payload.ref}}") .setFormat(HipChatMessage.Format.TEXT) .setColor(color) .setNotify(false); @@ -167,7 +167,7 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { default: assertThat(profile, is(HipChatAccount.Profile.V1)); account = "v1_account"; - actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}") + actionBuilder = hipchatAction(account, "{{ctx.payload.ref}}") .addRooms("test-watcher", "test-watcher-2") .setFrom("watcher-test") .setFormat(HipChatMessage.Format.TEXT) @@ -201,6 +201,23 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { assertThat(response.getHits().getTotalHits(), is(1L)); } + public void testDefaultValuesForColorAndFormatWorks() { + HipChatService service = getInstanceFromMaster(HipChatService.class); + HipChatMessage hipChatMessage = new HipChatMessage( + "HipChatServiceTests#testSendMessage_UserAccount with default Color and text", + new String[] { "test-watcher" }, + new String[] { "watcher@elastic.co" }, + null, // custom "from" is not supported by integration profiles + null, + null, + false); + + HipChatAccount account = service.getAccount("user_account"); + assertThat(account, notNullValue()); + SentMessages messages = account.send(hipChatMessage); + assertSentMessagesAreValid(2, messages); + } + private void assertSentMessagesAreValid(int expectedMessageSize, SentMessages messages) { assertThat(messages.count(), is(expectedMessageSize)); for (SentMessages.SentMessage message : messages) { diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java index 74325358f3b..bf8200f30ad 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.Map; import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; public class RestGetLicenseAction extends BaseRestHandler { @@ -58,14 +59,15 @@ public class RestGetLicenseAction extends BaseRestHandler { if (!request.hasParam("pretty")) { builder.prettyPrint().lfAtEnd(); } + boolean hasLicense = response.license() != null; builder.startObject(); - if (response.license() != null) { + if (hasLicense) { builder.startObject("license"); response.license().toInnerXContent(builder, params); builder.endObject(); } builder.endObject(); - return new BytesRestResponse(OK, builder); + return new BytesRestResponse(hasLicense ? OK : NOT_FOUND, builder); } }); } diff --git a/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/api/license.delete.json b/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/api/license.delete.json new file mode 100644 index 00000000000..903a0ed361d --- /dev/null +++ b/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/api/license.delete.json @@ -0,0 +1,12 @@ +{ + "license.delete": { + "documentation": "https://www.elastic.co/guide/en/shield/current/license-management.html", + "methods": ["DELETE"], + "url": { + "path": "/_license", + "paths": ["/_license"], + "parts" : {} + }, + "body": null + } +} diff --git a/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/test/license/20_put_license.yaml b/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/test/license/20_put_license.yaml index 1d5fb822c7e..be2592d265a 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/test/license/20_put_license.yaml +++ b/elasticsearch/x-pack/license-plugin/src/test/resources/rest-api-spec/test/license/20_put_license.yaml @@ -55,3 +55,14 @@ - length: { license: 10 } - match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" } +--- +"Should throw 404 after license deletion": + + - do: + license.delete: {} + + - match: { acknowledged: true } + + - do: + catch: missing + license.get: {} diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index 3ad58bad8ad..1b02791285e 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.integration; +import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetResponse; @@ -548,13 +549,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { refresh(); SearchResponse searchResponse = client().prepareSearch("test") - .setQuery(hasChildQuery("child", matchAllQuery())) + .setQuery(hasChildQuery("child", matchAllQuery(), ScoreMode.None)) .get(); assertHitCount(searchResponse, 1L); assertThat(searchResponse.getHits().getAt(0).id(), equalTo("p1")); searchResponse = client().prepareSearch("test") - .setQuery(hasParentQuery("parent", matchAllQuery())) + .setQuery(hasParentQuery("parent", matchAllQuery(), false)) .addSort("_uid", SortOrder.ASC) .get(); assertHitCount(searchResponse, 3L); @@ -565,39 +566,39 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { // Both user1 and user2 can't see field1 and field2, no parent/child query should yield results: searchResponse = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasChildQuery("child", matchAllQuery())) + .setQuery(hasChildQuery("child", matchAllQuery(), ScoreMode.None)) .get(); assertHitCount(searchResponse, 0L); searchResponse = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasChildQuery("child", matchAllQuery())) + .setQuery(hasChildQuery("child", matchAllQuery(), ScoreMode.None)) .get(); assertHitCount(searchResponse, 0L); searchResponse = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasParentQuery("parent", matchAllQuery())) + .setQuery(hasParentQuery("parent", matchAllQuery(), false)) .get(); assertHitCount(searchResponse, 0L); searchResponse = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasParentQuery("parent", matchAllQuery())) + .setQuery(hasParentQuery("parent", matchAllQuery(), false)) .get(); assertHitCount(searchResponse, 0L); // user 3 can see them but not c3 searchResponse = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasChildQuery("child", matchAllQuery())) + .setQuery(hasChildQuery("child", matchAllQuery(), ScoreMode.None)) .get(); assertHitCount(searchResponse, 1L); assertThat(searchResponse.getHits().getAt(0).id(), equalTo("p1")); searchResponse = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasParentQuery("parent", matchAllQuery())) + .setQuery(hasParentQuery("parent", matchAllQuery(), false)) .get(); assertHitCount(searchResponse, 2L); assertThat(searchResponse.getHits().getAt(0).id(), equalTo("c1")); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index 23b12fc8563..1585d33b9e4 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.integration; +import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.action.fieldstats.FieldStatsResponse; import org.elasticsearch.action.get.GetResponse; @@ -1177,7 +1178,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { SearchResponse searchResponse = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasChildQuery("child", termQuery("field1", "yellow"))) + .setQuery(hasChildQuery("child", termQuery("field1", "yellow"), ScoreMode.None)) .get(); assertHitCount(searchResponse, 1L); assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); @@ -1186,7 +1187,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { searchResponse = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareSearch("test") - .setQuery(hasChildQuery("child", termQuery("field1", "yellow"))) + .setQuery(hasChildQuery("child", termQuery("field1", "yellow"), ScoreMode.None)) .get(); assertHitCount(searchResponse, 0L); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/ReservedRealmTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/ReservedRealmTests.java index a1765ec9334..9baf301bba2 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/ReservedRealmTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/ReservedRealmTests.java @@ -129,6 +129,6 @@ public class ReservedRealmTests extends ESTestCase { assertThat(ReservedRealm.isReserved(notExpected), is(false)); assertThat(ReservedRealm.getUser(notExpected), nullValue()); - assertThat(ReservedRealm.users(), containsInAnyOrder(XPackUser.INSTANCE, KibanaUser.INSTANCE)); + assertThat(ReservedRealm.users(), containsInAnyOrder((User) XPackUser.INSTANCE, KibanaUser.INSTANCE)); } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherDateTimeUtils.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherDateTimeUtils.java index efcc04658df..5a6c27d09eb 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherDateTimeUtils.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherDateTimeUtils.java @@ -25,7 +25,7 @@ import java.util.concurrent.Callable; */ public class WatcherDateTimeUtils { - public static final FormatDateTimeFormatter dateTimeFormatter = DateFieldMapper.Defaults.DATE_TIME_FORMATTER; + public static final FormatDateTimeFormatter dateTimeFormatter = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER; public static final DateMathParser dateMathParser = new DateMathParser(dateTimeFormatter); private WatcherDateTimeUtils() { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java index bc3cceba7f7..86f3067c83d 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java @@ -5,6 +5,17 @@ */ package org.elasticsearch.watcher.support; +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.formatDate; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; @@ -27,17 +38,6 @@ import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.watch.Payload; import org.joda.time.DateTime; -import java.io.IOException; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.formatDate; - /** */ public final class WatcherUtils { @@ -113,7 +113,7 @@ public final class WatcherUtils { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); if (ParseFieldMatcher.STRICT.match(currentFieldName, BODY_FIELD)) { - searchRequest.source(SearchSourceBuilder.fromXContent(parser, context, aggParsers, suggesters)); + searchRequest.source(SearchSourceBuilder.fromXContent(context, aggParsers, suggesters)); } } else if (token == XContentParser.Token.START_ARRAY) { if (ParseFieldMatcher.STRICT.match(currentFieldName, INDICES_FIELD)) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java index cd1e934e9cf..c079e5da222 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java @@ -31,6 +31,10 @@ public class DefaultTextTemplateEngine extends AbstractComponent implements Text @Override public String render(TextTemplate template, Map model) { + if (template == null) { + return null; + } + XContentType contentType = detectContentType(template); Map compileParams = compileParams(contentType); template = trimContentType(template); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java index b4d54e5fe78..dd2c01ef294 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java @@ -17,8 +17,11 @@ import org.elasticsearch.watcher.support.http.HttpMethod; import org.elasticsearch.watcher.support.http.HttpRequest; import org.elasticsearch.watcher.support.http.HttpResponse; import org.elasticsearch.watcher.support.http.Scheme; +import org.elasticsearch.watcher.support.text.TextTemplate; +import org.elasticsearch.watcher.test.MockTextTemplateEngine; import java.io.IOException; +import java.util.HashMap; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.hamcrest.Matchers.arrayContaining; @@ -33,6 +36,7 @@ import static org.mockito.Mockito.when; * */ public class UserAccountTests extends ESTestCase { + public void testSettings() throws Exception { String accountName = "_name"; @@ -246,4 +250,41 @@ public class UserAccountTests extends ESTestCase { verify(httpClient).execute(reqU2); verify(httpClient).execute(reqU2); } + + public void testColorIsOptional() throws Exception { + Settings settings = Settings.builder() + .put("user", "testuser") + .put("auth_token", "awesome-auth-token") + .build(); + UserAccount userAccount = createUserAccount(settings); + + TextTemplate body = TextTemplate.inline("body").build(); + TextTemplate[] rooms = new TextTemplate[] { TextTemplate.inline("room").build() }; + HipChatMessage.Template template = new HipChatMessage.Template(body, rooms, null, "sender", HipChatMessage.Format.TEXT, null, true); + + HipChatMessage message = userAccount.render("watchId", "actionId", new MockTextTemplateEngine(), template, new HashMap<>()); + assertThat(message.color, is(nullValue())); + } + + public void testFormatIsOptional() throws Exception { + Settings settings = Settings.builder() + .put("user", "testuser") + .put("auth_token", "awesome-auth-token") + .build(); + UserAccount userAccount = createUserAccount(settings); + + TextTemplate body = TextTemplate.inline("body").build(); + TextTemplate[] rooms = new TextTemplate[] { TextTemplate.inline("room").build() }; + HipChatMessage.Template template = new HipChatMessage.Template(body, rooms, null, "sender", null, + TextTemplate.inline("yellow").build(), true); + + HipChatMessage message = userAccount.render("watchId", "actionId", new MockTextTemplateEngine(), template, new HashMap<>()); + assertThat(message.format, is(nullValue())); + } + + private UserAccount createUserAccount(Settings settings) { + HipChatServer hipChatServer = mock(HipChatServer.class); + HttpClient httpClient = mock(HttpClient.class); + return new UserAccount("notify-monitoring", settings, hipChatServer, httpClient, logger); + } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java index 481efc09365..2731fcd8501 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java @@ -34,6 +34,7 @@ import static org.elasticsearch.watcher.support.Exceptions.illegalArgument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -186,6 +187,10 @@ public class TextTemplateTests extends ESTestCase { } } + public void testNullObject() throws Exception { + assertThat(engine.render(null ,new HashMap<>()), is(nullValue())); + } + private TextTemplate.Builder templateBuilder(ScriptType type, String text) { switch (type) { case INLINE: return TextTemplate.inline(text); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/MockTextTemplateEngine.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/MockTextTemplateEngine.java index c5236983706..933f9bd79e0 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/MockTextTemplateEngine.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/MockTextTemplateEngine.java @@ -13,6 +13,10 @@ import java.util.Map; public class MockTextTemplateEngine implements TextTemplateEngine { @Override public String render(TextTemplate template, Map model) { + if (template == null ) { + return null; + } + return template.getTemplate(); } }