-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e test for S3 BOM upload storage
Relates to #633 Signed-off-by: nscuro <[email protected]>
- Loading branch information
Showing
4 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
e2e/src/test/java/org/dependencytrack/e2e/BomUploadProcessingWithS3StorageE2ET.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.e2e; | ||
|
||
import io.minio.ListObjectsArgs; | ||
import io.minio.MakeBucketArgs; | ||
import io.minio.MinioClient; | ||
import io.minio.Result; | ||
import io.minio.messages.Item; | ||
import org.apache.commons.io.IOUtils; | ||
import org.dependencytrack.apiserver.model.BomProcessingResponse; | ||
import org.dependencytrack.apiserver.model.BomUploadRequest; | ||
import org.dependencytrack.apiserver.model.WorkflowTokenResponse; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.MinIOContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.time.Duration; | ||
import java.util.Base64; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
class BomUploadProcessingWithS3StorageE2ET extends AbstractE2ET { | ||
|
||
private static final String BOM_UPLOAD_BUCKET_NAME = "bom-upload"; | ||
|
||
private MinIOContainer minioContainer; | ||
private MinioClient minioClient; | ||
|
||
@Override | ||
@BeforeEach | ||
void beforeEach() throws Exception { | ||
minioContainer = new MinIOContainer(DockerImageName.parse("minio/minio:RELEASE.2023-12-14T18-51-57Z")) | ||
.withNetworkAliases("minio") | ||
.withNetwork(internalNetwork); | ||
minioContainer.start(); | ||
|
||
minioClient = MinioClient.builder() | ||
.endpoint(minioContainer.getS3URL()) | ||
.credentials(minioContainer.getUserName(), minioContainer.getPassword()) | ||
.build(); | ||
createBucket(); | ||
|
||
super.beforeEach(); | ||
} | ||
|
||
@Override | ||
protected void customizeApiServerContainer(final GenericContainer<?> container) { | ||
container | ||
.withEnv("BOM_UPLOAD_STORAGE_DEFAULT_EXTENSION", "s3") | ||
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_ENABLED", "true") | ||
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_ENDPOINT", "http://minio:9000") | ||
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_BUCKET", BOM_UPLOAD_BUCKET_NAME) | ||
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_ACCESS_KEY", minioContainer.getUserName()) | ||
.withEnv("BOM_UPLOAD_STORAGE_EXTENSION_S3_SECRET_KEY", minioContainer.getPassword()); | ||
} | ||
|
||
@Override | ||
@AfterEach | ||
void afterEach() throws Exception { | ||
if (minioClient != null) { | ||
minioClient.close(); | ||
} | ||
Optional.ofNullable(minioContainer).ifPresent(GenericContainer::stop); | ||
|
||
super.afterEach(); | ||
} | ||
|
||
@Test | ||
void test() throws Exception { | ||
// Parse and base64 encode a BOM. | ||
final byte[] bomBytes = IOUtils.resourceToByteArray("/dtrack-apiserver-4.5.0.bom.json"); | ||
final String bomBase64 = Base64.getEncoder().encodeToString(bomBytes); | ||
|
||
// Upload the BOM. | ||
final WorkflowTokenResponse response = apiServerClient.uploadBom(new BomUploadRequest("foo", "bar", true, bomBase64)); | ||
assertThat(response.token()).isNotEmpty(); | ||
|
||
// Wait up to 15sec for the BOM processing to complete. | ||
await("BOM processing") | ||
.atMost(Duration.ofSeconds(15)) | ||
.pollDelay(Duration.ofMillis(250)) | ||
.untilAsserted(() -> { | ||
final BomProcessingResponse processingResponse = apiServerClient.isBomBeingProcessed(response.token()); | ||
assertThat(processingResponse.processing()).isFalse(); | ||
}); | ||
|
||
verifyBomDeleted(); | ||
} | ||
|
||
private void createBucket() throws Exception { | ||
minioClient.makeBucket(MakeBucketArgs.builder() | ||
.bucket(BOM_UPLOAD_BUCKET_NAME) | ||
.build()); | ||
} | ||
|
||
private void verifyBomDeleted() { | ||
final Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder() | ||
.bucket(BOM_UPLOAD_BUCKET_NAME) | ||
.recursive(true) | ||
.build()); | ||
|
||
assertThat(results).isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters