From 3d5dd65e306ba3ca560b3c221830ee4cdb4363fb Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Mon, 6 Nov 2017 12:41:00 +0100 Subject: 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. --- .../java/com/zeapo/pwdstore/PasswordEntryTest.java | 18 ++++++++++++++++++ .../androidTest/java/com/zeapo/pwdstore/TotpTest.java | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java (limited to 'app/src/androidTest/java') 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); + } +} -- cgit v1.2.3