Skip to content

Commit 98577a9

Browse files
WeltraumschafZero3141
authored andcommitted
#51 Reformatting
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 42f18ba commit 98577a9

File tree

3 files changed

+134
-130
lines changed

3 files changed

+134
-130
lines changed

src/test/java/io/securecodebox/persistence/defectdojo/service/FindingServiceTest.java

Lines changed: 107 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,126 +8,128 @@
88
import io.securecodebox.persistence.defectdojo.config.Config;
99

1010
import java.net.URISyntaxException;
11+
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Test;
1314
import org.springframework.test.web.client.MockRestServiceServer;
14-
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
15-
1615

16+
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
1717

1818

1919
import static org.junit.jupiter.api.Assertions.*;
20+
2021
import org.springframework.http.MediaType;
22+
2123
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
2224

2325

2426
// This test is sufficient for all services (except user profile) as all the code is generic
25-
class FindingServiceTest{
27+
class FindingServiceTest {
2628

2729
Config config;
2830
FindingService underTest;
2931
MockRestServiceServer mockServer;
3032

3133
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+
""";
131133

132134
@BeforeEach
133135
void setup() {
@@ -145,12 +147,12 @@ void deserializeList() throws JsonProcessingException {
145147

146148
@Test
147149
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";
149151
mockServer.expect(requestTo(url)).andRespond(withSuccess(findingResponse, MediaType.APPLICATION_JSON));
150-
152+
151153
var expected = underTest.deserializeList(findingResponse).getResults();
152154
var actual = underTest.search();
153-
155+
154156
mockServer.verify();
155157
assertIterableEquals(expected, actual);
156158
}

src/test/java/io/securecodebox/persistence/defectdojo/service/ImportScanServiceTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void createDefault_passesConfig() {
5050
void importScan_withoutOptionsShouldPassEmptyMap() {
5151
assertThat(sut.getOptions(), is(nullValue()));
5252

53-
sut.importScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
53+
sut.importScan(new ScanFile("content"), 42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
5454

5555
assertThat(sut.getOptions(), equalTo(Collections.EMPTY_MAP));
5656
}
@@ -59,7 +59,7 @@ void importScan_withoutOptionsShouldPassEmptyMap() {
5959
void importScan_withoutOptionsShouldPassModifiableMap() {
6060
assertThat(sut.getOptions(), is(nullValue()));
6161

62-
sut.importScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
62+
sut.importScan(new ScanFile("content"), 42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
6363
sut.getOptions().put("foo", "bar");
6464

6565
assertThat(sut.getOptions(), hasEntry("foo", "bar"));
@@ -69,7 +69,7 @@ void importScan_withoutOptionsShouldPassModifiableMap() {
6969
void reimportScan_withoutOptionsShouldPassEmptyMap() {
7070
assertThat(sut.getOptions(), is(nullValue()));
7171

72-
sut.reimportScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
72+
sut.reimportScan(new ScanFile("content"), 42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
7373

7474
assertThat(sut.getOptions(), equalTo(Collections.EMPTY_MAP));
7575
}
@@ -78,7 +78,7 @@ void reimportScan_withoutOptionsShouldPassEmptyMap() {
7878
void reimportScan_withoutOptionsShouldPassModifiableMap() {
7979
assertThat(sut.getOptions(), is(nullValue()));
8080

81-
sut.reimportScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
81+
sut.reimportScan(new ScanFile("content"), 42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
8282
sut.getOptions().put("foo", "bar");
8383

8484
assertThat(sut.getOptions(), hasEntry("foo", "bar"));

src/test/java/io/securecodebox/persistence/defectdojo/service/UserProfileServiceTest.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,58 @@
1313
import java.util.Arrays;
1414

1515
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
16+
1617
import org.junit.jupiter.api.BeforeEach;
1718
import org.junit.jupiter.api.Test;
1819
import org.springframework.http.MediaType;
1920
import org.springframework.test.web.client.MockRestServiceServer;
21+
2022
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
2123
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
2224

2325

2426
// This test is special because the defectdojo api does not return a list,
2527
// but the generic code assumes every endpoint returns a list
2628
public class UserProfileServiceTest {
27-
29+
2830
Config config;
2931
UserProfileService underTest;
3032
MockRestServiceServer mockServer;
31-
33+
3234
// This string does not contain every field of the api response as those are not implemented
3335
String apiResponse = """
34-
{
35-
"user": {
36-
"id": 0,
37-
"username": "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0",
38-
"first_name": "string",
39-
"last_name": "string",
40-
"email": "user@example.com",
41-
"last_login": "2022-11-01T16:20:19.373Z",
42-
"is_active": true,
43-
"is_superuser": true,
44-
"configuration_permissions": [0]
45-
}
46-
}
47-
""";
48-
36+
{
37+
"user": {
38+
"id": 0,
39+
"username": "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0",
40+
"first_name": "string",
41+
"last_name": "string",
42+
"email": "user@example.com",
43+
"last_login": "2022-11-01T16:20:19.373Z",
44+
"is_active": true,
45+
"is_superuser": true,
46+
"configuration_permissions": [0]
47+
}
48+
}
49+
""";
50+
4951
@BeforeEach
5052
void setup() {
5153
config = new Config("https://defectdojo.example.com", "abc", 42);
5254
underTest = new UserProfileService(config);
5355
mockServer = MockRestServiceServer.createServer(underTest.getRestTemplate());
5456
}
55-
57+
5658
@Test
5759
void testSearch() throws JsonProcessingException, URISyntaxException {
58-
var url = config.getUrl() + "/api/v2/" + underTest.getUrlPath() + "/?offset=0&limit=100";
60+
var url = config.getUrl() + "/api/v2/" + underTest.getUrlPath() + "/?offset=0&limit=100";
5961
mockServer.expect(requestTo(url)).andRespond(withSuccess(apiResponse, MediaType.APPLICATION_JSON));
60-
62+
6163
var user = new User(0L, "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", "string", "string");
6264
var userProfile = new UserProfile(user);
6365
var expected = Arrays.asList(userProfile);
6466
var actual = underTest.search();
65-
67+
6668
mockServer.verify();
6769
assertIterableEquals(expected, actual);
6870
}

0 commit comments

Comments
 (0)