From eea0e68dda1eb7248c6d458f52baeedb318b466a Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Tue, 25 Sep 2018 13:45:54 -0400 Subject: Display HOTP code if password contains HOTP secret, unify HOTP and TOTP code (#413) * Display HOTP code if password contains HOTP secret, unify HOTP and TOTP code * Add ability to show HOTP instead of showing every decrypt * Fix off by 1 error * fix return intent logic so that edits and HOTP increments are properly committed * fix linting errors * Fix broken logic for case when a password is created * add ability to choose if password entry will be updated on HOTP code calculation --- .../java/com/zeapo/pwdstore/OtpTest.java | 12 ++++++++++++ .../java/com/zeapo/pwdstore/PasswordEntryTest.java | 21 +++++++++++++++++++++ .../java/com/zeapo/pwdstore/TotpTest.java | 12 ------------ 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 app/src/androidTest/java/com/zeapo/pwdstore/OtpTest.java delete mode 100644 app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/OtpTest.java b/app/src/androidTest/java/com/zeapo/pwdstore/OtpTest.java new file mode 100644 index 00000000..e48f1ab6 --- /dev/null +++ b/app/src/androidTest/java/com/zeapo/pwdstore/OtpTest.java @@ -0,0 +1,12 @@ +package com.zeapo.pwdstore; + +import com.zeapo.pwdstore.utils.Otp; + +import junit.framework.TestCase; + +public class OtpTest extends TestCase { + public void testOtp() { + String code = Otp.calculateCode("JBSWY3DPEHPK3PXP", 0L); + assertEquals("282760", code); + } +} diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java b/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java index e8ddc04c..3df296fe 100644 --- a/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java +++ b/app/src/androidTest/java/com/zeapo/pwdstore/PasswordEntryTest.java @@ -59,4 +59,25 @@ public class PasswordEntryTest extends TestCase { assertTrue(entry.hasTotp()); assertEquals("JBSWY3DPEHPK3PXP", entry.getTotpSecret()); } + + public void testNoHotpUriPresent() { + PasswordEntry entry = new PasswordEntry("secret\nextra\nlogin: username\ncontent"); + assertFalse(entry.hasHotp()); + assertNull(entry.getHotpSecret()); + assertNull(entry.getHotpCounter()); + } + + public void testHotpUriInPassword() { + PasswordEntry entry = new PasswordEntry("otpauth://hotp/test?secret=JBSWY3DPEHPK3PXP&counter=25"); + assertTrue(entry.hasHotp()); + assertEquals("JBSWY3DPEHPK3PXP", entry.getHotpSecret()); + assertEquals(new Long(25 ), entry.getHotpCounter()); + } + + public void testHotpUriInContent() { + PasswordEntry entry = new PasswordEntry("secret\nusername: test\notpauth://hotp/test?secret=JBSWY3DPEHPK3PXP&counter=25"); + assertTrue(entry.hasHotp()); + assertEquals("JBSWY3DPEHPK3PXP", entry.getHotpSecret()); + assertEquals(new Long(25), entry.getHotpCounter()); + } } \ 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 deleted file mode 100644 index 500644d1..00000000 --- a/app/src/androidTest/java/com/zeapo/pwdstore/TotpTest.java +++ /dev/null @@ -1,12 +0,0 @@ -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