SimpleHashService extends HashService { @Override public String hash(String plaintext) { return plaintext; } SimpleHashService(boolean serverSideHashEnabled, boolean allowCommonMistakes); @Override String hash(String plaintext);  }
@Test void testHashSame() { String plaintext = "password"; String secondPlaintext = "password"; String result = hashService.hash(plaintext); String secondResult = hashService.hash(secondPlaintext); assertEquals(plaintext, result); assertEquals(secondPlaintext, secondResult); assertEquals(result, secondResult); }
@Test void testHashDifferent() { String plaintext = "password"; String secondPlaintext = "secondPassword"; String result = hashService.hash(plaintext); String secondResult = hashService.hash(secondPlaintext); assertEquals(plaintext, result); assertEquals(secondPlaintext, secondResult); assertNotEquals(result, secondResult); }
@Test void testHashWithMistakesDisabled() { String plaintext = "Password"; String hashed = hashService.hash(plaintext); assertTrue(hashService.isMatch(plaintext, hashed)); String capsLock = "pASSWORD"; assertFalse(hashService.isMatch(capsLock, hashed)); String extraFirstCharacter = "*Password"; assertFalse(hashService.isMatch(extraFirstCharacter, hashed)); String extraLastCharacter = "Password-"; assertFalse(hashService.isMatch(extraLastCharacter, hashed)); String firstCharacterCaseSwap = "password"; assertFalse(hashService.isMatch(firstCharacterCaseSwap, hashed)); }
@Test void testHashWithMistakesEnabled() { HashService hashService = new SimpleHashService(true, true); String plaintext = "Password"; String hashed = hashService.hash(plaintext); assertTrue(hashService.isMatch(plaintext, hashed)); String capsLock = "pASSWORD"; assertTrue(hashService.isMatch(capsLock, hashed)); String extraFirstCharacter = "*Password"; assertTrue(hashService.isMatch(extraFirstCharacter, hashed)); String extraLastCharacter = "Password-"; assertTrue(hashService.isMatch(extraLastCharacter, hashed)); String firstCharacterCaseSwap = "password"; assertTrue(hashService.isMatch(firstCharacterCaseSwap, hashed)); }
@Test void testHashWithMistakesEnabledIncorrect() { HashService hashService = new SimpleHashService(true, true); String plaintext = "Password"; String hashed = hashService.hash(plaintext); assertTrue(hashService.isMatch(plaintext, hashed)); String incorrectCapsLock = "PASSWORD"; assertFalse(hashService.isMatch(incorrectCapsLock, hashed)); String incorrectExtraFirstCharacter = "*2Password"; assertFalse(hashService.isMatch(incorrectExtraFirstCharacter, hashed)); String incorrectExtraLastCharacter = "Password-x"; assertFalse(hashService.isMatch(incorrectExtraLastCharacter, hashed)); String incorrectFirstCharacterCaseSwap = "passworD"; assertFalse(hashService.isMatch(incorrectFirstCharacterCaseSwap, hashed)); }