Skip to content

Commit

Permalink
Added integ test.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Jul 25, 2024
1 parent 7c9ef8c commit 23691da
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.Assert;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.commons.alerting.model.IntervalSchedule;
Expand Down Expand Up @@ -413,6 +414,24 @@ public void testCreateThreatIntelMonitor() throws IOException {
assertEquals(totalHitsVal.intValue(), 0);
}

public void testCreateThreatIntelMonitor_invalidMonitorJson() throws IOException {
ThreatIntelMonitorDto iocScanMonitor = randomIocScanMonitorDto("test-index");

String monitorJson = iocScanMonitor.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).toString();
final String invalidMonitorJson = monitorJson.replace("\"interval\":1", "\"interval\":100000000000000000000000000000000000000");

ResponseException exception = Assert.assertThrows(ResponseException.class,
() -> makeRequest(
client(),
"POST", SecurityAnalyticsPlugin.THREAT_INTEL_MONITOR_URI,
Collections.emptyMap(),
new StringEntity(invalidMonitorJson, ContentType.APPLICATION_JSON)
)
);
Assert.assertTrue(exception.getMessage().contains("Failed to parse threat intel monitor: "));
Assert.assertTrue(exception.getMessage().contains("\"status\":400"));
}

public static String getMatchAllRequest() {
return "{\n" +
" \"query\" : {\n" +
Expand Down

0 comments on commit 23691da

Please sign in to comment.