Skip to content

Commit 8a5c792

Browse files
nitinp19bhanurp
andauthored
Vulnerability fix and Test fixed (#412)
integration test fix and security fixes * Multiple security fixes * "adding wait for artifactory" * "removing unused import" * "introducing retries in case of failure to delete the repository" --------- Co-authored-by: Bhanu Reddy <[email protected]>
1 parent 6069030 commit 8a5c792

File tree

8 files changed

+98
-13
lines changed

8 files changed

+98
-13
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
uses: actions/checkout@v4
3030
with:
3131
ref: ${{ github.event.pull_request.head.sha }}
32+
3233
- name: Setup Go with cache
3334
uses: jfrog/.github/actions/install-go-with-cache@main
3435

@@ -43,5 +44,18 @@ jobs:
4344
java-version: "8"
4445
distribution: "zulu"
4546

47+
- name: Wait for Artifactory
48+
run: |
49+
for i in {1..30}; do
50+
if curl -sf http://localhost:8081/artifactory/api/system/ping; then
51+
echo "Artifactory is up!"
52+
exit 0
53+
fi
54+
echo "Waiting for Artifactory..."
55+
sleep 10
56+
done
57+
echo "Artifactory did not start in time"
58+
exit 1
59+
4660
- name: Run tests
4761
run: ./gradlew${{ matrix.gradlewSuffix }} clean test

build.gradle

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,48 @@ subprojects {
5858
sourceCompatibility = 1.8
5959
targetCompatibility = 1.8
6060

61+
// Force secure versions to fix vulnerabilities
62+
configurations.all {
63+
resolutionStrategy {
64+
// Use latest confirmed available Jetty 9.4.x versions
65+
force 'org.eclipse.jetty:jetty-server:9.4.56.v20240826'
66+
force 'org.eclipse.jetty:jetty-servlets:9.4.56.v20240826'
67+
force 'org.eclipse.jetty:jetty-http:9.4.56.v20240826'
68+
force 'org.eclipse.jetty:jetty-util:9.4.56.v20240826'
69+
force 'org.eclipse.jetty:jetty-io:9.4.56.v20240826'
70+
force 'org.eclipse.jetty:jetty-client:9.4.56.v20240826'
71+
force 'org.eclipse.jetty:jetty-security:9.4.56.v20240826'
72+
force 'org.eclipse.jetty:jetty-servlet:9.4.56.v20240826'
73+
force 'org.eclipse.jetty:jetty-webapp:9.4.56.v20240826'
74+
force 'org.eclipse.jetty:jetty-proxy:9.4.56.v20240826'
75+
force 'org.eclipse.jetty:jetty-continuation:9.4.56.v20240826'
76+
force 'org.eclipse.jetty:jetty-util-ajax:9.4.56.v20240826'
77+
force 'org.eclipse.jetty:jetty-xml:9.4.56.v20240826'
78+
force 'org.eclipse.jetty.http2:http2-server:9.4.56.v20240826'
79+
force 'org.eclipse.jetty.http2:http2-common:9.4.56.v20240826'
80+
force 'org.eclipse.jetty.http2:http2-hpack:9.4.56.v20240826'
81+
// Latest secure versions
82+
force 'commons-io:commons-io:2.18.0'
83+
force 'net.minidev:json-smart:2.5.2'
84+
force 'com.jayway.jsonpath:json-path:2.9.0'
85+
force 'com.google.guava:guava:33.4.0-jre'
86+
force 'org.xmlunit:xmlunit-core:2.10.0'
87+
}
88+
89+
// Exclude problematic dependencies
90+
exclude group: 'commons-fileupload', module: 'commons-fileupload'
91+
}
92+
6193
dependencies {
6294
implementation('org.apache.httpcomponents:httpclient:4.5.13') {
6395
exclude group: 'commons-codec', module: 'commons-codec'
6496
}
6597
implementation 'commons-codec:commons-codec:1.13'
66-
implementation 'org.apache.commons:commons-lang3:3.12.0'
98+
implementation 'org.apache.commons:commons-lang3:3.18.0'
6799
implementation 'com.fasterxml.jackson.core:jackson-core:2.19.1'
68100
implementation 'com.fasterxml.jackson.core:jackson-databind:2.19.1'
69101
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.19.1'
70-
api 'org.jfrog.filespecs:file-specs-java:1.1.1'
102+
api 'org.jfrog.filespecs:file-specs-java:1.1.2'
71103
}
72104

73105
task sourcesJar(type: Jar, dependsOn: classes) {

httpClient/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ repositories {
88

99
dependencies {
1010
testImplementation group: 'org.testng', name: 'testng', version: '7.5.1'
11-
testImplementation group: 'com.github.tomakehurst', name: 'wiremock-jre8', version: '2.35.1'
11+
testImplementation group: 'com.github.tomakehurst', name: 'wiremock-jre8', version: '2.35.0'
1212
}

httpClient/src/main/java/org/jfrog/artifactory/client/httpClient/http/HttpBuilderBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ private SSLContext buildSslContext() {
399399
sslContext = sslBuilder.build();
400400
}
401401
} catch (Exception e) {
402-
e.printStackTrace();
402+
throw new RuntimeException("Error building SSLContext: " + e.getMessage(), e);
403403
}
404404
return sslContext != null ? sslContext : SSLContexts.createDefault();
405405
}

services/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ dependencies {
77
implementation addSlf4J('slf4j-api')
88
implementation addSlf4J('log4j-over-slf4j')
99
implementation addSlf4J('jcl-over-slf4j')
10-
implementation 'commons-io:commons-io:2.17.0'
10+
implementation 'commons-io:commons-io:2.18.0'
1111
testImplementation group: 'org.hamcrest', name: 'hamcrest-core', version: '2.2'
1212
testImplementation group: 'org.testng', name: 'testng', version: '7.5.1'
1313
/*
1414
* Don't depend upon a specific logging implementation as a compile or runtime dependency.
1515
* https://github.com/jfrog/artifactory-client-java/issues/43
1616
* https://github.com/jfrog/artifactory-client-java/issues/232
1717
*/
18-
testRuntimeOnly group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
18+
testRuntimeOnly group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.15'
1919
}
2020

2121
task createReleasePropertiesFile(type: Exec) {

services/src/test/groovy/org/jfrog/artifactory/client/BaseRepositoryTests.groovy

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ abstract class BaseRepositoryTests extends ArtifactoryTestsBase {
5757
@BeforeMethod
5858
protected void setUp() {
5959
String id = Long.toString(repoUniqueId)
60+
println "[SETUP] Starting test setup for repo id: $id at ${new Date()}"
6061
if (prepareGenericRepo) {
6162
RepositorySettings settings = getRepositorySettings(RepositoryTypeImpl.LOCAL)
6263

@@ -174,12 +175,12 @@ abstract class BaseRepositoryTests extends ArtifactoryTestsBase {
174175

175176
@AfterMethod
176177
protected void tearDown() {
177-
// Invoking sequence is important!
178-
deleteRepoIfExists(genericRepo?.getKey())
179-
deleteRepoIfExists(localRepo?.getKey())
180-
deleteRepoIfExists(remoteRepo?.getKey())
181-
deleteRepoIfExists(federatedRepo?.getKey())
182-
deleteRepoIfExists(virtualRepo?.getKey())
178+
// Invoking sequence is important! Delete in reverse dependency order
179+
deleteRepoWithRetry(virtualRepo?.getKey()) // Delete virtual repo first (depends on generic)
180+
deleteRepoWithRetry(federatedRepo?.getKey())
181+
deleteRepoWithRetry(remoteRepo?.getKey())
182+
deleteRepoWithRetry(localRepo?.getKey())
183+
deleteRepoWithRetry(genericRepo?.getKey()) // Delete generic repo last (after dependents)
183184
repoUniqueId++
184185
}
185186

services/src/test/groovy/org/jfrog/artifactory/client/TerraformPackageTypeRepositoryTests.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TerraformPackageTypeRepositoryTests extends BaseRepositoryTests {
1515

1616
TerraformPackageTypeRepositoryTests() {
1717
remoteRepoUrl = "https://github.com"
18+
storeArtifactsLocallyInRemoteRepo = true
1819
}
1920

2021
@Override

services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTestsBase.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Arrays;
2727
import java.util.Collection;
2828
import java.util.Properties;
29+
import java.util.logging.Logger;
2930

3031
import static org.apache.commons.codec.binary.Base64.encodeBase64;
3132
import static org.apache.commons.lang3.StringUtils.isEmpty;
@@ -55,6 +56,7 @@ public abstract class ArtifactoryTestsBase {
5556
protected VirtualRepository virtualRepository;
5657
protected RemoteRepository remoteRepository;
5758
protected String federationUrl;
59+
private static final Logger logger = Logger.getLogger(ArtifactoryTestsBase.class.getName());
5860

5961
@BeforeClass
6062
public void init() throws IOException {
@@ -208,6 +210,40 @@ protected String textFrom(InputStream is) throws IOException {
208210
}
209211
}
210212

213+
protected void deleteRepoWithRetry(String repoKey) {
214+
for (int attempt = 1; attempt <= 3; attempt++) {
215+
try {
216+
logger.info("Attempt " + attempt + " to delete repo: " + repoKey);
217+
deleteRepoIfExists(repoKey);
218+
logger.info("Successfully deleted repo: " + repoKey + " on attempt " + attempt);
219+
return;
220+
} catch (RuntimeException e) {
221+
Throwable cause = e.getCause();
222+
logger.warning("Attempt " + attempt + " failed to delete repo: " + repoKey + ". Reason: " + e.getMessage());
223+
if (cause instanceof HttpResponseException &&
224+
((HttpResponseException) cause).getStatusCode() == 500 &&
225+
cause.getMessage() != null && cause.getMessage().contains("Lock on LockEntryId")) {
226+
227+
if (attempt < 3) {
228+
logger.info("Lock detected. Retrying after 5 seconds...");
229+
try {
230+
Thread.sleep(5000);
231+
} catch (InterruptedException ie) {
232+
Thread.currentThread().interrupt();
233+
logger.warning("Retry interrupted while waiting to retry repo deletion: " + repoKey);
234+
return;
235+
}
236+
} else {
237+
logger.severe("Failed to delete repo after 3 attempts due to lock: " + repoKey);
238+
}
239+
} else {
240+
logger.severe("Non-lock error occurred. Not retrying. Repo: " + repoKey);
241+
return; // Non-lock error, don't retry
242+
}
243+
}
244+
}
245+
}
246+
211247
protected String deleteRepoIfExists(String repoName) {
212248
if (isEmpty(repoName)) {
213249
return null;
@@ -220,7 +256,8 @@ protected String deleteRepoIfExists(String repoName) {
220256
//if repo wasn't found - that's ok.
221257
return e.getMessage();
222258
} else {
223-
throw e;
259+
// Wrap checked exception in a RuntimeException to avoid signature changes
260+
throw new RuntimeException(e);
224261
}
225262
}
226263
}

0 commit comments

Comments
 (0)