Expand range validation and event dispatch unit tests

This commit is contained in:
tongtong committed 2026-11-20 11:17:12 +08:00
1 parent 94e19b4fe4
commit 4fe8b4c6f9
2 files changed
+168

No files matched your search

@@ -22,4 +22,46 @@ public class HttpRangeValidatorTest {
@Test(expected = IOException.class) public void rejectsOverflow() throws Exception {
HttpRangeValidator.validate(206, "bytes 10-9999999999999999999999/100", null, 10, 20);
}
@Test public void acceptsUnknownTotal() throws Exception {
HttpRangeValidator.validate(206, "bytes 10-19/*", null, 10, 20);
}
@Test public void acceptsSingleByteAtEnd() throws Exception {
HttpRangeValidator.validate(206, "bytes 99-99/100", "IDENTITY", 99, 100);
}
@Test public void acceptsLargeFileOffsets() throws Exception {
HttpRangeValidator.validate(206, "bytes 4294967296-4294967395/8589934592",
"identity", 4294967296L, 4294967396L);
}
@Test public void acceptsWhitespaceAroundHeader() throws Exception {
HttpRangeValidator.validate(206, " bytes 10-19/100 ", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsMissingHeaderForPartialResponse()
throws Exception {
HttpRangeValidator.validate(206, null, null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsUnsatisfiableResponse() throws Exception {
HttpRangeValidator.validate(416, "bytes */100", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsRedirect() throws Exception {
HttpRangeValidator.validate(302, "bytes 10-19/100", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsTotalSmallerThanRange() throws Exception {
HttpRangeValidator.validate(206, "bytes 10-19/19", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsTotalOverflow() throws Exception {
HttpRangeValidator.validate(206, "bytes 10-19/9999999999999999999999", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsExtraBytes() throws Exception {
HttpRangeValidator.validate(206, "bytes 10-20/100", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsNegativeOffset() throws Exception {
HttpRangeValidator.validate(206, "bytes -1-19/100", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsMalformedHeader() throws Exception {
HttpRangeValidator.validate(206, "bytes ten-nineteen/100", null, 10, 20);
}
@Test(expected = IOException.class) public void rejectsMultipartHeader() throws Exception {
HttpRangeValidator.validate(206, "bytes 10-19/100, 30-39/100", null, 10, 20);
}
}