diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/common/TIFMetadata.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/common/TIFMetadata.java
index c6e8d78e8..04486fb7a 100644
--- a/src/main/java/org/opensearch/securityanalytics/threatIntel/common/TIFMetadata.java
+++ b/src/main/java/org/opensearch/securityanalytics/threatIntel/common/TIFMetadata.java
@@ -14,9 +14,8 @@
import org.opensearch.core.xcontent.*;
/**
- * Threat intel tif job metadata object
- *
- * TIFMetadata is stored in an external endpoint. OpenSearch read the file and store values it in this object.
+ * POJO containing Threat Intel Feed Metadata
+ * Contains all the data necessary to fetch and parse threat intel IoC feeds.
*/
public class TIFMetadata implements Writeable, ToXContent {
diff --git a/src/test/java/org/opensearch/securityanalytics/DetectorThreatIntelIT.java b/src/test/java/org/opensearch/securityanalytics/DetectorThreatIntelIT.java
index 49878da80..918f77f1f 100644
--- a/src/test/java/org/opensearch/securityanalytics/DetectorThreatIntelIT.java
+++ b/src/test/java/org/opensearch/securityanalytics/DetectorThreatIntelIT.java
@@ -58,8 +58,8 @@ public void testCreateDetectorWithThreatIntelEnabled_updateDetectorWithThreatInt
List detectorRules = List.of(new DetectorRule(randomDocRuleId));
DetectorInput input = new DetectorInput("windows detector for security analytics", List.of("windows"), detectorRules,
emptyList());
- DetectorTrigger trigger = new DetectorTrigger("all", "all", "high", List.of(randomDetectorType()), emptyList(), emptyList(),List.of(), emptyList(), List.of(DetectorTrigger.RULES_DETECTION_TYPE, DetectorTrigger.THREAT_INTEL_DETECTION_TYPE));
- Detector detector = randomDetectorWithInputsAndThreatIntelAndTriggers(List.of(input), true, List.of(trigger) );
+ DetectorTrigger trigger = new DetectorTrigger("all", "all", "high", List.of(randomDetectorType()), emptyList(), emptyList(), List.of(), emptyList(), List.of(DetectorTrigger.RULES_DETECTION_TYPE, DetectorTrigger.THREAT_INTEL_DETECTION_TYPE));
+ Detector detector = randomDetectorWithInputsAndThreatIntelAndTriggers(List.of(input), true, List.of(trigger));
Response createResponse = makeRequest(client(), "POST", SecurityAnalyticsPlugin.DETECTOR_BASE_URI, Collections.emptyMap(), toHttpEntity(detector));
String request = "{\n" +
@@ -122,7 +122,7 @@ public void testCreateDetectorWithThreatIntelEnabled_updateDetectorWithThreatInt
params.put("detector_id", detectorId);
Response getAlertsResponse = makeRequest(client(), "GET", SecurityAnalyticsPlugin.ALERTS_BASE_URI, params, null);
Map getAlertsBody = asMap(getAlertsResponse);
- // TODO enable asserts here when able
+
Assert.assertEquals(3, getAlertsBody.get("total_alerts"));
// update detector
@@ -132,7 +132,7 @@ public void testCreateDetectorWithThreatIntelEnabled_updateDetectorWithThreatInt
Map updateResponseBody = asMap(updateResponse);
for (String ioc : iocs) {
- indexDoc(index, i+"", randomDocWithIpIoc(5, 3, ioc));
+ indexDoc(index, i + "", randomDocWithIpIoc(5, 3, ioc));
i++;
}
@@ -227,9 +227,9 @@ public void testCreateDetectorWiththreatIntelDisabled_updateDetectorWithThreatIn
Map updateResponseBody = asMap(updateResponse);
List iocs = getThreatIntelFeedIocs(3);
- int i=2;
+ int i = 2;
for (String ioc : iocs) {
- indexDoc(index, i+"", randomDocWithIpIoc(5, 3, ioc));
+ indexDoc(index, i + "", randomDocWithIpIoc(5, 3, ioc));
i++;
}
executeResponse = executeAlertingWorkflow(workflowId, Collections.emptyMap());
@@ -241,4 +241,286 @@ public void testCreateDetectorWiththreatIntelDisabled_updateDetectorWithThreatIn
noOfSigmaRuleMatches = docLevelQueryResults.size();
assertEquals(2, noOfSigmaRuleMatches);
}
+
+ public void testCreateDetectorWithThreatIntelEnabledAndNoRules_triggerDetectionTypeOnlyRules_noAlertsForFindings() throws IOException {
+
+ updateClusterSetting(ENABLE_WORKFLOW_USAGE.getKey(), "true");
+ String index = createTestIndex(randomIndex(), windowsIndexMapping());
+
+ // Execute CreateMappingsAction to add alias mapping for index
+ Request createMappingRequest = new Request("POST", SecurityAnalyticsPlugin.MAPPER_BASE_URI);
+ // both req params and req body are supported
+ createMappingRequest.setJsonEntity(
+ "{ \"index_name\":\"" + index + "\"," +
+ " \"rule_topic\":\"" + randomDetectorType() + "\", " +
+ " \"partial\":true" +
+ "}"
+ );
+
+ Response createMappingResponse = client().performRequest(createMappingRequest);
+
+ assertEquals(HttpStatus.SC_OK, createMappingResponse.getStatusLine().getStatusCode());
+
+ String testOpCode = "Test";
+
+
+ List detectorRules = emptyList();
+ DetectorInput input = new DetectorInput("windows detector for security analytics", List.of("windows"), detectorRules,
+ emptyList());
+ DetectorTrigger trigger = new DetectorTrigger("all", "all", "high", List.of(randomDetectorType()), emptyList(), emptyList(), List.of(), emptyList(), List.of(DetectorTrigger.RULES_DETECTION_TYPE));
+ Detector detector = randomDetectorWithInputsAndThreatIntelAndTriggers(List.of(input), true, List.of(trigger));
+ Response createResponse = makeRequest(client(), "POST", SecurityAnalyticsPlugin.DETECTOR_BASE_URI, Collections.emptyMap(), toHttpEntity(detector));
+
+ String request = "{\n" +
+ " \"query\" : {\n" +
+ " \"match_all\":{\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ SearchResponse response = executeSearchAndGetResponse(DetectorMonitorConfig.getRuleIndex(randomDetectorType()), request, true);
+
+
+ assertEquals(1, response.getHits().getTotalHits().value);
+
+ assertEquals("Create detector failed", RestStatus.CREATED, restStatus(createResponse));
+ Map responseBody = asMap(createResponse);
+
+ String detectorId = responseBody.get("_id").toString();
+ request = "{\n" +
+ " \"query\" : {\n" +
+ " \"match\":{\n" +
+ " \"_id\": \"" + detectorId + "\"\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ List hits = executeSearch(Detector.DETECTORS_INDEX, request);
+ SearchHit hit = hits.get(0);
+ Map detectorMap = (HashMap) (hit.getSourceAsMap().get("detector"));
+ List inputArr = (List) detectorMap.get("inputs");
+
+
+ List monitorIds = ((List) (detectorMap).get("monitor_id"));
+ assertEquals(1, monitorIds.size());
+
+ assertNotNull("Workflow not created", detectorMap.get("workflow_ids"));
+ assertEquals("Number of workflows not correct", 1, ((List) detectorMap.get("workflow_ids")).size());
+
+ // Verify workflow
+ verifyWorkflow(detectorMap, monitorIds, 1);
+ List iocs = getThreatIntelFeedIocs(3);
+ int i = 1;
+ for (String ioc : iocs) {
+ indexDoc(index, i + "", randomDocWithIpIoc(5, 3, ioc));
+ i++;
+ }
+ String workflowId = ((List) detectorMap.get("workflow_ids")).get(0);
+
+ Response executeResponse = executeAlertingWorkflow(workflowId, Collections.emptyMap());
+
+ List