aboutsummaryrefslogtreecommitdiff
path: root/passgen/diceware/src/test/kotlin
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-12-10 13:59:32 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-12-21 13:01:40 +0530
commitc5436b543df466657a1d0dc3af40d4707fca9b9d (patch)
treea5b04250886153f0e9d4e1bba0867fbb8332fe04 /passgen/diceware/src/test/kotlin
parentab8f6a43eefab012900edd1ad9dbefd9a49b7429 (diff)
diceware: add passphrase generator
Diffstat (limited to 'passgen/diceware/src/test/kotlin')
-rw-r--r--passgen/diceware/src/test/kotlin/dev/msfjarvis/aps/passgen/diceware/DicewarePassphraseGeneratorTest.kt29
1 files changed, 29 insertions, 0 deletions
diff --git a/passgen/diceware/src/test/kotlin/dev/msfjarvis/aps/passgen/diceware/DicewarePassphraseGeneratorTest.kt b/passgen/diceware/src/test/kotlin/dev/msfjarvis/aps/passgen/diceware/DicewarePassphraseGeneratorTest.kt
new file mode 100644
index 00000000..7f22fdcc
--- /dev/null
+++ b/passgen/diceware/src/test/kotlin/dev/msfjarvis/aps/passgen/diceware/DicewarePassphraseGeneratorTest.kt
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+package dev.msfjarvis.aps.passgen.diceware
+
+import kotlin.random.Random
+import kotlin.test.assertEquals
+import org.junit.Test
+
+class DicewarePassphraseGeneratorTest {
+ /** Pre-seeded [Random] instance to ensure tests are deterministic. */
+ private val random = Random(1_00_000)
+
+ private val intGenerator = RandomIntGenerator { it.random(random) }
+ @Test
+ fun generate_passphrase() {
+ val die = Die(6, intGenerator)
+
+ val generator =
+ DicewarePassphraseGenerator(
+ die,
+ WordListParserTest.getDefaultWordList(),
+ )
+
+ assertEquals("salvation_cozily_croon_trustee_fidgety", generator.generatePassphrase(5, '_'))
+ }
+}