@@ -52,33 +52,25 @@ final class DefaultImportScanService implements ImportScanService {
52
52
53
53
@ Override
54
54
public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType ) {
55
- final var options = new LinkedMultiValueMap <String , String >();
56
- options .add ("engagement" , Long .toString (engagementId )); // FIXME Seems to be duplicated bc it is done again in the overloaded method.
57
-
58
- return this .importScan (scanFile , engagementId , lead , currentDate , scanType , testType , options );
55
+ return this .importScan (scanFile , engagementId , lead , currentDate , scanType , testType , new LinkedMultiValueMap <>());
59
56
}
60
57
61
58
@ Override
62
59
public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
63
60
options .add ("engagement" , Long .toString (engagementId ));
64
61
65
- // FIXME: Why is engagementId hardcoded overwritten with "import-scan"
66
62
return this .createFindings (scanFile , "import-scan" , lead , currentDate , scanType , testType , options );
67
63
}
68
64
69
65
@ Override
70
66
public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType ) {
71
- final var options = new LinkedMultiValueMap <String , String >();
72
- options .add ("test" , Long .toString (testId )); // FIXME Seems to be duplicated bc it is done again in the overloaded method.
73
-
74
- return this .reimportScan (scanFile , testId , lead , currentDate , scanType , testType , options );
67
+ return this .reimportScan (scanFile , testId , lead , currentDate , scanType , testType , new LinkedMultiValueMap <>());
75
68
}
76
69
77
70
@ Override
78
71
public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
79
72
options .add ("test" , Long .toString (testId ));
80
73
81
- // FIXME: Why is engagementId hardcoded overwritten with "reimport-scan"
82
74
return this .createFindings (scanFile , "reimport-scan" , lead , currentDate , scanType , testType , options );
83
75
}
84
76
@@ -88,6 +80,9 @@ public ImportScanResponse reimportScan(ScanFile scanFile, long testId, long lead
88
80
private ImportScanResponse createFindings (ScanFile scanFile , String endpoint , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
89
81
final var restTemplate = this .createRestTemplate ();
90
82
final var headers = createDefectDojoAuthorizationHeaders ();
83
+ // We use multipart because we send two "parts" in the request body:
84
+ // 1. generic info as key=value&key=value...
85
+ // 2. the raw scan result as file
91
86
headers .setContentType (MediaType .MULTIPART_FORM_DATA );
92
87
restTemplate .setMessageConverters (List .of (
93
88
new FormHttpMessageConverter (),
@@ -116,6 +111,7 @@ private ImportScanResponse createFindings(ScanFile scanFile, String endpoint, lo
116
111
}
117
112
118
113
try {
114
+ // scanFile is the raw result from lurker.
119
115
final var contentsAsResource = new ByteArrayResource (scanFile .getContent ().getBytes (StandardCharsets .UTF_8 )) {
120
116
@ Override
121
117
public String getFilename () {
@@ -124,6 +120,7 @@ public String getFilename() {
124
120
};
125
121
126
122
// FIXME: Why do we add the whole byte array resiurce here as object? Is not simply the file name sufficient here? Then we could use <String, String>
123
+ // We send the whole file content, so DefectDojo can parse the finding by itself.
127
124
body .add ("file" , contentsAsResource );
128
125
129
126
// FIXME: We do not define the the type T of the body here!
0 commit comments