From 8ac04a0c2f5cd949a45866f938bd1aa72fbe56e2 Mon Sep 17 00:00:00 2001 From: cirakg Date: Mon, 19 Oct 2026 15:27:37 +0200 Subject: test(storage): cover records, vault, PINs, lockout and migrations 34 new tests (65 per device): round trips per entry type, every tampered byte, swapped records, the pending queue, the entry cap, a full store at 67 fill levels, the lockout schedule on a fake clock including restarts, erase, PIN change and reset, auto-lock wiping, and v0 to v1 migration. Adds an in-memory store with a size limit and storage benchmarks. Co-Authored-By: Claude Opus 5.5 --- test/util/UtilTest.mc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/util/UtilTest.mc') diff --git a/test/util/UtilTest.mc b/test/util/UtilTest.mc index ea689a6..c19d6d0 100644 --- a/test/util/UtilTest.mc +++ b/test/util/UtilTest.mc @@ -64,3 +64,33 @@ function jobsRunToCompletion(logger as Test.Logger) as Boolean { Jobs.runToCompletion(job, 3); return job.calls == 4 && job.done == 12; } + +(:test) +function bytesUtf8Validation(logger as Test.Logger) as Boolean { + var valid = [[0x41]b, [0xC3, 0xA9]b, [0xE2, 0x82, 0xAC]b, [0xF0, 0x9F, 0x98, 0x80]b, [0xF4, 0x8F, 0xBF, 0xBF]b]; + var invalid = [ + [0x00]b, // NUL + [0xC0, 0x80]b, // overlong NUL + [0xE0, 0x80, 0x80]b, // overlong + [0xED, 0xA0, 0x80]b, // surrogate + [0xF4, 0x90, 0x80, 0x80]b, // above U+10FFFF + [0xF5, 0x80, 0x80, 0x80]b, // invalid lead byte + [0xE2, 0x82]b, // truncated + [0x80]b, // lone continuation + [0xC3, 0x28]b // bad continuation + ]; + for (var i = 0; i < valid.size(); i++) { + var text = Bytes.toUtf8(valid[i] as ByteArray); + if (text == null || !Bytes.equal(Bytes.fromUtf8(text), valid[i] as ByteArray)) { + logger.error("valid UTF-8 case " + i + " rejected or changed"); + return false; + } + } + for (var i = 0; i < invalid.size(); i++) { + if (Bytes.toUtf8(invalid[i] as ByteArray) != null) { + logger.error("invalid UTF-8 case " + i + " accepted"); + return false; + } + } + return true; +} -- cgit v1.2.3