mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-30 22:05:19 +00:00
PasswordEntry: add more potential fields for username (#764)
This commit is contained in:
@@ -34,6 +34,10 @@ class PasswordEntryTest {
|
||||
}
|
||||
|
||||
@Test fun testGetUsername() {
|
||||
for (field in PasswordEntry.USERNAME_FIELDS) {
|
||||
assertEquals("username", PasswordEntry("\n$field username").username)
|
||||
assertEquals("username", PasswordEntry("\n${field.toUpperCase()} username").username)
|
||||
}
|
||||
assertEquals(
|
||||
"username",
|
||||
PasswordEntry("secret\nextra\nlogin: username\ncontent\n").username)
|
||||
@@ -42,6 +46,9 @@ class PasswordEntryTest {
|
||||
PasswordEntry("\nextra\nusername: username\ncontent\n").username)
|
||||
assertEquals(
|
||||
"username", PasswordEntry("\nUSERNaMe: username\ncontent\n").username)
|
||||
assertEquals("username", PasswordEntry("\nlogin: username").username)
|
||||
assertEquals("foo@example.com", PasswordEntry("\nemail: foo@example.com").username)
|
||||
assertEquals("username", PasswordEntry("\nidentity: username\nlogin: another_username").username)
|
||||
assertEquals("username", PasswordEntry("\nLOGiN:username").username)
|
||||
assertNull(PasswordEntry("secret\nextra\ncontent\n").username)
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@
|
||||
package com.zeapo.pwdstore
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.annotation.VisibleForTesting.PRIVATE
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.UnsupportedEncodingException
|
||||
|
||||
@@ -162,7 +164,16 @@ class PasswordEntry(private val content: String) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val USERNAME_FIELDS = arrayOf("login:", "username:")
|
||||
@VisibleForTesting(otherwise = PRIVATE)
|
||||
val USERNAME_FIELDS = arrayOf(
|
||||
"login:",
|
||||
"username:",
|
||||
"account:",
|
||||
"email:",
|
||||
"name:",
|
||||
"handle:",
|
||||
"id:",
|
||||
"identity:"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user