1
|
/**
|
2
|
* Copyright (C) 2022 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.validation;
|
10
|
|
11
|
import static org.junit.Assert.assertTrue;
|
12
|
|
13
|
import java.util.Set;
|
14
|
|
15
|
import javax.validation.ConstraintViolation;
|
16
|
|
17
|
import org.apache.commons.lang3.StringUtils;
|
18
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.permission.User;
|
23
|
import eu.etaxonomy.cdm.validation.constraint.ValidPasswordValidator;
|
24
|
|
25
|
/**
|
26
|
* See https://dev.e-taxonomy.eu/redmine/issues/9862
|
27
|
*
|
28
|
* @author a.mueller
|
29
|
* @date 21.01.2022
|
30
|
*/
|
31
|
public class ValidPasswordTest extends ValidationTestBase {
|
32
|
|
33
|
@SuppressWarnings("unused")
|
34
|
private static final Logger logger = LogManager.getLogger(ValidPasswordTest.class);
|
35
|
|
36
|
private User user;
|
37
|
|
38
|
private static final String valid = "Aa345678";
|
39
|
|
40
|
@Before
|
41
|
public void setUp() {
|
42
|
|
43
|
}
|
44
|
|
45
|
/****************** TESTS *****************************/
|
46
|
|
47
|
@Test
|
48
|
public final void testValidPassword() {
|
49
|
|
50
|
user = User.NewInstance("testuser", valid);
|
51
|
|
52
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user, Level2.class);
|
53
|
assertTrue("There should not be a constraint violation as the 'valid' password fullfils all requirements",constraintViolations.isEmpty());
|
54
|
|
55
|
user.setPassword(StringUtils.leftPad(valid, 256, 'a'));
|
56
|
assertTrue("There should not be a constraint violation as up to 256 characters are allowed",constraintViolations.isEmpty());
|
57
|
|
58
|
}
|
59
|
|
60
|
@Test
|
61
|
public final void testNotValidPassword() {
|
62
|
user = User.NewInstance("testuser", null);
|
63
|
|
64
|
validateHasConstraint(user, ValidPasswordValidator.class, Level2.class);
|
65
|
|
66
|
user.setPassword("");
|
67
|
validateHasConstraint(user, ValidPasswordValidator.class, Level2.class);
|
68
|
|
69
|
user.setPassword("A");
|
70
|
validateHasConstraint(user, ValidPasswordValidator.class, Level2.class);
|
71
|
user.setPassword(valid.substring(0, 7));
|
72
|
validateHasConstraint(user, ValidPasswordValidator.class, Level2.class);
|
73
|
|
74
|
user.setPassword(StringUtils.leftPad(valid, 257, 'a'));
|
75
|
validateHasConstraint(user, ValidPasswordValidator.class, Level2.class);
|
76
|
|
77
|
|
78
|
}
|
79
|
|
80
|
}
|