@@ -37,6 +37,8 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
37
37
private static final String TEST_ADMIN_USERNAME = "test_admin" ;
38
38
private static final String TEST_ADMIN_PASSWORD = "x-pack-test-password" ;
39
39
40
+ private String watchId = randomAlphaOfLength (20 );
41
+
40
42
@ Before
41
43
public void startWatcher () throws Exception {
42
44
StringEntity entity = new StringEntity ("{ \" value\" : \" 15\" }" , ContentType .APPLICATION_JSON );
@@ -87,7 +89,6 @@ public void startWatcher() throws Exception {
87
89
88
90
@ After
89
91
public void stopWatcher () throws Exception {
90
- adminClient ().performRequest ("DELETE" , "_xpack/watcher/watch/my_watch" );
91
92
assertOK (adminClient ().performRequest ("DELETE" , "my_test_index" ));
92
93
93
94
assertBusy (() -> {
@@ -147,14 +148,14 @@ public void testSearchInputHasPermissions() throws Exception {
147
148
builder .startObject ("condition" ).startObject ("compare" ).startObject ("ctx.payload.hits.total" ).field ("gte" , 1 )
148
149
.endObject ().endObject ().endObject ();
149
150
builder .startObject ("actions" ).startObject ("logging" ).startObject ("logging" )
150
- .field ("text" , "successfully ran my_watch to test for search inpput" ).endObject ().endObject ().endObject ();
151
+ .field ("text" , "successfully ran " + watchId + " to test for search inpput" ).endObject ().endObject ().endObject ();
151
152
builder .endObject ();
152
153
153
- indexWatch ("my_watch" , builder );
154
+ indexWatch (watchId , builder );
154
155
}
155
156
156
157
// check history, after watch has fired
157
- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
158
+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
158
159
boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
159
160
assertThat (conditionMet , is (true ));
160
161
}
@@ -174,11 +175,11 @@ public void testSearchInputWithInsufficientPrivileges() throws Exception {
174
175
.field ("text" , "this should never be logged" ).endObject ().endObject ().endObject ();
175
176
builder .endObject ();
176
177
177
- indexWatch ("my_watch" , builder );
178
+ indexWatch (watchId , builder );
178
179
}
179
180
180
181
// check history, after watch has fired
181
- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" );
182
+ ObjectPath objectPath = getWatchHistoryEntry (watchId );
182
183
String state = objectPath .evaluate ("hits.hits.0._source.state" );
183
184
assertThat (state , is ("execution_not_needed" ));
184
185
boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
@@ -201,11 +202,11 @@ public void testSearchTransformHasPermissions() throws Exception {
201
202
.endObject ().endObject ().endObject ();
202
203
builder .endObject ();
203
204
204
- indexWatch ("my_watch" , builder );
205
+ indexWatch (watchId , builder );
205
206
}
206
207
207
208
// check history, after watch has fired
208
- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
209
+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
209
210
boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
210
211
assertThat (conditionMet , is (true ));
211
212
@@ -232,10 +233,10 @@ public void testSearchTransformInsufficientPermissions() throws Exception {
232
233
.endObject ().endObject ().endObject ();
233
234
builder .endObject ();
234
235
235
- indexWatch ("my_watch" , builder );
236
+ indexWatch (watchId , builder );
236
237
}
237
238
238
- getWatchHistoryEntry ("my_watch" );
239
+ getWatchHistoryEntry (watchId );
239
240
240
241
Response response = adminClient ().performRequest ("GET" , "my_test_index/doc/some-id" ,
241
242
Collections .singletonMap ("ignore" , "404" ));
@@ -254,10 +255,10 @@ public void testIndexActionHasPermissions() throws Exception {
254
255
.endObject ().endObject ().endObject ();
255
256
builder .endObject ();
256
257
257
- indexWatch ("my_watch" , builder );
258
+ indexWatch (watchId , builder );
258
259
}
259
260
260
- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
261
+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
261
262
boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
262
263
assertThat (conditionMet , is (true ));
263
264
@@ -278,10 +279,10 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
278
279
.endObject ().endObject ().endObject ();
279
280
builder .endObject ();
280
281
281
- indexWatch ("my_watch" , builder );
282
+ indexWatch (watchId , builder );
282
283
}
283
284
284
- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
285
+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
285
286
boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
286
287
assertThat (conditionMet , is (true ));
287
288
@@ -293,7 +294,7 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
293
294
private void indexWatch (String watchId , XContentBuilder builder ) throws Exception {
294
295
StringEntity entity = new StringEntity (Strings .toString (builder ), ContentType .APPLICATION_JSON );
295
296
296
- Response response = client ().performRequest ("PUT" , "_xpack/watcher/watch/my_watch" , Collections .emptyMap (), entity );
297
+ Response response = client ().performRequest ("PUT" , "_xpack/watcher/watch/" + watchId , Collections .emptyMap (), entity );
297
298
assertOK (response );
298
299
Map <String , Object > responseMap = entityAsMap (response );
299
300
assertThat (responseMap , hasEntry ("_id" , watchId ));
0 commit comments