Skip to content

Commit 4a5c4c1

Browse files
NIAD-1805: Fix vulnerabilities in dependencies (#1296)
* Address vulnerability in `org.testcontainers:testcontainers:1.21.3`. This occurs due to a bug (which will not be fixed) in the `commons-compress` version used. This addressed this by importing an implementation of `common-compress` where the vulnerability exists and allowing this to override the `TestContainers` version. * Remove `io.findify:s3mock_2.13:0.2.6` as this project has now been abandoned and archived. Switched instead to use `com.adobe.testing:s3mock-testcontainers:4.7.0` as this is in active development and is the recommended replacement. * Update the unit tests previously using `findify:s3mock` to use the test container instead, and removed now unneeded constants. * Update `org.apache.commons:commons-lang3:3.17.0` to version `3.18.0` where the vulnerability has been resolved.
1 parent 000c259 commit 4a5c4c1

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

service/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
implementation 'org.apache.qpid:qpid-jms-client:2.7.0'
5656

5757
// Utils
58-
implementation 'org.apache.commons:commons-lang3:3.17.0'
58+
implementation 'org.apache.commons:commons-lang3:3.18.0'
5959
implementation 'javax.xml.soap:javax.xml.soap-api:1.4.0'
6060
implementation 'com.github.spullara.mustache.java:compiler:0.9.14'
6161
implementation 'org.apache.tika:tika-core:3.2.0'
@@ -66,12 +66,14 @@ dependencies {
6666
// Test
6767
testImplementation 'org.springframework.boot:spring-boot-starter-test'
6868
testImplementation "org.assertj:assertj-core:3.27.3"
69+
testImplementation 'org.apache.commons:commons-compress:1.28.0'
6970
testImplementation 'org.testcontainers:testcontainers:1.21.3'
71+
testImplementation 'org.testcontainers:junit-jupiter:1.21.3'
7072
testImplementation 'org.awaitility:awaitility:4.3.0'
7173
testImplementation 'org.wiremock:wiremock-standalone:3.13.0'
7274
testImplementation 'com.squareup.okhttp3:okhttp:4.12.0'
7375
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
74-
testImplementation 'io.findify:s3mock_2.13:0.2.6'
76+
testImplementation 'com.adobe.testing:s3mock-testcontainers:4.7.0'
7577

7678
pitest 'com.arcmutate:base:1.3.2'
7779
pitest 'com.arcmutate:pitest-git-plugin:2.1.0'

service/src/test/java/uk/nhs/adaptors/gp2gp/common/configuration/CustomTrustStoreTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package uk.nhs.adaptors.gp2gp.common.configuration;
22

3-
import io.findify.s3mock.S3Mock;
3+
import com.adobe.testing.s3mock.testcontainers.S3MockContainer;
44
import org.junit.jupiter.api.AfterAll;
55
import org.junit.jupiter.api.BeforeAll;
66
import org.junit.jupiter.api.Test;
7+
import org.testcontainers.junit.jupiter.Container;
8+
import org.testcontainers.junit.jupiter.Testcontainers;
79
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
810
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
911
import software.amazon.awssdk.regions.Region;
@@ -15,10 +17,12 @@
1517
import java.net.URI;
1618
import static org.junit.jupiter.api.Assertions.assertNotNull;
1719

20+
@Testcontainers
1821
class CustomTrustStoreTest {
1922

20-
public static final int PORT = 8001;
21-
private static S3Mock s3Mock;
23+
@Container
24+
private static final S3MockContainer S3_MOCK = new S3MockContainer("4.7.0");
25+
2226
private static S3Client s3Client;
2327
private static final String BUCKET_NAME = "test-bucket";
2428
private static final String TRUSTSTORE_PATH = "test.jks";
@@ -27,12 +31,8 @@ class CustomTrustStoreTest {
2731

2832
@BeforeAll
2933
static void setUp() {
30-
s3Mock = new S3Mock.Builder().withPort(PORT).withInMemoryBackend().build();
31-
s3Mock.start();
32-
System.out.println("S3Mock started at http://localhost:" + PORT);
33-
3434
s3Client = S3Client.builder()
35-
.endpointOverride(URI.create("http://localhost:" + PORT))
35+
.endpointOverride(URI.create(S3_MOCK.getHttpEndpoint()))
3636
.credentialsProvider(StaticCredentialsProvider.create(
3737
AwsBasicCredentials.create("accessKey", "secretKey")))
3838
.serviceConfiguration(S3Configuration.builder().pathStyleAccessEnabled(true).build())
@@ -53,7 +53,6 @@ static void setup() {
5353

5454
@AfterAll
5555
static void tearDown() {
56-
s3Mock.shutdown();
5756
customTrustStore = null;
5857
}
5958

service/src/test/java/uk/nhs/adaptors/gp2gp/common/storage/S3StorageConnectorTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package uk.nhs.adaptors.gp2gp.common.storage;
22

3-
import io.findify.s3mock.S3Mock;
3+
import com.adobe.testing.s3mock.testcontainers.S3MockContainer;
44
import org.junit.jupiter.api.BeforeAll;
55
import org.junit.jupiter.api.Test;
6+
7+
import org.testcontainers.junit.jupiter.Container;
8+
import org.testcontainers.junit.jupiter.Testcontainers;
69
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
710
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
811
import software.amazon.awssdk.core.ResponseInputStream;
@@ -21,39 +24,35 @@
2124
import java.net.URI;
2225
import java.nio.charset.StandardCharsets;
2326

24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertThrows;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
2628
import static org.junit.jupiter.api.Assertions.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertThrows;
2730

2831

32+
@Testcontainers
2933
class S3StorageConnectorTest {
3034

31-
public static final int PORT = 9090;
3235
private static final String BUCKET_NAME = "s3bucket";
3336
private static final String FILE_NAME = "test-file.txt";
3437

35-
private static S3Mock s3Mock;
3638
private static S3StorageConnector s3StorageConnector;
37-
private static StorageConnectorConfiguration config;
39+
40+
@Container
41+
private static final S3MockContainer S3_MOCK = new S3MockContainer("4.7.0");
3842

3943
private static S3Client s3Client;
4044

4145
@BeforeAll
4246
static void setUp() {
43-
44-
s3Mock = new S3Mock.Builder().withPort(PORT).withInMemoryBackend().build();
45-
s3Mock.start();
46-
System.out.println("S3Mock started at http://localhost:" + PORT);
47-
4847
s3Client = S3Client.builder()
49-
.endpointOverride(URI.create("http://localhost:" + PORT))
48+
.endpointOverride(URI.create(S3_MOCK.getHttpEndpoint()))
5049
.credentialsProvider(StaticCredentialsProvider.create(
5150
AwsBasicCredentials.create("accessKey", "secretKey")))
5251
.serviceConfiguration(S3Configuration.builder().pathStyleAccessEnabled(true).build())
5352
.region(Region.EU_WEST_2)
5453
.build();
5554

56-
config = new StorageConnectorConfiguration();
55+
StorageConnectorConfiguration config = new StorageConnectorConfiguration();
5756
config.setContainerName(BUCKET_NAME);
5857

5958
s3Client.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build());

0 commit comments

Comments
 (0)