diff --git a/security-analytics-commons-1.0.0.jar b/security-analytics-commons-1.0.0.jar index 094a79102..27032468d 100644 Binary files a/security-analytics-commons-1.0.0.jar and b/security-analytics-commons-1.0.0.jar differ diff --git a/src/test/java/org/opensearch/securityanalytics/alerts/AlertsIT.java b/src/test/java/org/opensearch/securityanalytics/alerts/AlertsIT.java index 7eecaa3b7..d1b78fc3c 100644 --- a/src/test/java/org/opensearch/securityanalytics/alerts/AlertsIT.java +++ b/src/test/java/org/opensearch/securityanalytics/alerts/AlertsIT.java @@ -28,7 +28,6 @@ import org.opensearch.client.Request; import org.opensearch.client.Response; import org.opensearch.client.ResponseException; -import org.opensearch.commons.alerting.model.Monitor; import org.opensearch.commons.alerting.model.action.Action; import org.opensearch.core.rest.RestStatus; import org.opensearch.search.SearchHit; @@ -45,9 +44,7 @@ import static org.opensearch.securityanalytics.TestHelpers.netFlowMappings; import static org.opensearch.securityanalytics.TestHelpers.randomAction; import static org.opensearch.securityanalytics.TestHelpers.randomAggregationRule; -import static org.opensearch.securityanalytics.TestHelpers.randomDetector; import static org.opensearch.securityanalytics.TestHelpers.randomDetectorType; -import static org.opensearch.securityanalytics.TestHelpers.randomDetectorWithInputs; import static org.opensearch.securityanalytics.TestHelpers.randomDetectorWithInputsAndTriggers; import static org.opensearch.securityanalytics.TestHelpers.randomDetectorWithTriggers; import static org.opensearch.securityanalytics.TestHelpers.randomDoc; @@ -795,7 +792,7 @@ public void testAlertHistoryRollover_maxAge() throws IOException, InterruptedExc * * @throws IOException */ - public void testMultipleAggregationAndDocRules_alertSuccess() throws IOException { + public void testMultipleAggregationAndDocRules_alertSuccess() throws IOException, InterruptedException { String index = createTestIndex(randomIndex(), windowsIndexMapping()); Request createMappingRequest = new Request("POST", SecurityAnalyticsPlugin.MAPPER_BASE_URI); @@ -808,7 +805,7 @@ public void testMultipleAggregationAndDocRules_alertSuccess() throws IOException Response createMappingResponse = client().performRequest(createMappingRequest); - assertEquals(org.apache.http.HttpStatus.SC_OK, createMappingResponse.getStatusLine().getStatusCode()); + assertEquals(HttpStatus.SC_OK, createMappingResponse.getStatusLine().getStatusCode()); String infoOpCode = "Info"; @@ -949,17 +946,28 @@ public void testMultipleAggregationAndDocRules_alertSuccess() throws IOException } } - assertTrue(Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8").containsAll(docLevelFinding)); - - params1 = new HashMap<>(); - params1.put("detector_id", detectorId); - getAlertsResponse = makeRequest(client(), "GET", SecurityAnalyticsPlugin.ALERTS_BASE_URI, params1, null); - getAlertsBody = asMap(getAlertsResponse); - // TODO enable asserts here when able - Assert.assertEquals(2, getAlertsBody.get("total_alerts")); + AtomicBoolean alertRespStatus = new AtomicBoolean(false); + OpenSearchRestTestCase.waitUntil( + () -> { + Map queryParams = new HashMap<>(); + queryParams.put("detector_id", detectorId); + try { + Response alertsResponse = makeRequest(client(), "GET", SecurityAnalyticsPlugin.ALERTS_BASE_URI, queryParams, null); + Map alertsBody = asMap(alertsResponse); + // TODO enable asserts here when able + if (Integer.parseInt(alertsBody.get("total_alerts").toString()) == 2) { + alertRespStatus.set(true); + return true; + } + return false; + } catch (IOException e) { + return false; + } + }, 2, TimeUnit.MINUTES); + Assert.assertTrue(alertRespStatus.get()); } - public void test_detectorWith1AggRuleAndTriggeronRule_updateWithSecondAggRule() throws IOException { + public void test_detectorWith1AggRuleAndTriggeronRule_updateWithSecondAggRule() throws IOException, InterruptedException { String index = createTestIndex(randomIndex(), windowsIndexMapping()); Request createMappingRequest = new Request("POST", SecurityAnalyticsPlugin.MAPPER_BASE_URI); @@ -972,7 +980,7 @@ public void test_detectorWith1AggRuleAndTriggeronRule_updateWithSecondAggRule() Response createMappingResponse = client().performRequest(createMappingRequest); - assertEquals(org.apache.http.HttpStatus.SC_OK, createMappingResponse.getStatusLine().getStatusCode()); + assertEquals(HttpStatus.SC_OK, createMappingResponse.getStatusLine().getStatusCode()); String infoOpCode = "Info"; /** 1st agg rule*/ @@ -1071,11 +1079,24 @@ public void test_detectorWith1AggRuleAndTriggeronRule_updateWithSecondAggRule() assertNotNull(getFindingsBody); assertEquals(3, getFindingsBody.get("total_findings")); - params1 = new HashMap<>(); - params1.put("detector_id", detectorId); - getAlertsResponse = makeRequest(client(), "GET", SecurityAnalyticsPlugin.ALERTS_BASE_URI, params1, null); - getAlertsBody = asMap(getAlertsResponse); - Assert.assertEquals(3, getAlertsBody.get("total_alerts")); + AtomicBoolean alertsCondSatisfy = new AtomicBoolean(false); + OpenSearchRestTestCase.waitUntil( + () -> { + try { + Map queryParams = new HashMap<>(); + queryParams.put("detector_id", detectorId); + Response alertsResponse = makeRequest(client(), "GET", SecurityAnalyticsPlugin.ALERTS_BASE_URI, queryParams, null); + Map alertsBody = asMap(alertsResponse); + if (Integer.parseInt(alertsBody.get("total_alerts").toString()) == 3) { + alertsCondSatisfy.set(true); + } + return 3 == Integer.parseInt(alertsBody.get("total_alerts").toString()); + } catch (Exception e) { + return false; + } + }, 2, TimeUnit.MINUTES + ); + Assert.assertTrue(alertsCondSatisfy.get()); } @Ignore diff --git a/src/test/java/org/opensearch/securityanalytics/resthandler/ThreatIntelMonitorRestApiIT.java b/src/test/java/org/opensearch/securityanalytics/resthandler/ThreatIntelMonitorRestApiIT.java index 2a1f7fd85..720afd3fb 100644 --- a/src/test/java/org/opensearch/securityanalytics/resthandler/ThreatIntelMonitorRestApiIT.java +++ b/src/test/java/org/opensearch/securityanalytics/resthandler/ThreatIntelMonitorRestApiIT.java @@ -1,8 +1,8 @@ package org.opensearch.securityanalytics.resthandler; import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.io.entity.StringEntity; -import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Assert;