BCryptPasswordEncoder validates strength

Fixes gh-3862
This commit is contained in:
Kim Saabye Pedersen
2016-05-04 19:05:24 +02:00
committed by Rob Winch
parent 101190ad8b
commit 9fcfeaf225
3 changed files with 25 additions and 10 deletions

View File

@@ -15,12 +15,12 @@
*/
package org.springframework.security.crypto.bcrypt;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import java.security.SecureRandom;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
*
@@ -57,6 +57,16 @@ public class BCryptPasswordEncoderTests {
assertThat(encoder.matches("password", result)).isTrue();
}
@Test(expected = IllegalArgumentException.class)
public void badLowCustomStrength() {
new BCryptPasswordEncoder(3);
}
@Test(expected = IllegalArgumentException.class)
public void badHighCustomStrength() {
new BCryptPasswordEncoder(32);
}
@Test
public void customRandom() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(8, new SecureRandom());