Test truncated library snapshot headers

This commit is contained in:
jay
2026-11-13 20:57:37 -05:00
parent 17172705b4
commit 86eb441d33
@@ -20,6 +20,7 @@ package org.oxycblt.musikr.snapshot
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.EOFException
import java.io.IOException import java.io.IOException
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows import org.junit.Assert.assertThrows
@@ -60,4 +61,16 @@ class LibrarySnapshotCodecTest {
LibrarySnapshotCodec.readHeader(ByteArrayInputStream(bytes)) LibrarySnapshotCodec.readHeader(ByteArrayInputStream(bytes))
} }
} }
@Test
fun readHeader_truncatedSchemaVersion_throwsEOFException() {
val output = ByteArrayOutputStream()
LibrarySnapshotCodec.writeHeader(output)
val bytes = output.toByteArray()
val truncated = bytes.copyOf(bytes.size - 1)
assertThrows(EOFException::class.java) {
LibrarySnapshotCodec.readHeader(ByteArrayInputStream(truncated))
}
}
} }