From 62dbc183d52d93860228316b209ec5aa15f16a08 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 25 Jul 2020 14:37:16 +0530 Subject: Properly handle files without passwords (#969) * Properly handle files without passwords Fixes #967 Signed-off-by: Harsh Shandilya * Fix tests Signed-off-by: Harsh Shandilya * Only look for TOTP URI Signed-off-by: Harsh Shandilya --- .../pwdstore/model/PasswordEntryAndroidTest.kt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/model/PasswordEntryAndroidTest.kt b/app/src/androidTest/java/com/zeapo/pwdstore/model/PasswordEntryAndroidTest.kt index ba373f48..1928a5f4 100644 --- a/app/src/androidTest/java/com/zeapo/pwdstore/model/PasswordEntryAndroidTest.kt +++ b/app/src/androidTest/java/com/zeapo/pwdstore/model/PasswordEntryAndroidTest.kt @@ -84,6 +84,29 @@ class PasswordEntryAndroidTest { assertEquals("545293", code) } + @Test fun testGeneratesOtpWithOnlyUriInFile() { + val entry = makeEntry(TOTP_URI) + assertTrue(entry.password.isEmpty()) + assertTrue(entry.hasTotp()) + val code = Otp.calculateCode( + entry.totpSecret!!, + // The hardcoded date value allows this test to stay reproducible. + Date(8640000).time / (1000 * entry.totpPeriod), + entry.totpAlgorithm, + entry.digits + ) + assertNotNull(code) { "Generated OTP cannot be null" } + assertEquals(entry.digits.toInt(), code.length) + assertEquals("545293", code) + } + + @Test fun testOnlyLooksForUriInFirstLine() { + val entry = makeEntry("id:\n$TOTP_URI") + assertTrue(entry.password.isNotEmpty()) + assertTrue(entry.hasTotp()) + assertFalse(entry.hasUsername()) + } + companion object { const val TOTP_URI = "otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30" -- cgit v1.2.3