Skip to content

Commit ccfdd64

Browse files
committed
Capture & Replay Integration Test for TestService
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 8952285 commit ccfdd64

File tree

2 files changed

+153
-4
lines changed

2 files changed

+153
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,75 @@
11
package io.securecodebox.persistence.defectdojo.service;
22

3-
import org.junit.jupiter.api.Test;
43

5-
import static org.junit.jupiter.api.Assertions.*;
4+
import io.securecodebox.persistence.defectdojo.model.Test;
5+
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
9+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
610
import static org.hamcrest.MatcherAssert.assertThat;
7-
import static org.hamcrest.Matchers.*;
11+
import static org.hamcrest.Matchers.containsInAnyOrder;
12+
import static org.hamcrest.Matchers.hasSize;
13+
import static org.junit.jupiter.api.Assertions.assertAll;
814

915
/**
1016
* Tests for {@link TestService}
1117
*/
1218
final class TestServiceTest extends WireMockBaseTestCase {
1319
private final TestService sut = new TestService(conf());
20+
21+
@org.junit.jupiter.api.Test
22+
void search() throws URISyntaxException, IOException {
23+
stubFor(
24+
get("/api/v2/tests/?offset=0&limit=100")
25+
.willReturn(
26+
ok()
27+
.withBody(readResponseBodyFromFixture("TestService_response_fixture.json"))
28+
)
29+
);
30+
31+
final var result = sut.search();
32+
33+
assertAll(
34+
() -> assertThat(result, hasSize(3)),
35+
() -> assertThat(result, containsInAnyOrder(
36+
Test.builder()
37+
.id(1)
38+
.title("nuclei-owasp.org-1709280838-nmap-hostscan-6ckh4-nmap-su466fl")
39+
.description("# Nuclei Scan\nStarted: 01.03.2024 10:04:54\nEnded: 01.03.2024 15:06:30\nScanType: nuclei\nParameters: [-disable-update-check,-no-interactsh,-u,api.tokengate.dlt.owasp.org:443]")
40+
.targetStart("2024-03-01T10:04:54Z")
41+
.targetEnd("2024-03-01T15:06:29Z")
42+
.testType(67)
43+
.lead(3)
44+
.percentComplete(100)
45+
.engagement(1)
46+
.environment(1)
47+
.build(),
48+
Test.builder()
49+
.id(2)
50+
.title("nuclei-owasp.org-1709280838-nmap-hostscan-7xd2c-nuclei-5gzps")
51+
.description("# Nuclei Scan\nStarted: 01.03.2024 08:47:33\nEnded: 01.03.2024 15:06:34\nScanType: nuclei\nParameters: [-disable-update-check,-no-interactsh,-u,api.tokengate-dev.dlt.owasp.org]")
52+
.targetStart("2024-03-01T08:47:33Z")
53+
.targetEnd("2024-03-01T15:06:34Z")
54+
.testType(42)
55+
.lead(23)
56+
.percentComplete(43)
57+
.engagement(2)
58+
.environment(3)
59+
.build(),
60+
Test.builder()
61+
.id(3)
62+
.title("nuclei-owasp.org-1709280838-nmap-hostscan-6ckh4-nmap-sub6l7l")
63+
.description("# Nuclei Scan\nStarted: 01.03.2024 10:04:54\nEnded: 01.03.2024 15:06:35\nScanType: nuclei\nParameters: [-disable-update-check,-no-interactsh,-u,api.tokengate.dlt.owasp.org]")
64+
.targetStart("2024-03-01T10:04:54Z")
65+
.targetEnd("2024-03-01T15:06:35Z")
66+
.testType(67)
67+
.lead(3)
68+
.percentComplete(100)
69+
.engagement(1)
70+
.environment(1)
71+
.build()
72+
))
73+
);
74+
}
1475
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,89 @@
1-
{}
1+
{
2+
"count": 3,
3+
"next": null,
4+
"previous": null,
5+
"results": [
6+
{
7+
"id": 1,
8+
"tags": [],
9+
"test_type_name": "Nuclei Scan",
10+
"finding_groups": [],
11+
"scan_type": null,
12+
"title": "nuclei-owasp.org-1709280838-nmap-hostscan-6ckh4-nmap-su466fl",
13+
"description": "# Nuclei Scan\nStarted: 01.03.2024 10:04:54\nEnded: 01.03.2024 15:06:30\nScanType: nuclei\nParameters: [-disable-update-check,-no-interactsh,-u,api.tokengate.dlt.owasp.org:443]",
14+
"target_start": "2024-03-01T10:04:54Z",
15+
"target_end": "2024-03-01T15:06:29Z",
16+
"estimated_time": null,
17+
"actual_time": null,
18+
"percent_complete": 100,
19+
"updated": "2024-03-01T15:06:30.457382Z",
20+
"created": "2024-03-01T15:06:30.134001Z",
21+
"version": null,
22+
"build_id": null,
23+
"commit_hash": null,
24+
"branch_tag": null,
25+
"engagement": 1,
26+
"lead": 3,
27+
"test_type": 67,
28+
"environment": 1,
29+
"api_scan_configuration": null,
30+
"notes": [],
31+
"files": []
32+
},
33+
{
34+
"id": 2,
35+
"tags": [],
36+
"test_type_name": "Nuclei Scan",
37+
"finding_groups": [],
38+
"scan_type": null,
39+
"title": "nuclei-owasp.org-1709280838-nmap-hostscan-7xd2c-nuclei-5gzps",
40+
"description": "# Nuclei Scan\nStarted: 01.03.2024 08:47:33\nEnded: 01.03.2024 15:06:34\nScanType: nuclei\nParameters: [-disable-update-check,-no-interactsh,-u,api.tokengate-dev.dlt.owasp.org]",
41+
"target_start": "2024-03-01T08:47:33Z",
42+
"target_end": "2024-03-01T15:06:34Z",
43+
"estimated_time": null,
44+
"actual_time": null,
45+
"percent_complete": 43,
46+
"updated": "2024-03-01T15:06:35.117041Z",
47+
"created": "2024-03-01T15:06:34.716895Z",
48+
"version": null,
49+
"build_id": null,
50+
"commit_hash": null,
51+
"branch_tag": null,
52+
"engagement": 2,
53+
"lead": 23,
54+
"test_type": 42,
55+
"environment": 3,
56+
"api_scan_configuration": null,
57+
"notes": [],
58+
"files": []
59+
},
60+
{
61+
"id": 3,
62+
"tags": [],
63+
"test_type_name": "Nuclei Scan",
64+
"finding_groups": [],
65+
"scan_type": null,
66+
"title": "nuclei-owasp.org-1709280838-nmap-hostscan-6ckh4-nmap-sub6l7l",
67+
"description": "# Nuclei Scan\nStarted: 01.03.2024 10:04:54\nEnded: 01.03.2024 15:06:35\nScanType: nuclei\nParameters: [-disable-update-check,-no-interactsh,-u,api.tokengate.dlt.owasp.org]",
68+
"target_start": "2024-03-01T10:04:54Z",
69+
"target_end": "2024-03-01T15:06:35Z",
70+
"estimated_time": null,
71+
"actual_time": null,
72+
"percent_complete": 100,
73+
"updated": "2024-03-01T15:06:35.985476Z",
74+
"created": "2024-03-01T15:06:35.695294Z",
75+
"version": null,
76+
"build_id": null,
77+
"commit_hash": null,
78+
"branch_tag": null,
79+
"engagement": 1,
80+
"lead": 3,
81+
"test_type": 67,
82+
"environment": 1,
83+
"api_scan_configuration": null,
84+
"notes": [],
85+
"files": []
86+
}
87+
],
88+
"prefetch": {}
89+
}

0 commit comments

Comments
 (0)