Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7a4f074
Enable debug logging in test code
Weltraumschaf Mar 7, 2024
f7c9186
Disable example test
Weltraumschaf Mar 7, 2024
3f01dfd
Implement first capture replay test for ProductTypeService
Weltraumschaf Mar 7, 2024
f8972c7
Debul log requested URL to know what URI path to mock in tests
Weltraumschaf Mar 7, 2024
766c57d
Extract Common Logic for WireMock Test Setup to Share Across Test Cases
Weltraumschaf Mar 8, 2024
ddb62e3
Capture & Replay Integration Test for UserService
Weltraumschaf Mar 8, 2024
6660d1a
Add Integration Test Stubs for all Services
Weltraumschaf Mar 8, 2024
ab94dd8
Capture & Replay Integration Test for EndpointService
Weltraumschaf Mar 8, 2024
5577076
Simplify Fixture Loading
Weltraumschaf Mar 8, 2024
db808e5
Capture & Replay Integration Test for EngagementService
Weltraumschaf Mar 8, 2024
57f11ab
No Integration Test for Base Service Implementation
Weltraumschaf Mar 8, 2024
13f2635
Capture & Replay Integration Test for GroupMemberService
Weltraumschaf Mar 8, 2024
fb6d745
Capture & Replay Integration Test for GroupService
Weltraumschaf Mar 8, 2024
79ef531
Capture & Replay Integration Test for ProductGroupService
Weltraumschaf Mar 8, 2024
c2a2991
Capture & Replay Integration Test for ProductService
Weltraumschaf Mar 8, 2024
d511791
Capture & Replay Integration Test for TestService
Weltraumschaf Mar 8, 2024
5d89d5b
Capture & Replay Integration Test for TestTypeService
Weltraumschaf Mar 8, 2024
2dcae1d
Capture & Replay Integration Test for ToolConfigService
Weltraumschaf Mar 8, 2024
3083557
Capture & Replay Integration Test for ToolTypeService
Weltraumschaf Mar 8, 2024
1d759f8
Remove Example WireMock Test Case
Weltraumschaf Mar 8, 2024
1738067
Port FindingServiceTest To WireMock
Weltraumschaf Mar 8, 2024
c8fa2b1
Add Missing SPDX Headers
Weltraumschaf Mar 8, 2024
9eec68f
Port UserProfileServiceTest To WireMock
Weltraumschaf Mar 8, 2024
6b38ec9
Contains Only Tests for Interface
Weltraumschaf Mar 8, 2024
ae22d59
This Is Not a Typical Service
Weltraumschaf Mar 8, 2024
87d0c0c
Extract generic service interface to derive missin integration test m…
Weltraumschaf Mar 8, 2024
58ceeae
Add Test Method Stubs for Whole Interface
Weltraumschaf Mar 8, 2024
21b6a5a
Implement test for search with query params
Weltraumschaf Mar 9, 2024
4062e91
Simulate the DefectDojo Response Headers
Weltraumschaf Mar 9, 2024
75de015
Implement Test Case for Single Endpoint
Weltraumschaf Mar 9, 2024
4e27239
Even More Integration Tests for EndpointService
Weltraumschaf Mar 9, 2024
214d5fd
Set Log Level in Tests to Warn Level
Weltraumschaf Mar 9, 2024
eccab28
Port Test Cases from EndpointService to Other Services
Weltraumschaf Mar 10, 2024
155345f
Add Missing TEsts and Fixtures for ProductGroupService
Weltraumschaf Mar 14, 2024
2af85fa
Add Missing Fixture
Weltraumschaf Mar 14, 2024
9bdce96
Fix Assertions for Special Implementation of UserProfileService
Weltraumschaf Mar 14, 2024
f793401
Move Public API to top of Class
Weltraumschaf Mar 14, 2024
37931fc
Update dependencies
Weltraumschaf Mar 14, 2024
b9835b8
Update plugins
Weltraumschaf Mar 14, 2024
e4b6e3f
Add Missing Interface Doc and Null Checks
Weltraumschaf Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Capture & Replay Integration Test for ProductService
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
  • Loading branch information
Weltraumschaf committed Mar 8, 2024
commit c2a2991956c003081e1b054d3bdb64ed0caba5a1
Original file line number Diff line number Diff line change
@@ -1,14 +1,85 @@
package io.securecodebox.persistence.defectdojo.service;

import io.securecodebox.persistence.defectdojo.model.Product;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertAll;

