1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.changepw.service;
21
22
23 import javax.security.auth.kerberos.KerberosPrincipal;
24
25 import junit.framework.TestCase;
26
27
28
29
30
31
32
33
34 public class CheckPasswordPolicyTest extends TestCase
35 {
36 private int passwordLength = 6;
37 private int categoryCount = 3;
38 private int tokenSize = 3;
39
40 private CheckPasswordPolicy policy = new CheckPasswordPolicy();
41
42
43
44
45
46 public void testGoodPassword()
47 {
48 String username = "Enrique Rodriguez";
49 String password = "d1r3ct0rY";
50 assertTrue( policy.isValidPasswordLength( password, passwordLength ) );
51 assertTrue( policy.isValidCategoryCount( password, categoryCount ) );
52 assertTrue( policy.isValidUsernameSubstring( username, password, tokenSize ) );
53 assertTrue( policy.isValid( username, password, passwordLength, categoryCount, tokenSize ) );
54 }
55
56
57
58
59
60 public void testBadPassword()
61 {
62 String username = "Erin Randall";
63 String password = "erin1";
64 assertFalse( policy.isValidPasswordLength( password, passwordLength ) );
65 assertFalse( policy.isValidCategoryCount( password, categoryCount ) );
66 assertFalse( policy.isValidUsernameSubstring( username, password, tokenSize ) );
67 assertFalse( policy.isValid( username, password, passwordLength, categoryCount, tokenSize ) );
68 }
69
70
71
72
73
74 public void testPrincipalAsUsername()
75 {
76 String username = new KerberosPrincipal( "erodriguez@EXAMPLE.COM" ).getName();
77 String password1 = "d1r3ct0rY";
78 String password2 = "ERodriguez@d1r3ct0rY";
79 String password3 = "Example@d1r3ct0rY";
80
81 assertTrue( policy.isValidUsernameSubstring( username, password1, tokenSize ) );
82
83 assertFalse( policy.isValidUsernameSubstring( username, password2, tokenSize ) );
84 assertFalse( policy.isValidUsernameSubstring( username, password3, tokenSize ) );
85 }
86 }