public void testReallyLongPasswordWorksRight() { char[] reallyLongPassword = new char[1024]; for (int i = 0; i < reallyLongPassword.length; i++) { // We'll make a password filled with junk. reallyLongPassword[i] = (char) i; } PasswordDigest pwd = new PasswordDigest(reallyLongPassword); assertTrue(pwd.verify(reallyLongPassword)); // Make a new password that misses the last character. It shouldn't work. char[] shorterPassword = Arrays.copyOf(reallyLongPassword, 1023); assertFalse(pwd.verify(shorterPassword)); }
public void testReallyLongPasswordWorksRight() { char[] reallyLongPassword = new char[1024]; for (int i = 0; i < reallyLongPassword.length; i++) { // We'll make a password filled with junk. reallyLongPassword[i] = (char) i; } PasswordDigest pwd = new PasswordDigest(reallyLongPassword); assertTrue(pwd.verify(reallyLongPassword)); // Make a new password that misses the last character. It shouldn't work. char[] shorterPassword = Arrays.copyOf(reallyLongPassword, 1023); assertFalse(pwd.verify(shorterPassword)); }
public void testEditingExposedBytesDoesntChangeInternalState() { PasswordDigest pwd1 = new PasswordDigest("webernets".toCharArray()); byte[] digest = pwd1.getDigest(); byte[] salt = pwd1.getSalt(); PasswordDigest pwd2 = PasswordDigest.from(salt, digest); // We'll mess with the digest and salt we got back and make sure both // passwords still verify normally. digest[digest.length / 2]++; salt[salt.length / 2]--; assertTrue(pwd1.verify("webernets".toCharArray())); assertTrue(pwd2.verify("webernets".toCharArray())); }
} else if (!account.asHuman().getPasswordDigest().verify(password)) {
public void testEditingExposedBytesDoesntChangeInternalState() { PasswordDigest pwd1 = new PasswordDigest("webernets".toCharArray()); byte[] digest = pwd1.getDigest(); byte[] salt = pwd1.getSalt(); PasswordDigest pwd2 = PasswordDigest.from(salt, digest); // We'll mess with the digest and salt we got back and make sure both // passwords still verify normally. digest[digest.length / 2]++; salt[salt.length / 2]--; assertTrue(pwd1.verify("webernets".toCharArray())); assertTrue(pwd2.verify("webernets".toCharArray())); }
public void testSerializeDeserialize() { PasswordDigest pwd = new PasswordDigest("tubes".toCharArray()); byte[] digest = pwd.getDigest(); byte[] salt = pwd.getSalt(); PasswordDigest roundtripped = PasswordDigest.from(salt, digest); assertTrue(pwd.verify("tubes".toCharArray())); assertFalse(pwd.verify("wrongpwd".toCharArray())); }
public void testSerializeDeserialize() { PasswordDigest pwd = new PasswordDigest("tubes".toCharArray()); byte[] digest = pwd.getDigest(); byte[] salt = pwd.getSalt(); PasswordDigest roundtripped = PasswordDigest.from(salt, digest); assertTrue(pwd.verify("tubes".toCharArray())); assertFalse(pwd.verify("wrongpwd".toCharArray())); }
public void testRegisterNewUserEnabled() throws Exception { attemptToRegister(req, resp, "foo@example.com", "internet", false); verify(resp).setStatus(HttpServletResponse.SC_OK); ParticipantId participantId = ParticipantId.ofUnsafe("foo@example.com"); AccountData account = store.getAccount(participantId); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("internet".toCharArray())); verify(welcomeBot).greet(eq(participantId)); }
public void testRegisterNewUserEnabled() throws Exception { attemptToRegister(req, resp, "foo@example.com", "internet", false); verify(resp).setStatus(HttpServletResponse.SC_OK); ParticipantId participantId = ParticipantId.ofUnsafe("foo@example.com"); AccountData account = store.getAccount(participantId); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("internet".toCharArray())); verify(welcomeBot).greet(eq(participantId)); }
public void testNullPasswordWorks() throws Exception { attemptToRegister(req, resp, "zd@example.com", null, false); verify(resp).setStatus(HttpServletResponse.SC_OK); AccountData account = store.getAccount(ParticipantId.ofUnsafe("zd@example.com")); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("".toCharArray())); }
public void testNullPasswordWorks() throws Exception { attemptToRegister(req, resp, "zd@example.com", null, false); verify(resp).setStatus(HttpServletResponse.SC_OK); AccountData account = store.getAccount(ParticipantId.ofUnsafe("zd@example.com")); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("".toCharArray())); }
public void testPasswordDigestVerifies() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("captainhammer@example.com"), new PasswordDigest("wonderflownium".toCharArray())); assertNotNull(account.getPasswordDigest()); assertTrue(account.getPasswordDigest().verify("wonderflownium".toCharArray())); }
public void testPasswordDigestVerifies() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("captainhammer@example.com"), new PasswordDigest("wonderflownium".toCharArray())); assertNotNull(account.getPasswordDigest()); assertTrue(account.getPasswordDigest().verify("wonderflownium".toCharArray())); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }