diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-21 03:55:01 +0200 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-21 03:55:01 +0200 |
| commit | a69e23fb5266dd942d125239e7dcbe8a7c8ab956 (patch) | |
| tree | 164c7ed21b550ac3d5fef567060ffad4e40e4583 /test/import/ImporterTest.mc | |
| parent | 6039571d70b1f6de1ae384e58e11879869be356c (diff) | |
perf(import): keep parsed items packed and the pasted text once
A parsed import item with its Entry took about 760 bytes as objects on the
Forerunner 255S; packed into one Codec ByteArray it takes about 110, and
the importer unpacks one item per store step (wiping the packed secret).
Aegis group names are resolved when unpacking, so no step repacks all
items. The JSON is parsed from the untrimmed text's bytes and the string
is dropped; an incomplete part is saved from those bytes. The form hash
is computed before the importer copies the text.
The peak of a 100-entry import on the 255S falls from 56 % to 45 %.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test/import/ImporterTest.mc')
| -rw-r--r-- | test/import/ImporterTest.mc | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/test/import/ImporterTest.mc b/test/import/ImporterTest.mc index 411e528..3443f4e 100644 --- a/test/import/ImporterTest.mc +++ b/test/import/ImporterTest.mc @@ -1,5 +1,5 @@ // Author: cirakg & claude ai -// Summary: Tests for the import job: reports, duplicates, replacements, locking, Replace mode, multi-part buffer, failures, a full store, 100 entries. +// Summary: Tests for the import job: reports, duplicates, replacements, locking, Replace mode, multi-part buffer, failures, a full store, 100 entries, packed items. import Toybox.Lang; import Toybox.System; @@ -206,3 +206,60 @@ function importerHandlesOneHundredEntries(logger as Test.Logger) as Boolean { logger.debug("BENCH import_100_aegis ms=" + elapsed + " steps=" + steps + " json_bytes=" + text.length()); return job.report.imported == 100 && vault.ids().size() == 100; } + +// Packed items (M8 memory) keep every field, resolve the group when +// unpacked, and leave no second copy of the secret. +(:test) +function importItemsPackAndUnpack(logger as Test.Logger) as Boolean { + var e = new Entry(); + e.type = Entry.OTP_HOTP; + e.name = "Bänk €"; + e.account = "bob"; + e.favorite = true; + e.algorithm = Hashes.SHA512; + e.digits = 8; + e.period = 60; + e.counter = 5000000000l; + var secret = [1, 2, 3, 4, 5]b; + e.secret = secret; + var item = new ImportItem(7); + item.label = e.name; + item.note = "issuer differs"; + item.groupRef = "uuid:g-1"; + item.entry = e; + var packed = item.pack(); + var wiped = secret[0] == 0 && secret[4] == 0 && e.secret == null; + var back = ImportItem.unpack(packed, {"g-1" => "Work"} as Dictionary<String, String>); + var b = back.entry; + if (!wiped || b == null) { + logger.error("wiped " + wiped + ", entry " + b); + return false; + } + var fieldsOk = back.index == 7 && back.label.equals("Bänk €") && "issuer differs".equals(back.note) && back.problem == null + && b.kind == Entry.KIND_OTP && b.source == Entry.SOURCE_IMPORT && b.type == Entry.OTP_HOTP && b.name.equals("Bänk €") + && b.account.equals("bob") && b.favorite && b.algorithm == Hashes.SHA512 && b.digits == 8 && b.period == 60 + && b.counter == 5000000000l && Bytes.equal(b.secret as ByteArray, [1, 2, 3, 4, 5]b) && b.group.equals("Work") + && b.validate() == null; + + var bad = new ImportItem(3); + bad.label = "x"; + bad.problem = "secret missing"; + bad.groupRef = "name:Private"; + var badBack = ImportItem.unpack(bad.pack(), {} as Dictionary<String, String>); + var named = new ImportItem(4); + named.groupRef = "name: Private "; + var namedEntry = new Entry(); + namedEntry.name = "Mail"; + namedEntry.secret = [9]b; + named.entry = namedEntry; + var namedBack = ImportItem.unpack(named.pack(), {} as Dictionary<String, String>).entry; + var missing = new ImportItem(5); + missing.groupRef = "uuid:nope"; + var missingEntry = new Entry(); + missingEntry.name = "Mail"; + missingEntry.secret = [9]b; + missing.entry = missingEntry; + var missingBack = ImportItem.unpack(missing.pack(), {} as Dictionary<String, String>).entry; + return fieldsOk && badBack.entry == null && "secret missing".equals(badBack.problem) && badBack.index == 3 + && namedBack != null && namedBack.group.equals("Private") && missingBack != null && missingBack.group.equals(""); +} |
