From a10693e79e612701ecc461d6e1933b0cd5845e24 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Tue, 23 Jul 2024 20:26:45 +0200 Subject: [PATCH] Expand the number of cases covered under the slot exclusion tests --- .../aegis/vault/slots/SlotTest.java | 70 ++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/app/src/test/java/com/beemdevelopment/aegis/vault/slots/SlotTest.java b/app/src/test/java/com/beemdevelopment/aegis/vault/slots/SlotTest.java index dbee9f54..56a939b2 100644 --- a/app/src/test/java/com/beemdevelopment/aegis/vault/slots/SlotTest.java +++ b/app/src/test/java/com/beemdevelopment/aegis/vault/slots/SlotTest.java @@ -96,20 +96,84 @@ public class SlotTest { @Test public void testNonExportableSlotsExclusion() { - Slot rawSlot = new RawSlot(); + // If a backup password slot, multiple regular password slots and a biometric slot are present: + // -> The Regular password slots and the biometric slot get stripped Slot passwordSlot = new PasswordSlot(); + Slot passwordSlot2 = new PasswordSlot(); Slot biometricSlot = new BiometricSlot(); PasswordSlot backupSlot = new PasswordSlot(); backupSlot.setIsBackup(true); SlotList slots = new SlotList(); - slots.add(rawSlot); slots.add(passwordSlot); + slots.add(passwordSlot2); slots.add(biometricSlot); slots.add(backupSlot); SlotList actual = slots.exportable(); SlotList expected = new SlotList(); - expected.add(rawSlot); expected.add(backupSlot); assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); + + // If a backup password slot, a regular password slot and a biometric slot are present: + // -> The Regular password slot and the biometric slot get stripped + slots = new SlotList(); + slots.add(passwordSlot); + slots.add(biometricSlot); + slots.add(backupSlot); + actual = slots.exportable(); + expected = new SlotList(); + expected.add(backupSlot); + assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); + + // If a backup password slot and a regular password slot are present: + // -> The regular password slot get stripped + slots = new SlotList(); + slots.add(passwordSlot); + slots.add(backupSlot); + actual = slots.exportable(); + expected = new SlotList(); + expected.add(backupSlot); + assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); + + // If a backup password slot and multiple regular password slot are present: + // -> The regular password slots get stripped + slots = new SlotList(); + slots.add(passwordSlot); + slots.add(passwordSlot2); + slots.add(backupSlot); + actual = slots.exportable(); + expected = new SlotList(); + expected.add(backupSlot); + assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); + + // If multiple regular password slots and a biometric slot are present: + // -> The biometric slot gets stripped + slots = new SlotList(); + slots.add(passwordSlot); + slots.add(passwordSlot2); + slots.add(biometricSlot); + actual = slots.exportable(); + expected = new SlotList(); + expected.add(passwordSlot); + expected.add(passwordSlot2); + assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); + + // If a regular password slot and a biometric slot are present + // -> The biometric slot gets stripped + slots = new SlotList(); + slots.add(passwordSlot); + slots.add(biometricSlot); + actual = slots.exportable(); + expected = new SlotList(); + expected.add(passwordSlot); + assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); + + // If a regular password slot is present + // -> No slots get stripped + slots = new SlotList(); + slots.add(passwordSlot); + actual = slots.exportable(); + expected = new SlotList(); + expected.add(passwordSlot); + assertArrayEquals(expected.getValues().toArray(), actual.getValues().toArray()); } }