10BC0 Remove deprecated userId attribute by Zero3141 · Pull Request #1861 · secureCodeBox/secureCodeBox · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,14 @@ public void init(Config defectDojoConfig, PersistenceProviderConfig persistenceP

@Override
public List<Finding> run(Scan scan, ScanFile scanResultFile) throws Exception {
Long userId = null;

if (this.config.getUserId() != null) {
LOG.debug("Using configured User Id");
userId = this.config.getUserId();
} else {
LOG.debug("Getting DefectDojo User Id via user profile API");
List<UserProfile> userProfiles = userProfileService.search();
if (userProfiles.isEmpty()) {
LOG.debug("Getting DefectDojo User Id via user profile API");
Long userId = null;
List<UserProfile> userProfiles = userProfileService.search();
if (userProfiles.isEmpty()) {
throw new DefectDojoPersistenceException("UserProfileService did return empty list. Expected current user to be in list");
} else {
} else {
userId = userProfiles.get(0).getUser().getId();
}
}

LOG.info("Running with DefectDojo User Id: {}", userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand All @@ -37,11 +37,13 @@ class DefectDojoFindingToSecureCodeBoxMapperTest {
@Mock
FindingService findingService;

@Mock
Config config;

Finding exampleFinding;

@BeforeEach
public void setup(){
var config = new Config("http://example.defectdojo.com", "placeholder", "placeholder", 1000);
public void setup() {
this.mapper = new DefectDojoFindingToSecureCodeBoxMapper(config, endpointService, findingService);

this.exampleFinding = Finding.builder()
Expand All @@ -59,7 +61,7 @@ public void setup(){
}

@Test
public void shouldMapBasicFindings(){
public void shouldMapBasicFindings() {
// Typical ZAP Finding in DefectDojo
var ddFinding = exampleFinding;

Expand Down Expand Up @@ -94,7 +96,7 @@ public void shouldMapBasicFindings(){
}

@Test
public void shouldIncludeOriginalDuplicateFindingInAttributes(){
public void shouldIncludeOriginalDuplicateFindingInAttributes() {
// Typical ZAP Finding in DefectDojo
var ddFinding = exampleFinding;

Expand Down Expand Up @@ -134,7 +136,7 @@ public void shouldIncludeOriginalDuplicateFindingInAttributes(){
}

@Test
public void shouldNotBeStuckInARecursiveLoop(){
public void shouldNotBeStuckInARecursiveLoop() {
// Typical ZAP Finding in DefectDojo
var ddFinding = exampleFinding;

Expand All @@ -159,9 +161,7 @@ public void shouldNotBeStuckInARecursiveLoop(){

when(findingService.get(7L)).thenReturn(originalFinding);

var exception = Assertions.assertThrows(RuntimeException.class, () -> {
this.mapper.fromDefectDojoFinding(ddFinding);
});
var exception = Assertions.assertThrows(RuntimeException.class, () -> this.mapper.fromDefectDojoFinding(ddFinding));

assertEquals(
"Duplicate finding does not point to the actual original finding, as the original finding (id: 7) is also a duplicate. This should never happen.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand All @@ -52,11 +50,14 @@ public class VersionedEngagementsStrategyTest {
@Mock
ImportScanService importScanService;

@Mock
Config config;

Scan scan;

@BeforeEach
public void setup() throws Exception {
versionedEngagementsStrategy.config = new Config("https://defectdojo.example.com", "<key>", "foobar", 1000);
public void setup() {
versionedEngagementsStrategy.config = config;
versionedEngagementsStrategy.persistenceProviderConfig = new PersistenceProviderConfig(new String[]{"http://example.com","http://example.com"});

scan = new Scan();
Expand All @@ -74,7 +75,7 @@ public void setup() throws Exception {
@Test
@DisplayName("Fails when Configured User can not be looked up in the DefectDojo API")
void requiresUserToBeFound() throws Exception {
when(userProfileService.search()).thenReturn(new ArrayList<UserProfile>());
when(userProfileService.search()).thenReturn(new ArrayList<>());

Assertions.assertThrows(DefectDojoPersistenceException.class, () -> {
versionedEngagementsStrategy.run(scan, new ScanFile("nmap.xml","<!-- Nmap Report -->"));
Expand Down
0