diff --git a/server/src/main/java/com/adobe/testing/s3mock/ObjectController.java b/server/src/main/java/com/adobe/testing/s3mock/ObjectController.java index fc40ec542..5f788de93 100644 --- a/server/src/main/java/com/adobe/testing/s3mock/ObjectController.java +++ b/server/src/main/java/com/adobe/testing/s3mock/ObjectController.java @@ -973,7 +973,7 @@ private ResponseEntity getObjectWithRange( var contentLength = endInclusive - startInclusive + 1; if (contentLength < 0 || fileSize <= startInclusive) { - return ResponseEntity.status(REQUESTED_RANGE_NOT_SATISFIABLE).build(); + throw S3Exception.INVALID_RANGE; } return ResponseEntity diff --git a/server/src/main/java/com/adobe/testing/s3mock/S3Exception.java b/server/src/main/java/com/adobe/testing/s3mock/S3Exception.java index 7e9927523..86cc06a87 100644 --- a/server/src/main/java/com/adobe/testing/s3mock/S3Exception.java +++ b/server/src/main/java/com/adobe/testing/s3mock/S3Exception.java @@ -19,6 +19,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE; import com.adobe.testing.s3mock.dto.ErrorResponse; import org.springframework.http.HttpStatus; @@ -32,6 +33,8 @@ public class S3Exception extends RuntimeException { private static final String INVALID_REQUEST_CODE = "InvalidRequest"; private static final String BAD_REQUEST_CODE = "BadRequest"; + private static final String REQUESTED_RANGE_NOT_SATISFIABLE_CODE = "InvalidRange"; + public static final S3Exception INVALID_PART_NUMBER = new S3Exception(BAD_REQUEST.value(), "InvalidArgument", "Part number must be an integer between 1 and 10000, inclusive"); @@ -119,6 +122,10 @@ public static S3Exception completeRequestMissingChecksum(String algorithm, Integ + "changing the object's metadata, storage class, website redirect location or " + "encryption attributes."); + public static final S3Exception INVALID_RANGE = + new S3Exception(REQUESTED_RANGE_NOT_SATISFIABLE.value(), REQUESTED_RANGE_NOT_SATISFIABLE_CODE, + "Invalid http range."); + public static final S3Exception BAD_REQUEST_MD5 = new S3Exception(BAD_REQUEST.value(), BAD_REQUEST_CODE, "Content-MD5 does not match object md5"); diff --git a/server/src/test/kotlin/com/adobe/testing/s3mock/ObjectControllerTest.kt b/server/src/test/kotlin/com/adobe/testing/s3mock/ObjectControllerTest.kt index 5f25b3a58..e75d236d9 100644 --- a/server/src/test/kotlin/com/adobe/testing/s3mock/ObjectControllerTest.kt +++ b/server/src/test/kotlin/com/adobe/testing/s3mock/ObjectControllerTest.kt @@ -918,6 +918,7 @@ internal class ObjectControllerTest : BaseControllerTest() { .header("Range", "bytes=9999999-10000000") ) .andExpect(status().isRequestedRangeNotSatisfiable) + .andExpect(content().string(MAPPER.writeValueAsString(from(S3Exception.INVALID_RANGE)))) } @Test