From 8fcf7cae469b479cbdb4b26af062a5560931589c Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 6 Feb 2021 20:41:57 +0000 Subject: [PATCH] Test the master index length validation code Signed-off-by: Graham --- .../kotlin/org/openrs2/cache/Js5MasterIndexTest.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt index f3231730b5..119b68d79c 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt +++ b/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 { + 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 { + Unpooled.wrappedBuffer(byteArrayOf(0, 0, 0, 0)).use { buf -> + Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED) + } + } } @Test