diff options
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(""); +} |
