Skip to content
Open
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
49 changes: 49 additions & 0 deletions .github/workflows/ci-test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.
name: E2E Tests

on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch: { }

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: { }

jobs:
test-e2e:
name: Test E2E
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
with:
persist-credentials: false

- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # tag=v5.2.0
with:
distribution: 'temurin'
java-version: '25'
cache: 'maven'

- name: Execute end-to-end tests
run: make test-e2e
18 changes: 18 additions & 0 deletions e2e/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-jvm</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.adobe.testing</groupId>
<artifactId>s3mock-testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class AbstractE2ET {

protected static DockerImageName POSTGRES_IMAGE = DockerImageName.parse("postgres:14-alpine");
protected static DockerImageName API_SERVER_IMAGE = DockerImageName.parse("ghcr.io/dependencytrack/apiserver")
.withTag(Optional.ofNullable(System.getenv("APISERVER_VERSION")).orElse("local"));
.withTag(Optional.ofNullable(System.getenv("APISERVER_VERSION")).orElse("5-snapshot"));
Comment on lines 48 to +49

protected final Logger logger = LoggerFactory.getLogger(getClass());
protected final Network internalNetwork = Network.newNetwork();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 com.adobe.testing.s3mock.testcontainers.S3MockContainer;
import io.minio.ListObjectsArgs;
import io.minio.MinioClient;
import io.minio.Result;
import io.minio.messages.Item;
import org.dependencytrack.e2e.api.model.BomUploadRequest;
import org.dependencytrack.e2e.api.model.EventProcessingResponse;
import org.dependencytrack.e2e.api.model.EventTokenResponse;
import org.dependencytrack.e2e.api.model.Project;
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.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 BomUploadS3FileStorageE2ET extends AbstractE2ET {

private static final DockerImageName S3MOCK_IMAGE =
DockerImageName.parse("adobe/s3mock").withTag("5.0.0");

private S3MockContainer s3MockContainer;

@Override
@BeforeEach
void beforeEach() throws Exception {
s3MockContainer = new S3MockContainer(S3MOCK_IMAGE)
.withInitialBuckets("dtrack")
.withNetwork(internalNetwork)
.withNetworkAliases("s3mock");
s3MockContainer.start();

super.beforeEach();
}

@Override
protected void customizeApiServerContainer(GenericContainer<?> container) {
container
.withEnv("DT_FILE_STORAGE_PROVIDER", "s3")
.withEnv("DT_FILE_STORAGE_S3_ENDPOINT", "http://s3mock:9090")
.withEnv("DT_FILE_STORAGE_S3_BUCKET", "dtrack")
.withEnv("DT_FILE_STORAGE_S3_ACCESS_KEY", "foo")
.withEnv("DT_FILE_STORAGE_S3_SECRET_KEY", "bar");
}

@AfterEach
void afterEachS3() {
Optional.ofNullable(s3MockContainer).ifPresent(GenericContainer::stop);
}

@Test
void shouldUploadAndProcessBomWhenS3FileStorageConfigured() throws Exception {
final byte[] bomBytes = getClass().getResourceAsStream("/dtrack-apiserver-4.5.0.bom.json").readAllBytes();
final String bomBase64 = Base64.getEncoder().encodeToString(bomBytes);

final EventTokenResponse response = apiClient.uploadBom(
new BomUploadRequest("foo", "bar", true, bomBase64));
assertThat(response.token()).isNotEmpty();

await("BOM processing")
.atMost(Duration.ofSeconds(15))
.pollDelay(Duration.ofMillis(250))
.untilAsserted(() -> {
final EventProcessingResponse processingResponse =
apiClient.isEventBeingProcessed(response.token());
assertThat(processingResponse.processing()).isFalse();
});

final Project project = apiClient.lookupProject("foo", "bar");
assertThat(project).isNotNull();

try (final var s3Client = MinioClient.builder()
.endpoint(s3MockContainer.getHttpEndpoint())
.credentials("foo", "bar")
.build()) {
final Iterable<Result<Item>> items =
s3Client.listObjects(
ListObjectsArgs.builder()
.bucket("dtrack")
.recursive(true)
.build());
assertThat(items).isEmpty();
}
}

}
Loading