| 1 |
lars |
1 |
<?php
|
|
|
2 |
require_once 'System.php';
|
|
|
3 |
require_once 'PHPUnit.php';
|
|
|
4 |
require_once 'File/Passwd/Unix.php';
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
$GLOBALS['tmpfile'] = System::mktemp();
|
|
|
8 |
$GLOBALS['users'] = array(
|
|
|
9 |
'bug3348' => array(
|
|
|
10 |
'pass' => 'wxLaOdcajuKoI',
|
|
|
11 |
'uid' => '500',
|
|
|
12 |
'gid' => '501',
|
|
|
13 |
'gecos' => 'having # in gecos',
|
|
|
14 |
'home' => '/nonexistent',
|
|
|
15 |
'shell' => '/bin/false',
|
|
|
16 |
),
|
|
|
17 |
'mike' => array(
|
|
|
18 |
'pass' => 'q4M4mpfilkNnU',
|
|
|
19 |
'uid' => '501',
|
|
|
20 |
'gid' => '502',
|
|
|
21 |
'gecos' => 'User1',
|
|
|
22 |
'home' => '/home/mike',
|
|
|
23 |
'shell' => '/bin/bash'
|
|
|
24 |
),
|
|
|
25 |
'pete' => array(
|
|
|
26 |
'pass' => 'dS80VTLQHZ6VM',
|
|
|
27 |
'uid' => '502',
|
|
|
28 |
'gid' => '503',
|
|
|
29 |
'gecos' => 'User2',
|
|
|
30 |
'home' => '/home/pete',
|
|
|
31 |
'shell' => '/bin/sh'
|
|
|
32 |
),
|
|
|
33 |
'mary' => array(
|
|
|
34 |
'pass' => 'jHSiqFjaEiKPM',
|
|
|
35 |
'uid' => '503',
|
|
|
36 |
'gid' => '504',
|
|
|
37 |
'gecos' => 'User3',
|
|
|
38 |
'home' => '/home/mary',
|
|
|
39 |
'shell' => '/bin/ksh'
|
|
|
40 |
),
|
|
|
41 |
);
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* TestCase for File_Passwd_UnixTest class
|
|
|
45 |
* Generated by PHPEdit.XUnit Plugin
|
|
|
46 |
*
|
|
|
47 |
*/
|
|
|
48 |
class File_Passwd_UnixTest extends PHPUnit_TestCase{
|
|
|
49 |
|
|
|
50 |
var $pwd;
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Constructor
|
|
|
54 |
* @param string $name The name of the test.
|
|
|
55 |
* @access protected
|
|
|
56 |
*/
|
|
|
57 |
function File_Passwd_UnixTest($name){
|
|
|
58 |
$this->PHPUnit_TestCase($name);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
|
|
|
63 |
* @access protected
|
|
|
64 |
*/
|
|
|
65 |
function setUp(){
|
|
|
66 |
$this->pwd = &new File_Passwd_Unix();
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
|
|
|
71 |
* @access protected
|
|
|
72 |
*/
|
|
|
73 |
function tearDown(){
|
|
|
74 |
$this->pwd = null;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Regression test for File_Passwd_Unix.File_Passwd_Unix method
|
|
|
79 |
* @access public
|
|
|
80 |
*/
|
|
|
81 |
function testFile_Passwd_Unix(){
|
|
|
82 |
$this->assertTrue(is_a($this->pwd, 'File_Passwd_Unix'));
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Regression test for File_Passwd_Unix.save method
|
|
|
87 |
* @access public
|
|
|
88 |
*/
|
|
|
89 |
function testsave(){
|
|
|
90 |
$this->pwd->setFile($GLOBALS['tmpfile']);
|
|
|
91 |
$this->pwd->_users = $GLOBALS['users'];
|
|
|
92 |
$e = $this->pwd->save();
|
|
|
93 |
if (PEAR::isError($e)) {
|
|
|
94 |
echo $e->getMessage();
|
|
|
95 |
}
|
|
|
96 |
$this->assertTrue(!PEAR::isError($e));
|
|
|
97 |
$t = file($GLOBALS['tmpfile']);
|
|
|
98 |
$u = file('passwd.unix.txt');
|
|
|
99 |
$this->assertEquals($t,$u);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* Regression test for File_Passwd_Unix.parse method
|
|
|
104 |
* @access public
|
|
|
105 |
*/
|
|
|
106 |
function testparse(){
|
|
|
107 |
$this->pwd->setFile('passwd.unix.txt');
|
|
|
108 |
$this->assertTrue($this->pwd->load());
|
|
|
109 |
$this->assertEquals($this->pwd->_users, $GLOBALS['users']);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Regression test for File_Passwd_Unix.setMode method
|
|
|
114 |
* @access public
|
|
|
115 |
*/
|
|
|
116 |
function testsetMode(){
|
|
|
117 |
$this->assertTrue($this->pwd->setMode('md5'));
|
|
|
118 |
$this->assertTrue($this->pwd->getMode() === 'md5');
|
|
|
119 |
$this->assertTrue(PEAR::isError($this->pwd->setMode('no')));
|
|
|
120 |
$this->assertTrue($this->pwd->setMode('des'));
|
|
|
121 |
$this->assertTrue($this->pwd->getMode() === 'des');
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/**
|
|
|
125 |
* Regression test for File_Passwd_Unix.listModes method
|
|
|
126 |
* @access public
|
|
|
127 |
*/
|
|
|
128 |
function testlistModes(){
|
|
|
129 |
$this->assertTrue($this->pwd->listModes() == array('des' => 'des', 'md5' => 'md5'));
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Regression test for File_Passwd_Unix.getMode method
|
|
|
134 |
* @access public
|
|
|
135 |
*/
|
|
|
136 |
function testgetMode(){
|
|
|
137 |
$this->assertTrue($this->pwd->setMode('md5'));
|
|
|
138 |
$this->assertTrue($this->pwd->getMode() === 'md5');
|
|
|
139 |
$this->assertTrue(PEAR::isError($this->pwd->setMode('no')));
|
|
|
140 |
$this->assertTrue($this->pwd->setMode('des'));
|
|
|
141 |
$this->assertTrue($this->pwd->getMode() === 'des');
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
/**
|
|
|
145 |
* Regression test for File_Passwd_Unix.useMap method
|
|
|
146 |
* @access public
|
|
|
147 |
*/
|
|
|
148 |
function testuseMap(){
|
|
|
149 |
$this->assertTrue($this->pwd->useMap());
|
|
|
150 |
$this->assertTrue($this->pwd->useMap(false));
|
|
|
151 |
$this->assertFalse($this->pwd->useMap());
|
|
|
152 |
$this->assertTrue($this->pwd->useMap(true));
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* Regression test for File_Passwd_Unix.setMap method
|
|
|
157 |
* @access public
|
|
|
158 |
*/
|
|
|
159 |
function testsetMap(){
|
|
|
160 |
$array = array('uid','gid','gecos','home','shell');
|
|
|
161 |
$new = array('none');
|
|
|
162 |
$this->assertTrue($this->pwd->setMap($new));
|
|
|
163 |
$this->assertTrue($this->pwd->getMap() == $new);
|
|
|
164 |
$this->assertTrue($this->pwd->setMap($array));
|
|
|
165 |
$this->assertTrue($this->pwd->getMap() == $array);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/**
|
|
|
169 |
* Regression test for File_Passwd_Unix.getMap method
|
|
|
170 |
* @access public
|
|
|
171 |
*/
|
|
|
172 |
function testgetMap(){
|
|
|
173 |
$array = array('uid','gid','gecos','home','shell');
|
|
|
174 |
$this->assertTrue($array == $this->pwd->getMap());
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
/**
|
|
|
178 |
* Regression test for File_Passwd_Unix.isShadowed method
|
|
|
179 |
* @access public
|
|
|
180 |
*/
|
|
|
181 |
function testisShadowed(){
|
|
|
182 |
$this->assertFalse($this->pwd->isShadowed());
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
/**
|
|
|
186 |
* Regression test for File_Passwd_Unix.addUser method
|
|
|
187 |
* @access public
|
|
|
188 |
*/
|
|
|
189 |
function testaddUser(){
|
|
|
190 |
$this->assertTrue($this->pwd->addUser('add', 'pass'));
|
|
|
191 |
$user = $this->pwd->listUser('add');
|
|
|
192 |
$array = array(
|
|
|
193 |
'pass' => $this->pwd->_genPass('pass', $user['pass']),
|
|
|
194 |
'uid' =>'',
|
|
|
195 |
'gid' =>'',
|
|
|
196 |
'gecos' =>'',
|
|
|
197 |
'home' =>'',
|
|
|
198 |
'shell' =>''
|
|
|
199 |
);
|
|
|
200 |
$this->assertTrue($array == $user);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
/**
|
|
|
204 |
* Regression test for File_Passwd_Unix.modUser method
|
|
|
205 |
* @access public
|
|
|
206 |
*/
|
|
|
207 |
function testmodUser(){
|
|
|
208 |
$this->assertTrue($this->pwd->addUser('mod', 'pass', array('uid' => 555)));
|
|
|
209 |
$this->assertTrue($this->pwd->modUser('mod', array('uid' => 600)));
|
|
|
210 |
$user = $this->pwd->listUser('mod');
|
|
|
211 |
$this->assertTrue(600 == $user['uid']);
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
/**
|
|
|
215 |
* Regression test for File_Passwd_Unix.changePasswd method
|
|
|
216 |
* @access public
|
|
|
217 |
*/
|
|
|
218 |
function testchangePasswd(){
|
|
|
219 |
$this->pwd->addUser('change', 'pass');
|
|
|
220 |
$this->assertTrue($this->pwd->changePasswd('change', 'new'));
|
|
|
221 |
$this->assertTrue($this->pwd->verifyPasswd('change', 'new'));
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
/**
|
|
|
225 |
* Regression test for File_Passwd_Unix.verifyPasswd method
|
|
|
226 |
* @access public
|
|
|
227 |
*/
|
|
|
228 |
function testverifyPasswd(){
|
|
|
229 |
$this->pwd->addUser('verify', 'pass');
|
|
|
230 |
$this->assertTrue($this->pwd->verifyPasswd('verify', 'pass'));
|
|
|
231 |
$this->assertFalse($this->pwd->verifyPasswd('verify', 'other'));
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* Regression test for File_Passwd_Unix._genPass method
|
|
|
236 |
* @access public
|
|
|
237 |
*/
|
|
|
238 |
function test_genPass(){
|
|
|
239 |
$this->pwd->setMode('des');
|
|
|
240 |
$this->assertTrue('12wGUVd8lAOJY' === $this->pwd->_genPass('12','12'));
|
|
|
241 |
$this->pwd->setMode('md5');
|
|
|
242 |
$this->assertTrue('$1$45678901$8Dc8D8vusJXlDQUC7akws/' === $this->pwd->_genPass('12', '$1$456789012'));
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
function teststaticAuth(){
|
|
|
246 |
$this->assertTrue(true === File_Passwd::staticAuth('Unix', 'passwd.unix.txt', 'mike', 123, 'des'));
|
|
|
247 |
$this->assertTrue(false === File_Passwd::staticAuth('Unix', 'passwd.unix.txt', 'mike', 'abc', 'des'));
|
|
|
248 |
$this->assertFalse((File_Passwd::staticAuth('Unix', 'passwd.unix.txt', 'nonexist', 'asd', 'des')));
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
?>
|