| 1 |
lars |
1 |
<?php
|
|
|
2 |
require_once 'System.php';
|
|
|
3 |
require_once 'PHPUnit.php';
|
|
|
4 |
require_once 'File/Passwd/Smb.php';
|
|
|
5 |
|
|
|
6 |
function hash_nt($txt)
|
|
|
7 |
{
|
|
|
8 |
return strToUpper(bin2hex($GLOBALS['msc']->ntPasswordHash($txt)));
|
|
|
9 |
}
|
|
|
10 |
function hash_lm($txt)
|
|
|
11 |
{
|
|
|
12 |
return strToUpper(bin2hex($GLOBALS['msc']->lmPasswordHash($txt)));
|
|
|
13 |
}
|
|
|
14 |
|
|
|
15 |
$GLOBALS['tmpfile'] = System::mktemp();
|
|
|
16 |
$GLOBALS['msc'] = &new Crypt_CHAP_MSv1();
|
|
|
17 |
$GLOBALS['user'] = array(
|
|
|
18 |
'mike' => array(
|
|
|
19 |
'userid' => 501,
|
|
|
20 |
'nthash' => hash_nt('123'),
|
|
|
21 |
'lmhash' => hash_lm('123'),
|
|
|
22 |
'flags' => '[U ]',
|
|
|
23 |
'lct' => 'LCT-3FA7AE9B',
|
|
|
24 |
'comment'=> 'Michael Wallner'
|
|
|
25 |
)
|
|
|
26 |
);
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* TestCase for File_Passwd_SmbTest class
|
|
|
30 |
* Generated by PHPEdit.XUnit Plugin
|
|
|
31 |
*
|
|
|
32 |
*/
|
|
|
33 |
class File_Passwd_SmbTest extends PHPUnit_TestCase{
|
|
|
34 |
|
|
|
35 |
var $pw;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Constructor
|
|
|
39 |
* @param string $name The name of the test.
|
|
|
40 |
* @access protected
|
|
|
41 |
*/
|
|
|
42 |
function File_Passwd_SmbTest($name){
|
|
|
43 |
$this->PHPUnit_TestCase($name);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
|
|
|
48 |
* @access protected
|
|
|
49 |
*/
|
|
|
50 |
function setUp(){
|
|
|
51 |
$this->pw = &new File_Passwd_Smb();
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
|
|
|
56 |
* @access protected
|
|
|
57 |
*/
|
|
|
58 |
function tearDown(){
|
|
|
59 |
$this->pw = null;
|
|
|
60 |
unset($this->pw);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Regression test for File_Passwd_Smb.File_Passwd_Smb method
|
|
|
65 |
* @access public
|
|
|
66 |
*/
|
|
|
67 |
function testFile_Passwd_Smb(){
|
|
|
68 |
$this->assertTrue(is_a($this->pw, 'File_Passwd_Smb'));
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Regression test for File_Passwd_Smb.staticAuth method
|
|
|
73 |
* @access public
|
|
|
74 |
*/
|
|
|
75 |
function teststaticAuth(){
|
|
|
76 |
$rs = File_Passwd_Smb::staticAuth('passwd.smb.txt', 'mike', 123);
|
|
|
77 |
$this->assertTrue($rs);
|
|
|
78 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Regression test for File_Passwd_Smb.parse method
|
|
|
83 |
* @access public
|
|
|
84 |
*/
|
|
|
85 |
function testparse(){
|
|
|
86 |
$this->pw->setFile('passwd.smb.txt');
|
|
|
87 |
$rs = $this->pw->load();
|
|
|
88 |
$this->assertTrue($rs);
|
|
|
89 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
90 |
$u = asort($GLOBALS['user']);
|
|
|
91 |
$s = asort($this->pw->listUser());
|
|
|
92 |
$this->assertEquals($u, $s);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Regression test for File_Passwd_Smb.addUser method
|
|
|
97 |
* @access public
|
|
|
98 |
*/
|
|
|
99 |
function testaddUser(){
|
|
|
100 |
$rs = $this->pw->addUser('mike2', 123, array('userid' => 502));
|
|
|
101 |
$this->assertTrue($rs);
|
|
|
102 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Regression test for File_Passwd_Smb.modUser method
|
|
|
107 |
* @access public
|
|
|
108 |
*/
|
|
|
109 |
function testmodUser(){
|
|
|
110 |
$this->pw->addUser('mike3', 123, array('userid' => 503));
|
|
|
111 |
$rs = $this->pw->modUser('mike3', array('userid' => 599));
|
|
|
112 |
$this->assertTrue($rs);
|
|
|
113 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* Regression test for File_Passwd_Smb.changePasswd method
|
|
|
118 |
* @access public
|
|
|
119 |
*/
|
|
|
120 |
function testchangePasswd(){
|
|
|
121 |
$abc = 'E0FBA38268D0EC66EF1CB452D5885E53';
|
|
|
122 |
$abc = hash_nt('abc');
|
|
|
123 |
$this->pw->addUser('mike4', 123, array('userid' => 504));
|
|
|
124 |
$rs = $this->pw->changePasswd('mike4', 'abc');
|
|
|
125 |
$this->assertTrue($rs);
|
|
|
126 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
127 |
$this->assertEquals($abc, $this->pw->_users['mike4']['nthash']);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* Regression test for File_Passwd_Smb.verifyEncryptedPasswd method
|
|
|
132 |
* @access public
|
|
|
133 |
*/
|
|
|
134 |
function testverifyEncryptedPasswd(){
|
|
|
135 |
$this->pw->addUser('mike5', 'abc', array('userid' => 505));
|
|
|
136 |
$pass = hash_nt('abc');
|
|
|
137 |
$rs = $this->pw->verifyEncryptedPasswd('mike5', $pass);
|
|
|
138 |
$this->assertTrue($rs);
|
|
|
139 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
/**
|
|
|
143 |
* Regression test for File_Passwd_Smb.verifyPasswd method
|
|
|
144 |
* @access public
|
|
|
145 |
*/
|
|
|
146 |
function testverifyPasswd(){
|
|
|
147 |
$this->pw->addUser('mike6', 'abc', array('userid' => 506));
|
|
|
148 |
$rs = $this->pw->verifyPasswd('mike6', 'abc');
|
|
|
149 |
$this->assertTrue($rs);
|
|
|
150 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
* Regression test for File_Passwd_Smb.save method
|
|
|
155 |
* @access public
|
|
|
156 |
*/
|
|
|
157 |
function testsave(){
|
|
|
158 |
$this->pw->setFile($GLOBALS['tmpfile']);
|
|
|
159 |
$this->pw->addUser('mike', 123, array('userid' => 501, 'comment' => 'Michael Wallner'));
|
|
|
160 |
$_lct = $this->pw->_users['mike']['lct'];
|
|
|
161 |
$rs = $this->pw->save();
|
|
|
162 |
$this->assertTrue($rs);
|
|
|
163 |
$this->assertTrue(!PEAR::isError($rs));
|
|
|
164 |
|
|
|
165 |
list($line) = file($GLOBALS['tmpfile']);
|
|
|
166 |
$test = explode(':', trim(array_shift(file($GLOBALS['tmpfile']))));
|
|
|
167 |
$array= array(
|
|
|
168 |
'mike',
|
|
|
169 |
'501',
|
|
|
170 |
hash_lm(123),
|
|
|
171 |
hash_nt(123),
|
|
|
172 |
'[U ]',
|
|
|
173 |
$_lct,
|
|
|
174 |
'Michael Wallner'
|
|
|
175 |
);
|
|
|
176 |
$this->assertEquals($array, $test);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
?>
|