summaryrefslogtreecommitdiff
path: root/format-common/src/test
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-02-01 19:21:01 +0530
committerGitHub <noreply@github.com>2022-02-01 19:21:01 +0530
commitcf111f197856673185817921460025e7324ac512 (patch)
tree7a2b93ff755e6b55063f0b61fdd5506de59c8df9 /format-common/src/test
parentcf92d8a5a3b15f8866ef9782c68298f59dcb8aed (diff)
Refactor PasswordEntry TOTP calculation into a cold flow (#1702)
Diffstat (limited to 'format-common/src/test')
-rw-r--r--format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt34
1 files changed, 13 insertions, 21 deletions
diff --git a/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt b/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt
index 0f63a74a..d8a1fdc2 100644
--- a/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt
+++ b/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt
@@ -6,10 +6,10 @@
package dev.msfjarvis.aps.data.passfile
import dev.msfjarvis.aps.test.CoroutineTestRule
+import dev.msfjarvis.aps.test.test2
import dev.msfjarvis.aps.util.time.TestUserClock
import dev.msfjarvis.aps.util.totp.TotpFinder
import java.util.Locale
-import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
@@ -17,7 +17,6 @@ import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Rule
@@ -29,8 +28,6 @@ class PasswordEntryTest {
PasswordEntry(
fakeClock,
testFinder,
- coroutineTestRule.testDispatcherProvider,
- TestScope(coroutineTestRule.testDispatcher),
content.encodeToByteArray(),
)
@@ -133,27 +130,22 @@ class PasswordEntryTest {
}
@Test
- @Ignore("Timing with runTest seems hard to implement right now")
- fun testGeneratesOtpFromTotpUri() {
- runTest {
- val entry = makeEntry("secret\nextra\n$TOTP_URI")
- assertTrue(entry.hasTotp())
- val code = entry.totp.value
- assertNotNull(code) { "Generated OTP cannot be null" }
- assertEquals("818800", code)
+ fun testGeneratesOtpFromTotpUri() = runTest {
+ val entry = makeEntry("secret\nextra\n$TOTP_URI")
+ assertTrue(entry.hasTotp())
+ entry.totp.test2 {
+ assertEquals("818800", expectMostRecentItem())
+ cancelAndIgnoreRemainingEvents()
}
}
@Test
- @Ignore("Timing with runTest seems hard to implement right now")
- fun testGeneratesOtpWithOnlyUriInFile() {
- runTest {
- val entry = makeEntry(TOTP_URI)
- assertNull(entry.password)
- assertTrue(entry.hasTotp())
- val code = entry.totp.value
- assertNotNull(code) { "Generated OTP cannot be null" }
- assertEquals("818800", code)
+ fun testGeneratesOtpWithOnlyUriInFile() = runTest {
+ val entry = makeEntry(TOTP_URI)
+ assertNull(entry.password)
+ entry.totp.test2 {
+ assertEquals("818800", expectMostRecentItem())
+ cancelAndIgnoreRemainingEvents()
}
}