1 package org.cateproject.controller.user;
2
3 import org.cateproject.controller.user.PasswordMessage;
4 import org.cateproject.controller.user.PasswordValidatorImpl;
5 import org.junit.Assert;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.springframework.core.io.ClassPathResource;
9 import org.unitils.UnitilsJUnit4;
10
11 public class PasswordValidatorTest extends UnitilsJUnit4 {
12
13 private PasswordValidatorImpl passwordValidator;
14
15 @Before
16 public void setUp() throws Exception {
17 passwordValidator = new PasswordValidatorImpl();
18 passwordValidator.setDictionaryFolder(new ClassPathResource("/org/cateproject/controller/cracklib"));
19 passwordValidator.setDictionaryName("dictionary.words");
20 passwordValidator.setMinimumDifference(6);
21 passwordValidator.setMinimumLength(8);
22 passwordValidator.init();
23 }
24
25 @Test
26 public void testPasswordValidatorInit() {
27 Assert.assertNotNull(passwordValidator);
28 }
29
30 @Test
31 public void testIsWeak() throws Exception {
32 Assert.assertFalse(passwordValidator.checkPassword("ben").equals(PasswordMessage.PASSWORD_OK));
33 Assert.assertEquals(passwordValidator.checkPassword("7EZeCraS"),PasswordMessage.PASSWORD_OK);
34 }
35
36 }