public void testGetNextCode() throws Exception { addSomeRecords(); // HOTP, counter at 0, check getNextcode response. assertEquals("683298", otpProvider.getNextCode("*****@*****.**")); // counter updated to 1, check response has changed. assertEquals("891123", otpProvider.getNextCode("*****@*****.**")); // TOTP: HOTP with current time (seconds / 30) as the counter withTotpClockCurrentTimeSeconds(OtpProvider.DEFAULT_INTERVAL * 1); assertEquals("683298", otpProvider.getNextCode("*****@*****.**")); withTotpClockCurrentTimeSeconds(OtpProvider.DEFAULT_INTERVAL * 2); assertEquals("891123", otpProvider.getNextCode("*****@*****.**")); // Different TOTP account/secret withTotpClockCurrentTimeSeconds(OtpProvider.DEFAULT_INTERVAL * 1234567890L); assertEquals("817746", otpProvider.getNextCode("*****@*****.**")); }
public void testRespondToChallenge() throws Exception { addSomeRecords(); assertEquals("308683298", otpProvider.respondToChallenge("*****@*****.**", "")); assertEquals( "561472261", otpProvider.respondToChallenge("*****@*****.**", "this is my challenge")); // TOTP: HOTP with current time (seconds / 30) as the counter withTotpClockCurrentTimeSeconds(OtpProvider.DEFAULT_INTERVAL * 1); assertEquals("308683298", otpProvider.respondToChallenge("*****@*****.**", "")); withTotpClockCurrentTimeSeconds(OtpProvider.DEFAULT_INTERVAL * 2); assertEquals( "561472261", otpProvider.respondToChallenge("*****@*****.**", "this is my challenge")); // Different TOTP account/secret withTotpClockCurrentTimeSeconds(OtpProvider.DEFAULT_INTERVAL * 9876543210L); assertEquals( "834647199", otpProvider.respondToChallenge("*****@*****.**", "this is my challenge")); }
public void testEnumerateAccounts() throws Exception { addSomeRecords(); otpProvider.enumerateAccounts(result); MoreAsserts.assertContentsInAnyOrder( result, "*****@*****.**", "*****@*****.**", "*****@*****.**"); }
public void testEnumerateAccountsNoRecords() throws Exception { assertEquals(0, otpProvider.enumerateAccounts(result)); MoreAsserts.assertEmpty(result); }
public void testRespondToChallengeWithNullChallenge() throws Exception { addSomeRecords(); assertEquals("683298", otpProvider.respondToChallenge("*****@*****.**", null)); }
public void testGetNextCodeWithEmptyAccountName() throws Exception { accountDb.update("", SECRET, "", OtpType.HOTP, null); // HOTP, counter at 0, check getNextcode response. assertEquals("683298", otpProvider.getNextCode("")); }