Skip to content

Commit 8952285

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

File tree

2 files changed

+240
-4
lines changed

2 files changed

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

3+
import io.securecodebox.persistence.defectdojo.model.Product;
34
import org.junit.jupiter.api.Test;
45

5-
import static org.junit.jupiter.api.Assertions.*;
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
612
import static org.hamcrest.MatcherAssert.assertThat;
7-
import static org.hamcrest.Matchers.*;
13+
import static org.hamcrest.Matchers.containsInAnyOrder;
14+
import static org.hamcrest.Matchers.hasSize;
15+
import static org.junit.jupiter.api.Assertions.assertAll;
816

917
/**
1018
* Tests for {@link ProductService}
1119
*/
12-
final class ProductServiceTest extends WireMockBaseTestCase{
20+
final class ProductServiceTest extends WireMockBaseTestCase {
1321
private final ProductService sut = new ProductService(conf());
22+
23+
@Test
24+
void search() throws URISyntaxException, IOException {
25+
stubFor(
26+
get("/api/v2/products/?offset=0&limit=100")
27+
.willReturn(
28+
ok()
29+
.withBody(readResponseBodyFromFixture("ProductService_response_fixture.json"))
30+
)
31+
);
32+
33+
final var result = sut.search();
34+
35+
assertAll(
36+
() -> assertThat(result, hasSize(3)),
37+
() -> assertThat(result, containsInAnyOrder(
38+
Product.builder()
39+
.id(419)
40+
.name("10.0.0.1")
41+
.description("Product was automatically created by the secureCodeBox DefectDojo integration")
42+
.tags(List.of(
43+
"attack-surface/internal",
44+
"office/munich",
45+
"org/owasp",
46+
"vlan/dev"
47+
))
48+
.productType(2)
49+
.findingsCount(12)
50+
.enableFullRiskAcceptance(true)
51+
.authorizationGroups(Collections.emptyList())
52+
.build(),
53+
Product.builder()
54+
.id(312)
55+
.name("10.0.0.2")
56+
.description("Product was automatically created by the secureCodeBox DefectDojo integration")
57+
.tags(List.of(
58+
"attack-surface/internal",
59+
"office/hamburg",
60+
"org/owasp",
61+
"vlan/dev"
62+
))
63+
.productType(1)
64+
.findingsCount(16)
65+
.enableFullRiskAcceptance(false)
66+
.authorizationGroups(List.of(1L, 2L, 3L))
67+
.build(),
68+
Product.builder()
69+
.id(297)
70+
.name("10.0.0.3")
71+
.description("Product was automatically created by the secureCodeBox DefectDojo integration")
72+
.tags(List.of(
73+
"attack-surface/external",
74+
"office/munich",
75+
"org/owasp"
76+
))
77+
.productType(2)
78+
.findingsCount(16)
79+
.enableSimpleRiskAcceptance(true)
80+
.authorizationGroups(Collections.emptyList())
81+
.build()
82+
))
83+
);
84+
}
1485
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,166 @@
1-
{}
1+
{
2+
"count": 3,
3+
"next": null,
4+
"previous": null,
5+
"results": [
6+
{
7+
"id": 419,
8+
"findings_count": 12,
9+
"findings_list": [
10+
28834,
11+
28781,
12+
28752,
13+
28732,
14+
25096,
15+
25076,
16+
25055,
17+
25042,
18+
21822,
19+
21808,
20+
21793,
21+
21784
22+
],
23+
"tags": [
24+
"attack-surface/internal",
25+
"office/munich",
26+
"org/owasp",
27+
"vlan/dev"
28+
],
29+
"product_meta": [],
30+
"name": "10.0.0.1",
31+
"description": "Product was automatically created by the secureCodeBox DefectDojo integration",
32+
"created": "2024-03-05T10:23:43.680337Z",
33+
"prod_numeric_grade": null,
34+
"business_criticality": null,
35+
"platform": null,
36+
"lifecycle": null,
37+
"origin": null,
38+
"user_records": null,
39+
"revenue": null,
40+
"external_audience": false,
41+
"internet_accessible": false,
42+
"enable_product_tag_inheritance": false,
43+
"enable_simple_risk_acceptance": false,
44+
"enable_full_risk_acceptance": true,
45+
"disable_sla_breach_notifications": false,
46+
"product_manager": null,
47+
"technical_contact": null,
48+
"team_manager": null,
49+
"prod_type": 2,
50+
"sla_configuration": 1,
51+
"members": [],
52+
"authorization_groups": [],
53+
"regulations": []
54+
},
55+
{
56+
"id": 312,
57+
"findings_count": 16,
58+
"findings_list": [
59+
28804,
60+
28763,
61+
28743,
62+
28725,
63+
25131,
64+
25107,
65+
25091,
66+
25083,
67+
21817,
68+
21801,
69+
21785,
70+
21780,
71+
19167,
72+
18752,
73+
18416,
74+
18269
75+
],
76+
"tags": [
77+
"attack-surface/internal",
78+
"office/hamburg",
79+
"org/owasp",
80+
"vlan/dev"
81+
],
82+
"product_meta": [],
83+
"name": "10.0.0.2",
84+
"description": "Product was automatically created by the secureCodeBox DefectDojo integration",
85+
"created": "2024-03-04T17:09:22.871051Z",
86+
"prod_numeric_grade": null,
87+
"business_criticality": null,
88+
"platform": null,
89+
"lifecycle": null,
90+
"origin": null,
91+
"user_records": null,
92+
"revenue": null,
93+
"external_audience": false,
94+
"internet_accessible": false,
95+
"enable_product_tag_inheritance": false,
96+
"enable_simple_risk_acceptance": false,
97+
"enable_full_risk_acceptance": false,
98+
"disable_sla_breach_notifications": false,
99+
"product_manager": null,
100+
"technical_contact": null,
101+
"team_manager": null,
102+
"prod_type": 1,
103+
"sla_configuration": 1,
104+
"members": [],
105+
"authorization_groups": [
106+
1,
107+
2,
108+
3
109+
],
110+
"regulations": []
111+
},
112+
{
113+
"id": 297,
114+
"findings_count": 16,
115+
"findings_list": [
116+
28825,
117+
28776,
118+
28750,
119+
28735,
120+
25095,
121+
25075,
122+
25059,
123+
25043,
124+
21828,
125+
21815,
126+
21805,
127+
21797,
128+
18970,
129+
18462,
130+
18148,
131+
18023
132+
],
133+
"tags": [
134+
"attack-surface/external",
135+
"office/munich",
136+
"org/owasp"
137+
],
138+
"product_meta": [],
139+
"name": "10.0.0.3",
140+
"description": "Product was automatically created by the secureCodeBox DefectDojo integration",
141+
"created": "2024-03-04T17:07:39.258064Z",
142+
"prod_numeric_grade": null,
143+
"business_criticality": null,
144+
"platform": null,
145+
"lifecycle": null,
146+
"origin": null,
147+
"user_records": null,
148+
"revenue": null,
149+
"external_audience": false,
150+
"internet_accessible": false,
151+
"enable_product_tag_inheritance": false,
152+
"enable_simple_risk_acceptance": true,
153+
"enable_full_risk_acceptance": false,
154+
"disable_sla_breach_notifications": false,
155+
"product_manager": null,
156+
"technical_contact": null,
157+
"team_manager": null,
158+
"prod_type": 2,
159+
"sla_configuration": 1,
160+
"members": [],
161+
"authorization_groups": [],
162+
"regulations": []
163+
}
164+
],
165+
"prefetch": {}
166+
}

0 commit comments

Comments
 (0)