Skip to content

Commit 50de532

Browse files
committed
test: move test_cim_report.py to unit tests (#554)
1 parent c7caa68 commit 50de532

File tree

2 files changed

+138
-82
lines changed

2 files changed

+138
-82
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
3+
from pytest_splunk_addon.standard_lib.cim_compliance.cim_report_generator import (
4+
CIMReportGenerator,
5+
)
6+
7+
8+
def test_report():
9+
data = [
10+
{
11+
"data_model": "Change",
12+
"fields": "action",
13+
"fields_type": "required",
14+
"data_set": "All_Changes",
15+
"tag_stanza": "tag_stanza_1",
16+
"status": "passed",
17+
"test_property": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18+
},
19+
{
20+
"data_model": "Authentication",
21+
"fields": "change_type",
22+
"fields_type": "required",
23+
"data_set": "Default_Authentication",
24+
"tag_stanza": "file_authentication",
25+
"status": "skipped",
26+
"test_property": "-",
27+
},
28+
{
29+
"data_model": "Network_Traffic",
30+
"fields": "command",
31+
"fields_type": "conditional",
32+
"data_set": "All_Traffic",
33+
"tag_stanza": "event_traffic",
34+
"status": "failed",
35+
"test_property": "AssertionError: Field command is not extracted in any events.",
36+
},
37+
{
38+
"data_model": "Malware",
39+
"fields": "dest",
40+
"fields_type": "required",
41+
"data_set": "Malware_Attacks",
42+
"tag_stanza": "file_integrity_monitoring",
43+
"status": "passed",
44+
"test_property": "-",
45+
},
46+
]
47+
cim_report_gen = CIMReportGenerator(data)
48+
cim_report_gen.generate_report("test_report.md")
49+
50+
with open("test_report.md") as inputfile:
51+
test_data = inputfile.read()
52+
with open(
53+
os.path.join(os.path.dirname(__file__), "test_data", "sample_cim_report.md"),
54+
) as input_file:
55+
actual_data = input_file.read()
56+
assert test_data == actual_data
Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
# CIM AUDIT REPORT
2-
3-
## Summary
4-
5-
**Description:** Displays test case summary of the add-on for all the supported data models.
6-
7-
| Data Model | Status | Fail/Total |
8-
|:----------|:------|:---------- |
9-
| Alerts | N/A | - |
10-
| Authentication | Passed | 0/1 |
11-
| Certificates | N/A | - |
12-
| Change | Passed | 0/1 |
13-
| DLP | N/A | - |
14-
| Email | N/A | - |
15-
| Endpoint | N/A | - |
16-
| Intrusion_Detection | N/A | - |
17-
| Malware | Passed | 0/1 |
18-
| Network_Resolution | N/A | - |
19-
| Network_Sessions | N/A | - |
20-
| Network_Traffic | Failed | 1/1 |
21-
| Updates | N/A | - |
22-
| Vulnerabilities | N/A | - |
23-
| Web | N/A | - |
24-
25-
26-
## Tag Stanza Mapping
27-
28-
**Description:** Displays test case summary for the stanzas in tags.conf and the data model mapped with it.
29-
30-
| Tag Stanza | Data Model | Data Set | Fail/Total |
31-
|:----------|:----------|:--------|:---------- |
32-
| file_authentication | Authentication | Default_Authentication | 0/1 |
33-
| tag_stanza_1 | Change | All_Changes | 0/1 |
34-
| file_integrity_monitoring | Malware | Malware_Attacks | 0/1 |
35-
| event_traffic | Network_Traffic | All_Traffic | 1/1 |
36-
37-
38-
## Field Summary
39-
40-
**Description:** Displays test case summary for all the fields in the dataset for the tag-stanza it is mapped with.
41-
### file_authentication - Default_Authentication
42-
| Field | Type | Test Status | Failure Message |
43-
|:-----|:----|:-----------|:--------------- |
44-
| change_type | required | Skipped | - |
45-
46-
### tag_stanza_1 - All_Changes
47-
| Field | Type | Test Status | Failure Message |
48-
|:-----|:----|:-----------|:--------------- |
49-
| action | required | Passed | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
50-
51-
### file_integrity_monitoring - Malware_Attacks
52-
| Field | Type | Test Status | Failure Message |
53-
|:-----|:----|:-----------|:--------------- |
54-
| dest | required | Passed | - |
55-
56-
### event_traffic - All_Traffic
57-
| Field | Type | Test Status | Failure Message |
58-
|:-----|:----|:-----------|:--------------- |
59-
| command | conditional | Failed | AssertionError: Field command is not extracted in any events. |
60-
61-
62-
## Skipped Tests Summary
63-
64-
| Tag Stanza | Data Set | Field |
65-
|:----------|:--------|:----- |
66-
| file_authentication | Default_Authentication | change_type |
67-
68-
### Not Supported Datamodels
69-
| Name |
70-
|:---- |
71-
| Application_State |
72-
| Change_Analysis |
73-
| Compute_Inventory |
74-
| Databases |
75-
| Event_Signatures |
76-
| Interprocess_Messaging |
77-
| JVM |
78-
| Performance |
79-
| Splunk_Audit |
80-
| Splunk_CIM_Validation |
81-
| Ticket_Management |
82-
1+
# CIM AUDIT REPORT
2+
3+
## Summary
4+
5+
**Description:** Displays test case summary of the add-on for all the supported data models.
6+
7+
| Data Model | Status | Fail/Total |
8+
|:----------|:------|:---------- |
9+
| Alerts | N/A | - |
10+
| Authentication | Passed | 0/1 |
11+
| Certificates | N/A | - |
12+
| Change | Passed | 0/1 |
13+
| DLP | N/A | - |
14+
| Email | N/A | - |
15+
| Endpoint | N/A | - |
16+
| Intrusion_Detection | N/A | - |
17+
| Malware | Passed | 0/1 |
18+
| Network_Resolution | N/A | - |
19+
| Network_Sessions | N/A | - |
20+
| Network_Traffic | Failed | 1/1 |
21+
| Updates | N/A | - |
22+
| Vulnerabilities | N/A | - |
23+
| Web | N/A | - |
24+
25+
26+
## Tag Stanza Mapping
27+
28+
**Description:** Displays test case summary for the stanzas in tags.conf and the data model mapped with it.
29+
30+
| Tag Stanza | Data Model | Data Set | Fail/Total |
31+
|:----------|:----------|:--------|:---------- |
32+
| file_authentication | Authentication | Default_Authentication | 0/1 |
33+
| tag_stanza_1 | Change | All_Changes | 0/1 |
34+
| file_integrity_monitoring | Malware | Malware_Attacks | 0/1 |
35+
| event_traffic | Network_Traffic | All_Traffic | 1/1 |
36+
37+
38+
## Field Summary
39+
40+
**Description:** Displays test case summary for all the fields in the dataset for the tag-stanza it is mapped with.
41+
### file_authentication - Default_Authentication
42+
| Field | Type | Test Status | Failure Message |
43+
|:-----|:----|:-----------|:--------------- |
44+
| change_type | required | Skipped | - |
45+
46+
### tag_stanza_1 - All_Changes
47+
| Field | Type | Test Status | Failure Message |
48+
|:-----|:----|:-----------|:--------------- |
49+
| action | required | Passed | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
50+
51+
### file_integrity_monitoring - Malware_Attacks
52+
| Field | Type | Test Status | Failure Message |
53+
|:-----|:----|:-----------|:--------------- |
54+
| dest | required | Passed | - |
55+
56+
### event_traffic - All_Traffic
57+
| Field | Type | Test Status | Failure Message |
58+
|:-----|:----|:-----------|:--------------- |
59+
| command | conditional | Failed | AssertionError: Field command is not extracted in any events. |
60+
61+
62+
## Skipped Tests Summary
63+
64+
| Tag Stanza | Data Set | Field |
65+
|:----------|:--------|:----- |
66+
| file_authentication | Default_Authentication | change_type |
67+
68+
### Not Supported Datamodels
69+
| Name |
70+
|:---- |
71+
| Application_State |
72+
| Change_Analysis |
73+
| Compute_Inventory |
74+
| Databases |
75+
| Event_Signatures |
76+
| Interprocess_Messaging |
77+
| JVM |
78+
| Performance |
79+
| Splunk_Audit |
80+
| Splunk_CIM_Validation |
81+
| Ticket_Management |
82+

0 commit comments

Comments
 (0)