aboutsummaryrefslogtreecommitdiff
path: root/app/src/test/java/dev
diff options
context:
space:
mode:
authorAditya Wasan <adityawasan55@gmail.com>2021-02-19 13:57:57 +0530
committerGitHub <noreply@github.com>2021-02-19 08:27:57 +0000
commitd17ff0d9251bd2ad84778535dabe4884a4cf9d76 (patch)
tree57c2cfd031632e8687c038bd35ff2b39f61f6d77 /app/src/test/java/dev
parent92ece7dbb5607258bcf954963009bf1f9411ab07 (diff)
Parse extra content into key value pairs (#1321)
* ui: add skeleton recyclerview to parse extra content Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * ui: add recyclerview and update PasswordEntry to create map of key-value pairs Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * password-entry: When key-value pair is not correctly formed, display it as Extra Content Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix formatting Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * bug: update otp code on main thread Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Add complete string if key-value pair cannot be formed Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * test: add a few tests for key-value parsing logic Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * prefs: remove SHOW_EXTRA_CONTENT from shared preferences Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Update CHANGELOG.md * Cleanup and refactor Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * PasswordEntryTest: silence nullability warning Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * PasswordEntry: simplify constructor Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * PasswordEntry: annotate test-enablement visibility Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Reintroduce the catch-all field Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * update parsing logic Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * add one more test case Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Add missing newlines Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Remove unnecessary scrollview Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * rv: do not return if hasExtraContent is false Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Don't anchor RV to bottom Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/test/java/dev')
-rw-r--r--app/src/test/java/dev/msfjarvis/aps/data/password/PasswordEntryTest.kt34
1 files changed, 33 insertions, 1 deletions
diff --git a/app/src/test/java/dev/msfjarvis/aps/data/password/PasswordEntryTest.kt b/app/src/test/java/dev/msfjarvis/aps/data/password/PasswordEntryTest.kt
index a627dd7a..aab7d1d2 100644
--- a/app/src/test/java/dev/msfjarvis/aps/data/password/PasswordEntryTest.kt
+++ b/app/src/test/java/dev/msfjarvis/aps/data/password/PasswordEntryTest.kt
@@ -50,6 +50,38 @@ class PasswordEntryTest {
assertEquals("", makeEntry("").extraContent)
}
+ @Test fun parseExtraContentWithoutAuth() {
+ var entry = makeEntry("username: abc\npassword: abc\ntest: abcdef")
+ assertEquals(1, entry.extraContentMap.size)
+ assertTrue(entry.extraContentMap.containsKey("test"))
+ assertEquals("abcdef", entry.extraContentMap["test"])
+
+ entry = makeEntry("username: abc\npassword: abc\ntest: :abcdef:")
+ assertEquals(1, entry.extraContentMap.size)
+ assertTrue(entry.extraContentMap.containsKey("test"))
+ assertEquals(":abcdef:", entry.extraContentMap["test"])
+
+ entry = makeEntry("username: abc\npassword: abc\ntest : ::abc:def::")
+ assertEquals(1, entry.extraContentMap.size)
+ assertTrue(entry.extraContentMap.containsKey("test"))
+ assertEquals("::abc:def::", entry.extraContentMap["test"])
+
+ entry = makeEntry("username: abc\npassword: abc\ntest: abcdef\ntest2: ghijkl")
+ assertEquals(2, entry.extraContentMap.size)
+ assertTrue(entry.extraContentMap.containsKey("test2"))
+ assertEquals("ghijkl", entry.extraContentMap["test2"])
+
+ entry = makeEntry("username: abc\npassword: abc\ntest: abcdef\n: ghijkl\n mnopqr:")
+ assertEquals(2, entry.extraContentMap.size)
+ assertTrue(entry.extraContentMap.containsKey("Extra Content"))
+ assertEquals(": ghijkl\n mnopqr:", entry.extraContentMap["Extra Content"])
+
+ entry = makeEntry("username: abc\npassword: abc\n:\n\n")
+ assertEquals(1, entry.extraContentMap.size)
+ assertTrue(entry.extraContentMap.containsKey("Extra Content"))
+ assertEquals(":", entry.extraContentMap["Extra Content"])
+ }
+
@Test fun testGetUsername() {
for (field in PasswordEntry.USERNAME_FIELDS) {
assertEquals("username", makeEntry("\n$field username").username)
@@ -133,7 +165,7 @@ class PasswordEntryTest {
// This implementation is hardcoded for the URI above.
val testFinder = object : TotpFinder {
- override fun findSecret(content: String): String? {
+ override fun findSecret(content: String): String {
return "HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ"
}