SEC-1666: Use constant time comparison for sensitive data.
Constant time comparison helps to mitigate timing attacks. See the following link for more information * http://rdist.root.org/2010/07/19/exploiting-remote-timing-attacks/ * http://en.wikipedia.org/wiki/Timing_attack for more information.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package org.springframework.security.authentication.encoding;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
/**
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public class PasswordEncoderUtilsTests {
|
||||
|
||||
@Test
|
||||
public void differentLength() {
|
||||
assertFalse(PasswordEncoderUtils.equals("abc", "a"));
|
||||
assertFalse(PasswordEncoderUtils.equals("a", "abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsNull() {
|
||||
assertFalse(PasswordEncoderUtils.equals(null, "a"));
|
||||
assertFalse(PasswordEncoderUtils.equals("a", null));
|
||||
assertTrue(PasswordEncoderUtils.equals(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsCaseSensitive() {
|
||||
assertFalse(PasswordEncoderUtils.equals("aBc", "abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsSuccess() {
|
||||
assertTrue(PasswordEncoderUtils.equals("abcdef", "abcdef"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user