Skip to content

Commit

Permalink
fix mapper it tests
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep committed Jan 11, 2023
1 parent 0d1c796 commit 55fffbc
Show file tree
Hide file tree
Showing 30 changed files with 69 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/ad_ldap/fieldmappings.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fieldmappings:
TargetUserName: winlog-event_data-TargetUserName
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/ad_ldap/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "alias"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fieldmappings:
fieldB: mappedB
fieldA1: mappedA
CommandLine: windows-event_data-CommandLine
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/apache_access/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"path": "EventID"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/dns/fieldmappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ fieldmappings:
record_type: dns-answers-type
query: dns-question-name
parent_domain: dns-question-registered_domain
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/dns/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"path": "dns.question.registered_domain"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/linux/fieldmappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ fieldmappings:
ParentImage: process-parent-executable
CurrentDirectory: process-working_directory
LogonId: process-real_user-id
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/linux/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"type": "alias"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/network/NetFlowMapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "netflow.http_status_code"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/network/fieldmappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fieldmappings:
resp_mime_types: zeek-http-resp_mime_types
cipher: zeek-kerberos-cipher
request_type: zeek-kerberos-request_type
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/network/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"type": "alias"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "ServiceName"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/others_apt/fieldmappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/others_apt/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "ServiceName"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp
4 changes: 2 additions & 2 deletions src/main/resources/OSMapping/others_cloud/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"type": "alias",
"path": "ServiceName"
},
"@timestamp": {
"path": "@timestamp",
"creationTime": {
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "ServiceName"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/others_macos/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"path": "CommandLine"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/others_proxy/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "ServiceName"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/others_web/fieldmappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fieldmappings:
HiveName: unmapped.HiveName
fieldB: mappedB
fieldA1: mappedA
@timestamp: timestamp
creationTime: timestamp

2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/others_web/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "ServiceName"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fieldmappings:
Message: windows-message
Provider_Name: windows-provider-name
ServiceName: windows-servicename
@timestamp: timestamp
creationTime: timestamp
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/test_windows/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "ServiceName"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/windows/fieldmappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ fieldmappings:
windows-hostname: winlog-computer_name
windows-provider-name: winlog-provider_name
windows-servicename: winlog-event_data-ServiceName
@timestamp: timestamp
creationTime: timestamp

2 changes: 1 addition & 1 deletion src/main/resources/OSMapping/windows/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"type": "alias"
},
"timestamp": {
"path": "@timestamp",
"path": "creationTime",
"type": "alias"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void testCreateMappingSuccess() throws IOException {
// both req params and req body are supported
request.setJsonEntity(
"{ \"index_name\":\"" + testIndexName + "\"," +
" \"rule_topic\":\"netflow\", " +
" \"partial\":true" +
"}"
" \"rule_topic\":\"netflow\", " +
" \"partial\":true" +
"}"
);
Response response = client().performRequest(request);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
Expand Down Expand Up @@ -88,22 +88,22 @@ public void testCreateMappingWithAliasesSuccess() throws IOException {
// both req params and req body are supported
request.setJsonEntity(
"{\n" +
" \"index_name\": \"my_index\",\n" +
" \"rule_topic\":\"netflow\", " +
" \"partial\":true," +
" \"alias_mappings\": {\n" +
" \"properties\": {\n" +
" \"source.ip\": {\n" +
" \"type\": \"alias\",\n" +
" \"path\": \"netflow.source_ipv4_address\"\n" +
" },\n" +
" \"source.port\": {\n" +
" \"type\": \"alias\",\n" +
" \"path\": \"netflow.source_transport_port\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}"
" \"index_name\": \"my_index\",\n" +
" \"rule_topic\":\"netflow\", " +
" \"partial\":true," +
" \"alias_mappings\": {\n" +
" \"properties\": {\n" +
" \"source.ip\": {\n" +
" \"type\": \"alias\",\n" +
" \"path\": \"netflow.source_ipv4_address\"\n" +
" },\n" +
" \"source.port\": {\n" +
" \"type\": \"alias\",\n" +
" \"path\": \"netflow.source_transport_port\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}"
);
// request.addParameter("indexName", testIndexName);
// request.addParameter("ruleTopic", "netflow");
Expand Down Expand Up @@ -224,7 +224,7 @@ public void testExistingMappingsAreUntouched() throws IOException {
GetMappingsResponse getMappingsResponse = SecurityAnalyticsClientUtils.executeGetMappingsRequest(testIndexName);
Map<String, Object> properties =
(Map<String, Object>) getMappingsResponse.getMappings().get(testIndexName)
.getSourceAsMap().get("properties");
.getSourceAsMap().get("properties");
// Verify that there is still mapping for integer field "plain1"
assertTrue(((Map<String, Object>)properties.get("plain1")).get("type").equals("integer"));
}
Expand Down Expand Up @@ -291,7 +291,7 @@ public void testGetMappingsViewSuccess() throws IOException {
assertEquals(6, unmappedIndexFields.size());
// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(2, unmappedFieldAliases.size());
assertEquals(3, unmappedFieldAliases.size());
}

public void testCreateMappings_withIndexPattern_indexTemplate_createAndUpdate_success() throws IOException {
Expand Down Expand Up @@ -621,7 +621,7 @@ public void testGetMappingsView_index_pattern_two_indices_Success() throws IOExc
assertTrue(extraField.isPresent());
// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(2, unmappedFieldAliases.size());
assertEquals(3, unmappedFieldAliases.size());
}

public void testGetMappingsView_alias_without_writeindex_Success() throws IOException {
Expand Down Expand Up @@ -656,7 +656,7 @@ public void testGetMappingsView_alias_without_writeindex_Success() throws IOExce
assertTrue(extraField.isPresent());
// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(2, unmappedFieldAliases.size());
assertEquals(3, unmappedFieldAliases.size());
}

public void testGetMappingsView_alias_with_writeindex_Success() throws IOException {
Expand Down Expand Up @@ -694,7 +694,7 @@ public void testGetMappingsView_alias_with_writeindex_Success() throws IOExcepti
assertTrue(extraField.isPresent());
// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(2, unmappedFieldAliases.size());
assertEquals(3, unmappedFieldAliases.size());
}

public void testGetMappingsView_datastream_one_backing_index_Success() throws IOException {
Expand All @@ -721,7 +721,7 @@ public void testGetMappingsView_datastream_one_backing_index_Success() throws IO
assertEquals(7, unmappedIndexFields.size());
// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(2, unmappedFieldAliases.size());
assertEquals(3, unmappedFieldAliases.size());

deleteDatastream(datastreamName);
}
Expand Down Expand Up @@ -771,11 +771,10 @@ public void testGetMappingsView_datastream_two_backing_index_Success() throws IO
assertEquals(1, props.size());
assertTrue(props.containsKey("source.ip"));
// Verify unmapped index fields
List<String> unmappedIndexFields = (List<String>) respMap.get("unmapped_index_fields");
assertEquals(1, unmappedIndexFields.size());

// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(5, unmappedFieldAliases.size());
assertEquals(6, unmappedFieldAliases.size());

deleteDatastream(datastreamName);
}
Expand Down Expand Up @@ -856,20 +855,20 @@ private void createSampleIndex(String indexName, Settings settings, String alias
" \"keyword\":{" +
" \"type\":\"keyword\"," +
" \"ignore_above\":256" +
"}" +
"}" +
"}," +
"}" +
"}" +
"}," +
" \"last\":{" +
"\"type\":\"text\"," +
"\"fields\":{" +
"\"type\":\"text\"," +
"\"fields\":{" +
" \"keyword\":{" +
" \"type\":\"keyword\"," +
" \"ignore_above\":256" +
"}" +
"}" +
"}" +
"}" +
"}" +
"}" +
"}" +
"}" +
"}" +
"}" +
" }";

createIndex(indexName, settings, indexMapping, aliases);
Expand Down Expand Up @@ -1152,6 +1151,8 @@ public void testCreateDNSMapping() throws IOException{
//Loop over the mappings and run update request for each one specifying the index to be updated
mappings.entrySet().forEach(entry -> {
String key = entry.getKey();
if("timestamp".equals(key))
return;
String path = ((Map<String, Object>) entry.getValue()).get("path").toString();
try {
Request updateRequest = new Request("PUT", SecurityAnalyticsPlugin.MAPPER_BASE_URI);
Expand Down

0 comments on commit 55fffbc

Please sign in to comment.