/**
* Tests for {@link ProductService}
*/
final class ProductServiceTest extends WireMockBaseTestCase{
final class ProductServiceTest extends WireMockBaseTestCase {
private final ProductService sut = new ProductService(conf());

@Test
void search() throws URISyntaxException, IOException {
stubFor(
get("/api/v2/products/?offset=0&limit=100")
.willReturn(
ok()
.withBody(readResponseBodyFromFixture("ProductService_response_fixture.json"))
)
);

final var result = sut.search();

assertAll(
() -> assertThat(result, hasSize(3)),
() -> assertThat(result, containsInAnyOrder(
Product.builder()
.id(419)
.name("10.0.0.1")
.description("Product was automatically created by the secureCodeBox DefectDojo integration")
.tags(List.of(
"attack-surface/internal",
"office/munich",
"org/owasp",
"vlan/dev"
))
.productType(2)
.findingsCount(12)
.enableFullRiskAcceptance(true)
.authorizationGroups(Collections.emptyList())
.build(),
Product.builder()
.id(312)
.name("10.0.0.2")
.description("Product was automatically created by the secureCodeBox DefectDojo integration")
.tags(List.of(
"attack-surface/internal",
"office/hamburg",
"org/owasp",
"vlan/dev"
))
.productType(1)
.findingsCount(16)
.enableFullRiskAcceptance(false)
.authorizationGroups(List.of(1L, 2L, 3L))
.build(),
Product.builder()
.id(297)
.name("10.0.0.3")
.description("Product was automatically created by the secureCodeBox DefectDojo integration")
.tags(List.of(
"attack-surface/external",
"office/munich",
"org/owasp"
))
.productType(2)
.findingsCount(16)
.enableSimpleRiskAcceptance(true)
.authorizationGroups(Collections.emptyList())
.build()
))
);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,166 @@
{}
{
"count": 3,
"next": null,
"previous": null,
"results": [
{
"id": 419,
"findings_count": 12,
"findings_list": [
28834,
28781,
28752,
28732,
25096,
25076,
25055,
25042,
21822,
21808,
21793,
21784
],
"tags": [
"attack-surface/internal",
"office/munich",
"org/owasp",
"vlan/dev"
],
"product_meta": [],
"name": "10.0.0.1",
"description": "Product was automatically created by the secureCodeBox DefectDojo integration",
"created": "2024-03-05T10:23:43.680337Z",
"prod_numeric_grade": null,
"business_criticality": null,
"platform": null,
"lifecycle": null,
"origin": null,
"user_records": null,
"revenue": null,
"external_audience": false,
"internet_accessible": false,
"enable_product_tag_inheritance": false,
"enable_simple_risk_acceptance": false,
"enable_full_risk_acceptance": true,
"disable_sla_breach_notifications": false,
"product_manager": null,
"technical_contact": null,
"team_manager": null,
"prod_type": 2,
"sla_configuration": 1,
"members": [],
"authorization_groups": [],
"regulations": []
},
{
"id": 312,
"findings_count": 16,
"findings_list": [
28804,
28763,
28743,
28725,
25131,
25107,
25091,
25083,
21817,
21801,
21785,
21780,
19167,
18752,
18416,
18269
],
"tags": [
"attack-surface/internal",
"office/hamburg",
"org/owasp",
"vlan/dev"
],
"product_meta": [],
"name": "10.0.0.2",
"description": "Product was automatically created by the secureCodeBox DefectDojo integration",
"created": "2024-03-04T17:09:22.871051Z",
"prod_numeric_grade": null,
"business_criticality": null,
"platform": null,
"lifecycle": null,
"origin": null,
"user_records": null,
"revenue": null,
"external_audience": false,
"internet_accessible": false,
"enable_product_tag_inheritance": false,
"enable_simple_risk_acceptance": false,
"enable_full_risk_acceptance": false,
"disable_sla_breach_notifications": false,
"product_manager": null,
"technical_contact": null,
"team_manager": null,
"prod_type": 1,
"sla_configuration": 1,
"members": [],
"authorization_groups": [
1,
2,
3
],
"regulations": []
},
{
"id": 297,
"findings_count": 16,
"findings_list": [
28825,
28776,
28750,
28735,
25095,
25075,
25059,
25043,
21828,
21815,
21805,
21797,
18970,
18462,
18148,
18023
],
"tags": [
"attack-surface/external",
"office/munich",
"org/owasp"
],
"product_meta": [],
"name": "10.0.0.3",
"description": "Product was automatically created by the secureCodeBox DefectDojo integration",
"created": "2024-03-04T17:07:39.258064Z",
"prod_numeric_grade": null,
"business_criticality": null,
"platform": null,
"lifecycle": null,
"origin": null,
"user_records": null,
"revenue": null,
"external_audience": false,
"internet_accessible": false,
"enable_product_tag_inheritance": false,
"enable_simple_risk_acceptance": true,
"enable_full_risk_acceptance": false,
"disable_sla_breach_notifications": false,
"product_manager": null,
"technical_contact": null,
"team_manager": null,
"prod_type": 2,
"sla_configuration": 1,
"members": [],
"authorization_groups": [],
"regulations": []
}
],
"prefetch": {}
}