Skip to content

Commit 3d91334

Browse files
committed
Add e2e test for local BOM upload storage
Signed-off-by: nscuro <[email protected]>
1 parent 1baaaf5 commit 3d91334

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

e2e/src/test/java/org/dependencytrack/e2e/AbstractE2ET.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class AbstractE2ET {
5656
protected static DockerImageName POSTGRES_IMAGE = DockerImageName.parse("postgres:15-alpine");
5757
protected static DockerImageName REDPANDA_IMAGE = DockerImageName.parse("docker.redpanda.com/vectorized/redpanda:v24.2.2");
5858
protected static DockerImageName API_SERVER_IMAGE = DockerImageName.parse("ghcr.io/dependencytrack/hyades-apiserver")
59-
.withTag(Optional.ofNullable(System.getenv("APISERVER_VERSION")).orElse("snapshot"));
59+
.withTag(Optional.ofNullable(System.getenv("APISERVER_VERSION")).orElse("local"));
6060
protected static DockerImageName MIRROR_SERVICE_IMAGE = DockerImageName.parse("ghcr.io/dependencytrack/hyades-mirror-service")
6161
.withTag(Optional.ofNullable(System.getenv("HYADES_VERSION")).orElse("snapshot"));
6262
protected static DockerImageName NOTIFICATION_PUBLISHER_IMAGE = DockerImageName.parse("ghcr.io/dependencytrack/hyades-notification-publisher")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* This file is part of Dependency-Track.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
package org.dependencytrack.e2e;
20+
21+
import org.apache.commons.io.IOUtils;
22+
import org.dependencytrack.apiserver.model.BomUploadRequest;
23+
import org.dependencytrack.apiserver.model.EventProcessingResponse;
24+
import org.dependencytrack.apiserver.model.WorkflowTokenResponse;
25+
import org.junit.jupiter.api.Test;
26+
import org.testcontainers.containers.Container.ExecResult;
27+
import org.testcontainers.containers.GenericContainer;
28+
29+
import java.time.Duration;
30+
import java.util.Base64;
31+
32+
import static org.assertj.core.api.Assertions.assertThat;
33+
import static org.awaitility.Awaitility.await;
34+
35+
class BomUploadProcessingWithLocalStorageE2ET extends AbstractE2ET {
36+
37+
@Override
38+
protected void customizeApiServerContainer(final GenericContainer<?> container) {
39+
container
40+
// Ensure other storage extensions are disabled.
41+
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_DATABASE_ENABLED", "false")
42+
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_ENABLED", "false")
43+
// Enable and configure local storage extension.
44+
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_LOCAL_ENABLED", "true")
45+
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_LOCAL_DIRECTORY", "/tmp/bom-uploads");
46+
}
47+
48+
@Override
49+
protected void customizeVulnAnalyzerContainer(final GenericContainer<?> container) {
50+
// We don't test analysis here, so don't waste any quota with the OSS Index API.
51+
container.withEnv("SCANNER_OSSINDEX_ENABLED", "false");
52+
}
53+
54+
@Test
55+
void test() throws Exception {
56+
// Parse and base64 encode a BOM.
57+
final byte[] bomBytes = IOUtils.resourceToByteArray("/dtrack-apiserver-4.5.0.bom.json");
58+
final String bomBase64 = Base64.getEncoder().encodeToString(bomBytes);
59+
60+
// Upload the BOM.
61+
final WorkflowTokenResponse response = apiServerClient.uploadBom(new BomUploadRequest("foo", "bar", true, bomBase64));
62+
assertThat(response.token()).isNotEmpty();
63+
64+
// Wait up to 15sec for the BOM processing to complete.
65+
await("BOM processing")
66+
.atMost(Duration.ofSeconds(15))
67+
.pollDelay(Duration.ofMillis(250))
68+
.untilAsserted(() -> {
69+
final EventProcessingResponse processingResponse = apiServerClient.isEventBeingProcessed(response.token());
70+
assertThat(processingResponse.processing()).isFalse();
71+
});
72+
73+
verifyBomDeleted();
74+
}
75+
76+
private void verifyBomDeleted() throws Exception {
77+
final ExecResult dirExistsResult = apiServerContainer.execInContainer("test", "-d", "/tmp/bom-uploads");
78+
assertThat(dirExistsResult.getExitCode()).withFailMessage("Storage directory was not created").isZero();
79+
80+
final ExecResult dirEmptyResult = apiServerContainer.execInContainer("ls", "/tmp/bom-uploads");
81+
assertThat(dirEmptyResult.getStdout()).withFailMessage("BOM was not deleted after processing").isBlank();
82+
}
83+
84+
}

e2e/src/test/java/org/dependencytrack/e2e/BomUploadProcessingWithS3StorageE2ET.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import io.minio.Result;
2525
import io.minio.messages.Item;
2626
import org.apache.commons.io.IOUtils;
27-
import org.dependencytrack.apiserver.model.BomProcessingResponse;
2827
import org.dependencytrack.apiserver.model.BomUploadRequest;
28+
import org.dependencytrack.apiserver.model.EventProcessingResponse;
2929
import org.dependencytrack.apiserver.model.WorkflowTokenResponse;
3030
import org.junit.jupiter.api.AfterEach;
3131
import org.junit.jupiter.api.BeforeEach;
@@ -79,6 +79,12 @@ protected void customizeApiServerContainer(final GenericContainer<?> container)
7979
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_SECRET_KEY", minioContainer.getPassword());
8080
}
8181

82+
@Override
83+
protected void customizeVulnAnalyzerContainer(final GenericContainer<?> container) {
84+
// We don't test analysis here, so don't waste any quota with the OSS Index API.
85+
container.withEnv("SCANNER_OSSINDEX_ENABLED", "false");
86+
}
87+
8288
@Override
8389
@AfterEach
8490
void afterEach() throws Exception {
@@ -105,7 +111,7 @@ void test() throws Exception {
105111
.atMost(Duration.ofSeconds(15))
106112
.pollDelay(Duration.ofMillis(250))
107113
.untilAsserted(() -> {
108-
final BomProcessingResponse processingResponse = apiServerClient.isBomBeingProcessed(response.token());
114+
final EventProcessingResponse processingResponse = apiServerClient.isEventBeingProcessed(response.token());
109115
assertThat(processingResponse.processing()).isFalse();
110116
});
111117

0 commit comments

Comments
 (0)