Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fixes verifying workflow test when security is enabled #566

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ protected Map<String, Object> searchWorkflow(String workflowId) throws IOExcepti
" }\n" +
" }\n" +
"}";
List<SearchHit> hits = executeSearch(ScheduledJob.SCHEDULED_JOBS_INDEX, workflowRequest);
List<SearchHit> hits = executeWorkflowSearch("/_plugins/_alerting/monitors", workflowRequest);

if (hits.size() == 0) {
return new HashMap<>();
}

SearchHit hit = hits.get(0);
return (Map<String, Object>) hit.getSourceAsMap().get("workflow");
return (Map<String, Object>) hit.getSourceAsMap();
}


Expand Down Expand Up @@ -412,6 +413,16 @@ protected List<SearchHit> executeSearch(String index, String request, Boolean re
return Arrays.asList(searchResponse.getHits().getHits());
}

protected List<SearchHit> executeWorkflowSearch(String url, String request) throws IOException {

Response response = makeRequest(client(), "POST", String.format(Locale.getDefault(), "%s/_search", url), Collections.emptyMap(), new StringEntity(request), new BasicHeader("Content-Type", "application/json"));
Assert.assertEquals("Workflow search failed", RestStatus.OK, restStatus(response));

SearchResponse searchResponse = SearchResponse.fromXContent(createParser(JsonXContent.jsonXContent, response.getEntity().getContent()));

return Arrays.asList(searchResponse.getHits().getHits());
}

protected SearchResponse executeSearchAndGetResponse(String index, String request, Boolean refresh) throws IOException {
if (refresh) {
refreshIndex(index);
Expand Down