Test the master index length validation code

Signed-off-by: Graham <gpe@openrs2.org>
pull/132/head
Graham 3 years ago
parent 4126abfaad
commit 8fcf7cae46
  1. 13
      cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt

@ -2,6 +2,7 @@ package org.openrs2.cache
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.Unpooled
import org.junit.jupiter.api.assertThrows
import org.openrs2.buffer.use
import java.nio.file.Path
import kotlin.test.Test
@ -61,6 +62,12 @@ object Js5MasterIndexTest {
val index = Js5MasterIndex.read(buf, MasterIndexFormat.ORIGINAL)
assertEquals(decodedOriginal, index)
}
assertThrows<IllegalArgumentException> {
Unpooled.wrappedBuffer(byteArrayOf(0)).use { buf ->
Js5MasterIndex.read(buf, MasterIndexFormat.ORIGINAL)
}
}
}
@Test
@ -80,6 +87,12 @@ object Js5MasterIndexTest {
val index = Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED)
assertEquals(decodedVersioned, index)
}
assertThrows<IllegalArgumentException> {
Unpooled.wrappedBuffer(byteArrayOf(0, 0, 0, 0)).use { buf ->
Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED)
}
}
}
@Test

Loading…
Cancel
Save