summaryrefslogtreecommitdiff
path: root/app/src/androidTest
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2017-11-06 12:41:00 +0100
committerMohamed Zenadi <zeapo@users.noreply.github.com>2017-11-19 11:14:45 +0100
commit3d5dd65e306ba3ca560b3c221830ee4cdb4363fb (patch)
tree6a417353098a9dc22093568c7e6c1dd505997512 /app/src/androidTest
parent67a7b124eec9178f8539664bf4d2528a111465b2 (diff)
Display TOTP code if entry contains OTP secret
TOTP is calculated on display and on copy to clipboard from secret embedded in entry (either in password or in extra) and the current time.
Diffstat (limited to 'app/src/androidTest')
-rw-r--r--app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java18
-rw-r--r--app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java12
2 files changed, 30 insertions, 0 deletions
diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java b/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java
index 66636b1b..e8ddc04c 100644
--- a/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java
+++ b/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java
@@ -41,4 +41,22 @@ public class PasswordEntryTest extends TestCase {
assertFalse(new PasswordEntry("\n").hasUsername());
assertFalse(new PasswordEntry("").hasUsername());
}
+
+ public void testNoTotpUriPresent() {
+ PasswordEntry entry = new PasswordEntry("secret\nextra\nlogin: username\ncontent");
+ assertFalse(entry.hasTotp());
+ assertNull(entry.getTotpSecret());
+ }
+
+ public void testTotpUriInPassword() {
+ PasswordEntry entry = new PasswordEntry("otpauth://totp/test?secret=JBSWY3DPEHPK3PXP");
+ assertTrue(entry.hasTotp());
+ assertEquals("JBSWY3DPEHPK3PXP", entry.getTotpSecret());
+ }
+
+ public void testTotpUriInContent() {
+ PasswordEntry entry = new PasswordEntry("secret\nusername: test\notpauth://totp/test?secret=JBSWY3DPEHPK3PXP");
+ assertTrue(entry.hasTotp());
+ assertEquals("JBSWY3DPEHPK3PXP", entry.getTotpSecret());
+ }
} \ No newline at end of file
diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java b/app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java
new file mode 100644
index 00000000..500644d1
--- /dev/null
+++ b/app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java
@@ -0,0 +1,12 @@
+package com.zeapo.pwdstore;
+
+import com.zeapo.pwdstore.utils.Totp;
+
+import junit.framework.TestCase;
+
+public class TotpTest extends TestCase {
+ public void testTotp() {
+ String code = Totp.calculateCode("JBSWY3DPEHPK3PXP", 0L);
+ assertEquals("282760", code);
+ }
+}