8
8
import io .securecodebox .persistence .defectdojo .config .Config ;
9
9
10
10
import java .net .URISyntaxException ;
11
+
11
12
import org .junit .jupiter .api .BeforeEach ;
12
13
import org .junit .jupiter .api .Test ;
13
14
import org .springframework .test .web .client .MockRestServiceServer ;
14
- import static org .springframework .test .web .client .response .MockRestResponseCreators .withSuccess ;
15
-
16
15
16
+ import static org .springframework .test .web .client .response .MockRestResponseCreators .withSuccess ;
17
17
18
18
19
19
import static org .junit .jupiter .api .Assertions .*;
20
+
20
21
import org .springframework .http .MediaType ;
22
+
21
23
import static org .springframework .test .web .client .match .MockRestRequestMatchers .requestTo ;
22
24
23
25
24
26
// This test is sufficient for all services (except user profile) as all the code is generic
25
- class FindingServiceTest {
27
+ class FindingServiceTest {
26
28
27
29
Config config ;
28
30
FindingService underTest ;
29
31
MockRestServiceServer mockServer ;
30
32
31
33
String findingResponse = """
32
- {
33
- "count": 1,
34
- "next": null,
35
- "previous": null,
36
- "results":
37
- [
38
- {
39
- "id": 42,
40
- "tags": [],
41
- "request_response": {
42
- "req_resp": []
43
- },
44
- "accepted_risks": [],
45
- "push_to_jira": false,
46
- "age": 145,
47
- "sla_days_remaining": null,
48
- "finding_meta": [],
49
- "related_fields": null,
50
- "jira_creation": null,
51
- "jira_change": null,
52
- "display_status": "Active, Verified",
53
- "finding_groups": [],
54
- "title": "Open Port: 9929/TCP",
55
- "date": "2021-03-18",
56
- "sla_start_date": null,
57
- "cwe": 0,
58
- "cve": null,
59
- "cvssv3": null,
60
- "cvssv3_score": null,
61
- "url": null,
62
- "severity": "Info",
63
- "description": "### Host\\ n\\ n**IP Address:** 198.51.100.0\\ n**FQDN:** scanme.nmap.org\\ n\\ n\\ n**Port/Protocol:** 9929/tcp\\ n\\ n\\ n\\ n\\ n",
64
- "mitigation": "N/A",
65
- "impact": "No impact provided",
66
- "steps_to_reproduce": null,
67
- "severity_justification": null,
68
- "references": null,
69
- "is_template": false,
70
- "active": true,
71
- "verified": true,
72
- "false_p": false,
73
- "duplicate": false,
74
- "out_of_scope": false,
75
- "risk_accepted": false,
76
- "under_review": false,
77
- "last_status_update": "2021-07-21T12:43:36.628994Z",
78
- "under_defect_review": false,
79
- "is_mitigated": false,
80
- "thread_id": 0,
81
- "mitigated": null,
82
- "numerical_severity": "S4",
83
- "last_reviewed": "2021-07-21T12:43:36.545348Z",
84
- "line_number": null,
85
- "sourcefilepath": null,
86
- "sourcefile": null,
87
- "param": null,
88
- "payload": null,
89
- "hash_code": "8dbaad23d4056f0a97bb8f487795fe392b4124f28d4049d16430e43415f1c219",
90
- "line": null,
91
- "file_path": null,
92
- "component_name": null,
93
- "component_version": null,
94
- "static_finding": false,
95
- "dynamic_finding": true,
96
- "created": "2021-07-21T12:43:36.549669Z",
97
- "scanner_confidence": null,
98
- "unique_id_from_tool": null,
99
- "vuln_id_from_tool": null,
100
- "sast_source_object": null,
101
- "sast_sink_object": null,
102
- "sast_source_line": null,
103
- "sast_source_file_path": null,
104
- "nb_occurences": null,
105
- "publish_date": null,
106
- "test": 222,
107
- "duplicate_finding": null,
108
- "review_requested_by": null,
109
- "defect_review_requested_by": null,
110
- "mitigated_by": null,
111
- "reporter": 5,
112
- "last_reviewed_by": 5,
113
- "sonarqube_issue": null,
114
- "endpoints": [
115
- 875
116
- ],
117
- "endpoint_status": [
118
- 8640
119
- ],
120
- "reviewers": [],
121
- "notes": [],
122
- "files": [],
123
- "found_by": [
124
- 132
125
- ]
126
- }
127
- ],
128
- "prefetch": {}
129
- }
130
- """ ;
34
+ {
35
+ "count": 1,
36
+ "next": null,
37
+ "previous": null,
38
+ "results":
39
+ [
40
+ {
41
+ "id": 42,
42
+ "tags": [],
43
+ "request_response": {
44
+ "req_resp": []
45
+ },
46
+ "accepted_risks": [],
47
+ "push_to_jira": false,
48
+ "age": 145,
49
+ "sla_days_remaining": null,
50
+ "finding_meta": [],
51
+ "related_fields": null,
52
+ "jira_creation": null,
53
+ "jira_change": null,
54
+ "display_status": "Active, Verified",
55
+ "finding_groups": [],
56
+ "title": "Open Port: 9929/TCP",
57
+ "date": "2021-03-18",
58
+ "sla_start_date": null,
59
+ "cwe": 0,
60
+ "cve": null,
61
+ "cvssv3": null,
62
+ "cvssv3_score": null,
63
+ "url": null,
64
+ "severity": "Info",
65
+ "description": "### Host\\ n\\ n**IP Address:** 198.51.100.0\\ n**FQDN:** scanme.nmap.org\\ n\\ n\\ n**Port/Protocol:** 9929/tcp\\ n\\ n\\ n\\ n\\ n",
66
+ "mitigation": "N/A",
67
+ "impact": "No impact provided",
68
+ "steps_to_reproduce": null,
69
+ "severity_justification": null,
70
+ "references": null,
71
+ "is_template": false,
72
+ "active": true,
73
+ "verified": true,
74
+ "false_p": false,
75
+ "duplicate": false,
76
+ "out_of_scope": false,
77
+ "risk_accepted": false,
78
+ "under_review": false,
79
+ "last_status_update": "2021-07-21T12:43:36.628994Z",
80
+ "under_defect_review": false,
81
+ "is_mitigated": false,
82
+ "thread_id": 0,
83
+ "mitigated": null,
84
+ "numerical_severity": "S4",
85
+ "last_reviewed": "2021-07-21T12:43:36.545348Z",
86
+ "line_number": null,
87
+ "sourcefilepath": null,
88
+ "sourcefile": null,
89
+ "param": null,
90
+ "payload": null,
91
+ "hash_code": "8dbaad23d4056f0a97bb8f487795fe392b4124f28d4049d16430e43415f1c219",
92
+ "line": null,
93
+ "file_path": null,
94
+ "component_name": null,
95
+ "component_version": null,
96
+ "static_finding": false,
97
+ "dynamic_finding": true,
98
+ "created": "2021-07-21T12:43:36.549669Z",
99
+ "scanner_confidence": null,
100
+ "unique_id_from_tool": null,
101
+ "vuln_id_from_tool": null,
102
+ "sast_source_object": null,
103
+ "sast_sink_object": null,
104
+ "sast_source_line": null,
105
+ "sast_source_file_path": null,
106
+ "nb_occurences": null,
107
+ "publish_date": null,
108
+ "test": 222,
109
+ "duplicate_finding": null,
110
+ "review_requested_by": null,
111
+ "defect_review_requested_by": null,
112
+ "mitigated_by": null,
113
+ "reporter": 5,
114
+ "last_reviewed_by": 5,
115
+ "sonarqube_issue": null,
116
+ "endpoints": [
117
+ 875
118
+ ],
119
+ "endpoint_status": [
120
+ 8640
121
+ ],
122
+ "reviewers": [],
123
+ "notes": [],
124
+ "files": [],
125
+ "found_by": [
126
+ 132
127
+ ]
128
+ }
129
+ ],
130
+ "prefetch": {}
131
+ }
132
+ """ ;
131
133
132
134
@ BeforeEach
133
135
void setup () {
@@ -145,12 +147,12 @@ void deserializeList() throws JsonProcessingException {
145
147
146
148
@ Test
147
149
void testSearch () throws JsonProcessingException , URISyntaxException {
148
- var url = config .getUrl () + "/api/v2/" + underTest .getUrlPath () + "/?offset=0&limit=100" ;
150
+ var url = config .getUrl () + "/api/v2/" + underTest .getUrlPath () + "/?offset=0&limit=100" ;
149
151
mockServer .expect (requestTo (url )).andRespond (withSuccess (findingResponse , MediaType .APPLICATION_JSON ));
150
-
152
+
151
153
var expected = underTest .deserializeList (findingResponse ).getResults ();
152
154
var actual = underTest .search ();
153
-
155
+
154
156
mockServer .verify ();
155
157
assertIterableEquals (expected , actual );
156
158
}
0 commit comments