Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
  • Loading branch information
petardz committed May 4, 2023
1 parent 59b0d1d commit 9ee8e6e
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,16 @@ public void testGetMappingSuccess_1() throws IOException {

indexDoc(testIndexName1, "1", sampleDoc);
// puts mappings with timestamp alias
String createMappingsRequest = "{\"index_name\":\"my_index*\",\"rule_topic\":\"windows\",\"partial\":true,\"alias_mappings\":{\"properties\":{\"timestamp\":{\"type\":\"alias\",\"path\":\"lvl1field\"},\"winlog-computer_name\":{\"type\":\"alias\",\"path\":\"source1.port\"},\"winlog-event_data-AuthenticationPackageName\":{\"type\":\"alias\",\"path\":\"source1.ip\"},\"winlog-event_data-Company\":{\"type\":\"alias\",\"path\":\"some.very.long.field.name\"}}}}";
String createMappingsRequest = "{\"index_name\":\"my_index*\",\"rule_topic\":\"windows\",\"partial\":true,\"alias_mappings\":{\"properties\":{\"timestamp\":{\"type\":\"alias\",\"path\":\"lvl1field\"},\"winlog.computer_name\":{\"type\":\"alias\",\"path\":\"source1.port\"},\"winlog.event_data.AuthenticationPackageName\":{\"type\":\"alias\",\"path\":\"source1.ip\"},\"winlog.event_data.Company\":{\"type\":\"alias\",\"path\":\"some.very.long.field.name\"}}}}";

Request request = new Request("POST", MAPPER_BASE_URI);
// both req params and req body are supported
request.setJsonEntity(createMappingsRequest);
Response response = client().performRequest(request);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

request = new Request("GET", MAPPER_BASE_URI + "?index_name=" + testIndexPattern);
response = client().performRequest(request);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
Map<String, Object> respMap = (Map<String, Object>) responseAsMap(response);
Map<String, Object> props = (Map<String, Object>)((Map<String, Object>) respMap.get(testIndexPattern)).get("mappings");
props = (Map<String, Object>) props.get("properties");
assertEquals(4, props.size());
Map<String, Object> appliedMappings = getIndexMappingsSAFlat(testIndexPattern);
assertEquals(4, appliedMappings.size());
}

public void testCreateMappingSuccess() throws IOException {
Expand Down Expand Up @@ -180,7 +175,7 @@ public void testCreateMappingWithAliasesSuccess() throws IOException {

// Verify mappings
GetMappingsResponse getMappingsResponse = SecurityAnalyticsClientUtils.executeGetMappingsRequest(testIndexName);
MappingsTraverser mappingsTraverser = new MappingsTraverser(getMappingsResponse.getMappings().iterator().next().value);
MappingsTraverser mappingsTraverser = new MappingsTraverser(getMappingsResponse.getMappings().entrySet().iterator().next().getValue());
List<String> flatProperties = mappingsTraverser.extractFlatNonAliasFields();
assertFalse(flatProperties.contains("source.ip"));
assertFalse(flatProperties.contains("source.port"));
Expand Down Expand Up @@ -1512,10 +1507,12 @@ public void testWindowsMappings() throws IOException {

indexDoc(indexName, "1", sampleDoc);

createMappingsAPI(indexName, Detector.DetectorType.WINDOWS.getDetectorType());

Map<String, Object> respMap = getIndexMappingsViewAPI(indexName, "windows");

assertFalse(respMap.containsKey("unmapped_index_fields"));

createMappingsAPI(indexName, Detector.DetectorType.WINDOWS.getDetectorType());

// Verify that all rules are working
DetectorInput input = new DetectorInput("windows detector for security analytics", List.of(indexName), List.of(),
getPrePackagedRules(Detector.DetectorType.WINDOWS.getDetectorType()).stream().map(DetectorRule::new).collect(Collectors.toList()));
Expand Down

0 comments on commit 9ee8e6e

Please sign in to comment.