@@ -186,6 +186,33 @@ public void testGetWithBytesRange() {
186186 );
187187 }
188188
189+ public void testZeroLengthObjectGets () {
190+ final var bucket = randomIdentifier ();
191+ final var handler = new GoogleCloudStorageHttpHandler (bucket );
192+ final var blobName = "blob_name_" + randomIdentifier ();
193+ final var blobBytes = BytesArray .EMPTY ;
194+
195+ assertEquals (RestStatus .OK , executeMultipartUpload (handler , bucket , blobName , blobBytes , 0L ).restStatus ());
196+
197+ assertEquals (
198+ "No Range" ,
199+ new TestHttpResponse (RestStatus .OK , blobBytes , TestHttpExchange .EMPTY_HEADERS ),
200+ getBlobContents (handler , bucket , blobName , null , null )
201+ );
202+
203+ assertEquals (
204+ "Range 0-0" ,
205+ new TestHttpResponse (RestStatus .REQUESTED_RANGE_NOT_SATISFIED , BytesArray .EMPTY , TestHttpExchange .EMPTY_HEADERS ),
206+ getBlobContents (handler , bucket , blobName , null , new HttpHeaderParser .Range (0 , 0 ))
207+ );
208+
209+ assertEquals (
210+ "Random range x-y" ,
211+ new TestHttpResponse (RestStatus .REQUESTED_RANGE_NOT_SATISFIED , BytesArray .EMPTY , TestHttpExchange .EMPTY_HEADERS ),
212+ getBlobContents (handler , bucket , blobName , null , new HttpHeaderParser .Range (randomIntBetween (0 , 30 ), randomIntBetween (31 , 100 )))
213+ );
214+ }
215+
189216 public void testResumableUpload () {
190217 final var bucket = randomIdentifier ();
191218 final var handler = new GoogleCloudStorageHttpHandler (bucket );
@@ -545,7 +572,6 @@ private static TestHttpResponse executeUpload(
545572 BytesReference bytes ,
546573 Long ifGenerationMatch
547574 ) {
548- assert bytes .length () > 20 ;
549575 if (randomBoolean ()) {
550576 return executeResumableUpload (handler , bucket , blobName , bytes , ifGenerationMatch );
551577 } else {
@@ -560,6 +586,7 @@ private static TestHttpResponse executeResumableUpload(
560586 BytesReference bytes ,
561587 Long ifGenerationMatch
562588 ) {
589+ assert bytes .length () >= 2 : "We can't split anything smaller than two" ;
563590 final var createUploadResponse = handleRequest (
564591 handler ,
565592 "POST" ,
@@ -572,7 +599,7 @@ private static TestHttpResponse executeResumableUpload(
572599 final var sessionURI = locationHeader .substring (locationHeader .indexOf (HOST ) + HOST .length ());
573600 assertEquals (RestStatus .OK , createUploadResponse .restStatus ());
574601
575- final int partBoundary = randomIntBetween (10 , bytes .length () - 1 );
602+ final int partBoundary = randomIntBetween (1 , bytes .length () - 1 );
576603 final var part1 = bytes .slice (0 , partBoundary );
577604 final var uploadPart1Response = handleRequest (handler , "PUT" , sessionURI , part1 , contentRangeHeader (0 , partBoundary - 1 , null ));
578605 assertEquals (RESUME_INCOMPLETE , uploadPart1Response .status ());
0 commit comments