1
1
<?php
2
+
2
3
/**
3
4
* @group plugin_passpolicy
4
5
* @group plugins
5
6
*/
6
- class helper_plugin_passpolicy_test extends DokuWikiTest {
7
+ class helper_plugin_passpolicy_test extends DokuWikiTest
8
+ {
7
9
8
10
protected $ pluginsEnabled = array ('passpolicy ' );
9
11
@@ -22,16 +24,27 @@ class helper_plugin_passpolicy_test extends DokuWikiTest {
22
24
* @param bool $noleak
23
25
* @return helper_plugin_passpolicy
24
26
*/
25
- public function newPolicy ($ minl , $ minp , $ lower , $ upper , $ num , $ special , $ ucheck , $ pron =true , $ nocom =true , $ noleak =false ) {
27
+ public function newPolicy (
28
+ $ minl ,
29
+ $ minp ,
30
+ $ lower ,
31
+ $ upper ,
32
+ $ num ,
33
+ $ special ,
34
+ $ ucheck ,
35
+ $ pron = true ,
36
+ $ nocom = true ,
37
+ $ noleak = false
38
+ ) {
26
39
/** @var helper_plugin_passpolicy $policy */
27
- $ policy = plugin_load ('helper ' , 'passpolicy ' );
28
- $ policy ->min_pools = $ minp ;
29
- $ policy ->min_length = $ minl ;
30
- $ policy ->usepools = array (
31
- 'lower ' => $ lower ,
32
- 'upper ' => $ upper ,
40
+ $ policy = plugin_load ('helper ' , 'passpolicy ' );
41
+ $ policy ->min_pools = $ minp ;
42
+ $ policy ->min_length = $ minl ;
43
+ $ policy ->usepools = array (
44
+ 'lower ' => $ lower ,
45
+ 'upper ' => $ upper ,
33
46
'numeric ' => $ num ,
34
- 'special ' => $ special
47
+ 'special ' => $ special,
35
48
);
36
49
$ policy ->usernamecheck = $ ucheck ;
37
50
$ policy ->pronouncable = $ pron ;
@@ -41,30 +54,33 @@ public function newPolicy($minl, $minp, $lower, $upper, $num, $special, $ucheck,
41
54
return $ policy ;
42
55
}
43
56
44
- public function test_policies () {
57
+ public function test_policies ()
58
+ {
45
59
$ policy = $ this ->newPolicy (6 , 1 , true , true , true , true , 0 );
46
- $ this ->assertTrue ($ policy ->checkPolicy ('tested ' ,'tested ' ), '1 pool, no user check ' .$ policy ->error );
47
- $ this ->assertFalse ($ policy ->checkPolicy ('test ' ,'tested ' ), '1 pool, no user check, but too short ' .$ policy ->error );
60
+ $ this ->assertTrue ($ policy ->checkPolicy ('tested ' , 'tested ' ), '1 pool, no user check ' . $ policy ->error );
61
+ $ this ->assertFalse ($ policy ->checkPolicy ('test ' , 'tested ' ),
62
+ '1 pool, no user check, but too short ' . $ policy ->error );
48
63
$ this ->assertEquals (helper_plugin_passpolicy::LENGTH_VIOLATION , $ policy ->error );
49
- $ this ->assertTrue ($ policy ->checkPolicy ('tested99! ' ,'tested ' ), '1 pool, no user check ' . $ policy ->error );
64
+ $ this ->assertTrue ($ policy ->checkPolicy ('tested99! ' , 'tested ' ), '1 pool, no user check ' . $ policy ->error );
50
65
51
66
$ policy = $ this ->newPolicy (6 , 3 , true , true , true , true , 0 );
52
- $ this ->assertFalse ($ policy ->checkPolicy ('tested ' ,'tested ' ), '3 pools, no user check ' . $ policy ->error );
67
+ $ this ->assertFalse ($ policy ->checkPolicy ('tested ' , 'tested ' ), '3 pools, no user check ' . $ policy ->error );
53
68
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
54
- $ this ->assertTrue ($ policy ->checkPolicy ('tested99! ' ,'tested ' ), '3 pools, no user check ' . $ policy ->error );
69
+ $ this ->assertTrue ($ policy ->checkPolicy ('tested99! ' , 'tested ' ), '3 pools, no user check ' . $ policy ->error );
55
70
56
71
$ policy = $ this ->newPolicy (6 , 1 , true , true , true , true , 2 );
57
- $ this ->assertFalse ($ policy ->checkPolicy ('tested ' ,'tested ' ), '1 pool, user check ' . $ policy ->error );
72
+ $ this ->assertFalse ($ policy ->checkPolicy ('tested ' , 'tested ' ), '1 pool, user check ' . $ policy ->error );
58
73
$ this ->assertEquals (helper_plugin_passpolicy::USERNAME_VIOLATION , $ policy ->error );
59
- $ this ->assertFalse ($ policy ->checkPolicy ('tested99! ' ,'tested ' ), '1 pool, user check ' . $ policy ->error );
74
+ $ this ->assertFalse ($ policy ->checkPolicy ('tested99! ' , 'tested ' ), '1 pool, user check ' . $ policy ->error );
60
75
$ this ->assertEquals (helper_plugin_passpolicy::USERNAME_VIOLATION , $ policy ->error );
61
- $ this ->assertFalse ($ policy ->checkPolicy ('tested ' ,'untested ' ), '1 pool, user check ' . $ policy ->error );
76
+ $ this ->assertFalse ($ policy ->checkPolicy ('tested ' , 'untested ' ), '1 pool, user check ' . $ policy ->error );
62
77
$ this ->assertEquals (helper_plugin_passpolicy::USERNAME_VIOLATION , $ policy ->error );
63
- $ this ->assertFalse ($ policy ->checkPolicy ('tested99! ' ,'comptessa ' ), '1 pool1, user check ' . $ policy ->error );
78
+ $ this ->assertFalse ($ policy ->checkPolicy ('tested99! ' , 'comptessa ' ), '1 pool1, user check ' . $ policy ->error );
64
79
$ this ->assertEquals (helper_plugin_passpolicy::USERNAME_VIOLATION , $ policy ->error );
65
80
}
66
81
67
- public function test_nocommon (){
82
+ public function test_nocommon ()
83
+ {
68
84
$ policy = $ this ->newPolicy (6 , 1 , true , true , true , true , 0 , true , true );
69
85
$ this ->assertTrue ($ policy ->checkPolicy ('bazzel ' , 'nope ' ));
70
86
$ this ->assertFalse ($ policy ->checkPolicy ('eyphed ' , 'nope ' ));
@@ -74,7 +90,8 @@ public function test_nocommon(){
74
90
$ this ->assertTrue ($ policy ->checkPolicy ('password ' , 'nope ' ));
75
91
}
76
92
77
- public function test_noleak (){
93
+ public function test_noleak ()
94
+ {
78
95
$ policy = $ this ->newPolicy (6 , 1 , true , true , true , true , 0 , false , true , true );
79
96
$ this ->assertTrue ($ policy ->checkPolicy ('sadf asfd s as asf a afafaa fadfsa fas ' , 'nope ' ));
80
97
$ this ->assertFalse ($ policy ->checkPolicy ('qwertzuiop ' , 'nope ' ));
@@ -84,45 +101,47 @@ public function test_noleak(){
84
101
$ this ->assertTrue ($ policy ->checkPolicy ('qwertzuiop ' , 'nope ' ));
85
102
}
86
103
87
- public function test_minpools (){
104
+ public function test_minpools ()
105
+ {
88
106
$ policy = $ this ->newPolicy (3 , 0 , true , true , true , true , 0 );
89
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' ,'tester ' ), '0 required, 4 given ' . $ policy ->error );
90
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' ,'tester ' ), '0 required, 3 given ' . $ policy ->error );
91
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER ' ,'tester ' ), '0 required, 2 given ' . $ policy ->error );
92
- $ this ->assertTrue ($ policy ->checkPolicy ('lower ' ,'tester ' ), '0 required, 1 given ' . $ policy ->error );
107
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' , 'tester ' ), '0 required, 4 given ' . $ policy ->error );
108
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' , 'tester ' ), '0 required, 3 given ' . $ policy ->error );
109
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER ' , 'tester ' ), '0 required, 2 given ' . $ policy ->error );
110
+ $ this ->assertTrue ($ policy ->checkPolicy ('lower ' , 'tester ' ), '0 required, 1 given ' . $ policy ->error );
93
111
94
112
$ policy = $ this ->newPolicy (3 , 1 , true , true , true , true , 0 );
95
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' ,'tester ' ), '1 required, 4 given ' . $ policy ->error );
96
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' ,'tester ' ), '1 required, 3 given ' . $ policy ->error );
97
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER ' ,'tester ' ), '1 required, 2 given ' . $ policy ->error );
98
- $ this ->assertTrue ($ policy ->checkPolicy ('lower ' ,'tester ' ), '1 required, 1 given ' . $ policy ->error );
113
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' , 'tester ' ), '1 required, 4 given ' . $ policy ->error );
114
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' , 'tester ' ), '1 required, 3 given ' . $ policy ->error );
115
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER ' , 'tester ' ), '1 required, 2 given ' . $ policy ->error );
116
+ $ this ->assertTrue ($ policy ->checkPolicy ('lower ' , 'tester ' ), '1 required, 1 given ' . $ policy ->error );
99
117
100
118
$ policy = $ this ->newPolicy (3 , 2 , true , true , true , true , 0 );
101
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' ,'tester ' ), '2 required, 4 given ' . $ policy ->error );
102
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' ,'tester ' ), '2 required, 3 given ' . $ policy ->error );
103
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER ' ,'tester ' ), '2 required, 2 given ' . $ policy ->error );
104
- $ this ->assertFalse ($ policy ->checkPolicy ('lower ' ,'tester ' ), '2 required, 1 given ' . $ policy ->error );
119
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' , 'tester ' ), '2 required, 4 given ' . $ policy ->error );
120
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' , 'tester ' ), '2 required, 3 given ' . $ policy ->error );
121
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER ' , 'tester ' ), '2 required, 2 given ' . $ policy ->error );
122
+ $ this ->assertFalse ($ policy ->checkPolicy ('lower ' , 'tester ' ), '2 required, 1 given ' . $ policy ->error );
105
123
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
106
124
107
125
$ policy = $ this ->newPolicy (3 , 3 , true , true , true , true , 0 );
108
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' ,'tester ' ), '3 required, 4 given ' . $ policy ->error );
109
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' ,'tester ' ), '3 required, 3 given ' . $ policy ->error );
110
- $ this ->assertFalse ($ policy ->checkPolicy ('lowerUPPER ' ,'tester ' ), '3 required, 2 given ' . $ policy ->error );
126
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' , 'tester ' ), '3 required, 4 given ' . $ policy ->error );
127
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123 ' , 'tester ' ), '3 required, 3 given ' . $ policy ->error );
128
+ $ this ->assertFalse ($ policy ->checkPolicy ('lowerUPPER ' , 'tester ' ), '3 required, 2 given ' . $ policy ->error );
111
129
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
112
- $ this ->assertFalse ($ policy ->checkPolicy ('lower ' ,'tester ' ), '3 required, 1 given ' . $ policy ->error );
130
+ $ this ->assertFalse ($ policy ->checkPolicy ('lower ' , 'tester ' ), '3 required, 1 given ' . $ policy ->error );
113
131
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
114
132
115
133
$ policy = $ this ->newPolicy (3 , 4 , true , true , true , true , 0 );
116
- $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' ,'tester ' ), '4 required, 4 given ' . $ policy ->error );
117
- $ this ->assertFalse ($ policy ->checkPolicy ('lowerUPPER123 ' ,'tester ' ), '4 required, 3 given ' . $ policy ->error );
134
+ $ this ->assertTrue ($ policy ->checkPolicy ('lowerUPPER123!" ' , 'tester ' ), '4 required, 4 given ' . $ policy ->error );
135
+ $ this ->assertFalse ($ policy ->checkPolicy ('lowerUPPER123 ' , 'tester ' ), '4 required, 3 given ' . $ policy ->error );
118
136
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
119
- $ this ->assertFalse ($ policy ->checkPolicy ('lowerUPPER ' ,'tester ' ), '4 required, 2 given ' . $ policy ->error );
137
+ $ this ->assertFalse ($ policy ->checkPolicy ('lowerUPPER ' , 'tester ' ), '4 required, 2 given ' . $ policy ->error );
120
138
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
121
- $ this ->assertFalse ($ policy ->checkPolicy ('lower ' ,'tester ' ), '4 required, 1 given ' . $ policy ->error );
139
+ $ this ->assertFalse ($ policy ->checkPolicy ('lower ' , 'tester ' ), '4 required, 1 given ' . $ policy ->error );
122
140
$ this ->assertEquals (helper_plugin_passpolicy::POOL_VIOLATION , $ policy ->error );
123
141
}
124
142
125
- public function test_selfcheck () {
143
+ public function test_selfcheck ()
144
+ {
126
145
$ policy = $ this ->newPolicy (6 , 4 , true , true , true , true , 0 , true );
127
146
$ pw1 = $ policy ->generatePassword ('test ' );
128
147
$ pw2 = $ policy ->generatePassword ('test ' );
0 commit comments