Skip to content

Commit c628f71

Browse files
WeltraumschafManuelNeuer
authored andcommitted
#36 Factor out method to generate API URL
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 9213dba commit c628f71

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/service/DefaultImportScanService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,16 @@ public String getFilename() {
122122
// FIXME: We do not define the the type T of the body here!
123123
final var payload = new HttpEntity<MultiValueMap<String, Object>>(body, headers);
124124

125-
return restTemplate.exchange(defectDojoUrl + "/api/v2/" + endpoint + "/", HttpMethod.POST, payload, ImportScanResponse.class).getBody();
125+
return restTemplate.exchange(generateApiUrl(endpoint), HttpMethod.POST, payload, ImportScanResponse.class).getBody();
126126
} catch (HttpClientErrorException e) {
127127
throw new DefectDojoPersistenceException("Failed to attach findings to engagement.");
128128
}
129129
}
130130

131+
String generateApiUrl(final String endpoint) {
132+
return String.format("%s/api/v2/%s/", getDefectDojoUrl(), endpoint);
133+
}
134+
131135
/**
132136
* The DefectDojo Authentication Header
133137
*

src/test/java/io/securecodebox/persistence/defectdojo/service/DefaultImportScanServiceTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class DefaultImportScanServiceTest {
2222
private final DefectDojoConfig config = new DefectDojoConfig(
23-
"url",
23+
"http://localhost",
2424
"apiKey",
2525
"username",
2626
23,
@@ -169,8 +169,13 @@ void createRequestFactoryWithProxyAuthConfig_throesExceptionIfPortIsNotInteger()
169169
IllegalArgumentException.class,
170170
sut::createRequestFactoryWithProxyAuthConfig);
171171

172-
assertEquals(
173-
"Given port for proxy authentication configuration (property 'http.proxyPort') is not a valid number! Given value wa 'FUBAR'.",
174-
thrown.getMessage());
172+
assertThat(
173+
thrown.getMessage(),
174+
is("Given port for proxy authentication configuration (property 'http.proxyPort') is not a valid number! Given value wa 'FUBAR'."));
175+
}
176+
177+
@Test
178+
void generateApiUrl() {
179+
assertThat(sut.generateApiUrl("foo"), is("http://localhost/api/v2/foo/"));
175180
}
176181
}

0 commit comments

Comments
 (0)