Add tests for corrupt containers

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent b51b2f5e77
commit e764403cb2
  1. 65
      cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt
  2. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/bzip2-eof.dat
  3. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/gzip-eof.dat
  4. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/invalid-length.dat
  5. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/invalid-type.dat
  6. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/invalid-uncompressed-length.dat
  7. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/lzma-eof.dat
  8. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/none-eof.dat

@ -4,6 +4,8 @@ import dev.openrs2.buffer.use
import dev.openrs2.crypto.XteaKey import dev.openrs2.crypto.XteaKey
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import org.junit.jupiter.api.assertThrows
import java.io.EOFException
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotEquals import kotlin.test.assertNotEquals
@ -255,6 +257,69 @@ object Js5CompressionTest {
} }
} }
@Test
fun testInvalidType() {
read("invalid-type.dat").use { compressed ->
assertThrows<IllegalArgumentException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testInvalidLength() {
read("invalid-length.dat").use { compressed ->
assertThrows<IllegalArgumentException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testInvalidUncompressedLength() {
read("invalid-uncompressed-length.dat").use { compressed ->
assertThrows<IllegalArgumentException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testNoneEof() {
read("none-eof.dat").use { compressed ->
assertThrows<IndexOutOfBoundsException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testBzip2Eof() {
read("bzip2-eof.dat").use { compressed ->
assertThrows<EOFException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testGzipEof() {
read("gzip-eof.dat").use { compressed ->
assertThrows<EOFException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testLzmaEof() {
read("lzma-eof.dat").use { compressed ->
assertThrows<EOFException> {
Js5Compression.uncompress(compressed).release()
}
}
}
private fun read(name: String): ByteBuf { private fun read(name: String): ByteBuf {
Js5CompressionTest::class.java.getResourceAsStream("compression/$name").use { input -> Js5CompressionTest::class.java.getResourceAsStream("compression/$name").use { input ->
return Unpooled.wrappedBuffer(input.readAllBytes()) return Unpooled.wrappedBuffer(input.readAllBytes())

Loading…
Cancel
Save