diff options
author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-11-06 10:50:34 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-06 10:50:34 +0530 |
commit | df6ebfee27597887075b94a945e707ecd69decb1 (patch) | |
tree | ebd05d44362f7bb518bef1a4861501813ca9bb9c /app/src | |
parent | 354687e3a60f348af75c1a2f901270264d7e0313 (diff) |
Fix extra content for multiple username fields (#1192)
Fixes #1190
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/model/PasswordEntry.kt | 4 | ||||
-rw-r--r-- | app/src/test/java/com/zeapo/pwdstore/model/PasswordEntryTest.kt | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/model/PasswordEntry.kt b/app/src/main/java/com/zeapo/pwdstore/model/PasswordEntry.kt index a143fcb9..5727c4ba 100644 --- a/app/src/main/java/com/zeapo/pwdstore/model/PasswordEntry.kt +++ b/app/src/main/java/com/zeapo/pwdstore/model/PasswordEntry.kt @@ -60,9 +60,11 @@ class PasswordEntry(content: String, private val totpFinder: TotpFinder = UriTot } val extraContentWithoutAuthData by lazy(LazyThreadSafetyMode.NONE) { + var foundUsername = false extraContent.splitToSequence("\n").filter { line -> return@filter when { - USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } -> { + USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } && !foundUsername -> { + foundUsername = true false } line.startsWith("otpauth://", ignoreCase = true) || diff --git a/app/src/test/java/com/zeapo/pwdstore/model/PasswordEntryTest.kt b/app/src/test/java/com/zeapo/pwdstore/model/PasswordEntryTest.kt index 04c606e8..082fc110 100644 --- a/app/src/test/java/com/zeapo/pwdstore/model/PasswordEntryTest.kt +++ b/app/src/test/java/com/zeapo/pwdstore/model/PasswordEntryTest.kt @@ -116,6 +116,17 @@ class PasswordEntryTest { assertFalse(entry.hasUsername()) } + // https://github.com/android-password-store/Android-Password-Store/issues/1190 + @Test fun extraContentWithMultipleUsernameFields() { + val entry = makeEntry("pass\nuser: user\nid: id\n$TOTP_URI") + assertTrue(entry.hasExtraContent()) + assertTrue(entry.hasTotp()) + assertTrue(entry.hasUsername()) + assertEquals("pass", entry.password) + assertEquals("user", entry.username) + assertEquals("id: id", entry.extraContentWithoutAuthData) + } + companion object { const val TOTP_URI = "otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30" |