Skip to content
Merged
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
67 changes: 20 additions & 47 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.20.0</version>
<version>3.22.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand All @@ -45,96 +45,69 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.22.1</version>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<version>2.0.20</version>
</dependency>

<!-- S3 STORAGE & JSON DEPENDENCIES (PROVIDED) -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>9.0.3</version>
<version>9.0.4</version>
<scope>provided</scope>
</dependency>

<!-- AZURE BLOB STORAGE DEPENDENCY (PROVIDED) -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.35.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
<version>4.2.17.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>4.2.17.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http2</artifactId>
<version>4.2.17.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-dns</artifactId>
<version>4.2.17.Final</version>
<version>12.37.2</version>
<scope>provided</scope>
</dependency>

<!-- SHARED DEPENDENCIES (PROVIDED) -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
<version>4.12.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>2.3.21</version>
<version>2.4.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.85</version>
<scope>provided</scope>
</dependency>
<!-- Jackson dependencies are compile-scope to ensure LeaseFileLockingService (default locking in 2.0.0),
UploadInfo JSON serialization, S3, and Azure backends work out-of-the-box without NoClassDefFoundError. -->

<!-- Jackson dependencies are compile-scope to ensure LeaseFileLockingService (default
locking in 2.0.0),
UploadInfo JSON serialization, S3, and Azure backends work out-of-the-box without
NoClassDefFoundError. -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.22.3</version>
<version>2.23.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.22</version>
<version>2.23</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.22.3</version>
<version>2.23.0</version>
</dependency>

<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<version>2.0.20</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -181,7 +154,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.15</version>
<version>0.8.16</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
Expand Down Expand Up @@ -262,7 +235,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.6.1</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine} ${surefireJvmArgs}</argLine>
Expand All @@ -281,7 +254,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
<version>3.6.1</version>
<configuration>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>${failsafeArgLine} ${failsafeJvmArgs}</argLine>
Expand All @@ -308,7 +281,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.16.0</version>
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/me/desair/tus/server/upload/azure/AzureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ private AzureUtils() {
// Utility class
}

/**
* Checks whether a blob exists in Azure Blob Storage.
*
* @param blobClient The {@link BlobClient} to inspect
* @return {@code true} if the blob exists; {@code false} if it does not exist, argument is null,
* or an error occurs
*/
/**
* Calculates the cutoff timestamp before which listed blobs can be considered candidates for
* expiration, subtracting a safety margin to account for clock skew and in-flight writes.
Expand All @@ -38,10 +31,20 @@ public static OffsetDateTime calculateExpirationCutoff(Long uploadExpirationPeri
if (uploadExpirationPeriod == null || uploadExpirationPeriod <= 0) {
return null;
}
return OffsetDateTime.now()
.minus(Duration.ofMillis(Math.max(0L, uploadExpirationPeriod - 2000L)));
// Do not clamp (uploadExpirationPeriod - 2000L) at 0: when uploadExpirationPeriod is shorter
// than the 2000ms safety margin (e.g. 1ms in tests), the cutoff must remain in the future
// (now + 2000ms - uploadExpirationPeriod) so remote clocks slightly ahead of the host JVM
// do not cause newly expired blobs to be skipped.
return OffsetDateTime.now().minus(Duration.ofMillis(uploadExpirationPeriod - 2000L));
}

/**
* Checks whether a blob exists in Azure Blob Storage.
*
* @param blobClient The {@link BlobClient} to inspect
* @return {@code true} if the blob exists; {@code false} if it does not exist, argument is null,
* or an error occurs
*/
public static boolean blobExists(BlobClient blobClient) {
if (blobClient == null) {
return false;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/me/desair/tus/server/upload/s3/S3Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ public static ZonedDateTime calculateExpirationCutoff(Long uploadExpirationPerio
if (uploadExpirationPeriod == null || uploadExpirationPeriod <= 0) {
return null;
}
return ZonedDateTime.now()
.minus(Duration.ofMillis(Math.max(0L, uploadExpirationPeriod - 2000L)));
// Do not clamp (uploadExpirationPeriod - 2000L) at 0: when uploadExpirationPeriod is shorter
// than the 2000ms safety margin (e.g. 1ms in tests), the cutoff must remain in the future
// (now + 2000ms - uploadExpirationPeriod) so remote clocks slightly ahead of the host JVM
// do not cause newly expired objects to be skipped.
return ZonedDateTime.now().minus(Duration.ofMillis(uploadExpirationPeriod - 2000L));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ public void testCalculateExpirationCutoff() {
assertNull(AzureUtils.calculateExpirationCutoff(0L));
assertNull(AzureUtils.calculateExpirationCutoff(-100L));

OffsetDateTime now = OffsetDateTime.now();
OffsetDateTime shortCutoff = AzureUtils.calculateExpirationCutoff(1000L);
assertNotNull(shortCutoff);
assertTrue(shortCutoff.isAfter(now));

OffsetDateTime longCutoff = AzureUtils.calculateExpirationCutoff(10_000L);
assertNotNull(longCutoff);
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/me/desair/tus/server/upload/s3/S3UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.minio.messages.ErrorResponse;
import io.minio.messages.Item;
import java.io.InputStream;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -326,6 +327,22 @@ public void testParseErrorResponseHttp501() {
assertEquals(S3ErrorType.API_NOT_IMPLEMENTED, S3Utils.parseErrorResponse(ex));
}

@Test
public void testCalculateExpirationCutoff() {
assertNull(S3Utils.calculateExpirationCutoff(null));
assertNull(S3Utils.calculateExpirationCutoff(0L));
assertNull(S3Utils.calculateExpirationCutoff(-100L));

ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime shortCutoff = S3Utils.calculateExpirationCutoff(1000L);
assertNotNull(shortCutoff);
assertTrue(shortCutoff.isAfter(now));

ZonedDateTime longCutoff = S3Utils.calculateExpirationCutoff(10_000L);
assertNotNull(longCutoff);
assertTrue(longCutoff.isBefore(ZonedDateTime.now()));
}

private ErrorResponseException createExceptionWithCode(String code) {
ErrorResponse errorResponse = mock(ErrorResponse.class);
when(errorResponse.code()).thenReturn(code);
Expand Down
Loading