SHARE
TWEET

Untitled

a guest Nov 22nd, 2019 155 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PasswordTest {  
  2.   private static final Predicate<String> ALWAYS_TRUE_VALIDATOR = s -> true;
  3.   private static final Predicate<String> DEFAULT_VALIDATOR = PasswordValidators.DEFAULT_PASSWORD_VALIDATOR;
  4.   private static final Function<String, String> PASSWORD_HASH_FUNCTION = DigestUtils::md5Hex;
  5.  
  6.   private static final String USER_ID = "id";
  7.  
  8.   private static final String INSECURE_PASSWORD = "password";
  9.   private static final String INSECURE_PASSWORD_HASHED = PASSWORD_HASH_FUNCTION.apply(INSECURE_PASSWORD);
  10.  
  11.   private static final String SECURE_PASSWORD = "Wa#fe4Whg!j3";
  12.   private static final String SECURE_PASSWORD_HASHED = PASSWORD_HASH_FUNCTION.apply(SECURE_PASSWORD);
  13.  
  14.   @Test
  15.   public void create_AlwaysTrueValidatorSomePassword_NoException() {
  16.     User user = User.create(USER_ID);
  17.     user.setPassword(Password.create(INSECURE_PASSWORD, ALWAYS_TRUE_VALIDATOR, PASSWORD_HASH_FUNCTION));
  18.     assertEquals(INSECURE_PASSWORD_HASHED, user.getPassword().getValue());
  19.   }
  20.  
  21.   @Test
  22.   public void create_DefaultPasswordValidatorValidPassword_NoException() {
  23.     User user = User.create(USER_ID);
  24.     user.setPassword(Password.create(SECURE_PASSWORD, DEFAULT_VALIDATOR, PASSWORD_HASH_FUNCTION));
  25.     assertEquals(SECURE_PASSWORD_HASHED, user.getPassword().getValue());
  26.   }
  27.  
  28.   @Test(expected = IllegalArgumentException.class)
  29.   public void create_DefaultPasswordValidatorInvalidPassword_Exception() {
  30.     User user = User.create(USER_ID);
  31.     user.setPassword(Password.create(INSECURE_PASSWORD, DEFAULT_VALIDATOR, PASSWORD_HASH_FUNCTION));
  32.   }
  33.  
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top