Skip to content

Commit 55f7b7b

Browse files
committed
Add test case
1 parent 0dddb1a commit 55f7b7b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/io/SdkLengthAwareInputStreamTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,27 @@ void readByte_readExactLength_doesNotThrow() throws IOException {
249249
assertThat(total).isEqualTo(delegateLength);
250250
}
251251

252+
@Test
253+
void readBytePartialThenMark_doesNotResetContentLength() throws IOException {
254+
int delegateLength = 16;
255+
int expectedContentLength = delegateLength + 1;
256+
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
257+
258+
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, expectedContentLength);
259+
is.read(); // read one byte
260+
is.mark(1024);
261+
// read another byte and reset, the length should not be reset based on the byte that was already read
262+
is.read();
263+
is.reset();
264+
assertThatThrownBy(() -> {
265+
int read;
266+
while ((read = is.read()) != -1) {
267+
}
268+
})
269+
.isInstanceOf(IllegalStateException.class)
270+
.hasMessageContaining("The request content has fewer bytes than the specified content-length: " + expectedContentLength);
271+
}
272+
252273
@Test
253274
void readByte_delegateLongerThanRequired_truncated() throws IOException {
254275
int delegateLength = 32;

0 commit comments

Comments
 (0)