Changeset 136 for trunk/tests/Auth_SQLTest.php
- Timestamp:
- Jun 3, 2006 7:47:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/Auth_SQLTest.php
r42 r136 21 21 function setUp() 22 22 { 23 23 require dirname(__FILE__) . '/_config.inc.php'; 24 24 require_once '../lib/Auth_SQL.inc.php'; 25 25 $this->Auth_SQL =& new Auth_SQL('testauth'); … … 29 29 'db_login_table' => 'test_login_tbl', 30 30 'login_url' => '/login.php', 31 'blocking' => true 31 'blocking' => true, 32 'encryption_type' => AUTH_ENCRYPT_MD5_HARDENED, 32 33 )); 33 34 … … 36 37 37 38 // Insert test data. 38 DB::query(" 39 $db =& DB::getInstance(); 40 $db->query(" 39 41 INSERT INTO test_user_tbl ( 40 42 username, … … 46 48 ) VALUES ( 47 49 'testuser', 48 md5('testpass'),50 '" . $this->Auth_SQL->encryptPassword('testpass') . "', 49 51 'John', 50 52 'Doe', … … 58 60 function tearDown() 59 61 { 60 unset($this->Auth_SQL); 61 DB::query("DROP TABLE IF EXISTS test_user_tbl"); 62 DB::query("DROP TABLE IF EXISTS test_login_tbl"); 62 $db =& DB::getInstance(); 63 64 unset($this->Auth_SQL); 65 $db->query("DROP TABLE IF EXISTS test_user_tbl"); 66 $db->query("DROP TABLE IF EXISTS test_login_tbl"); 63 67 } 64 68 … … 66 70 { 67 71 $this->Auth_SQL->setval('testuserkey', 'testuserval'); 68 $this->assertEquals('testuserval', $_SESSION[$this->Auth_SQL->_ sess]['user_data']['testuserkey']);72 $this->assertEquals('testuserval', $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey']); 69 73 } 70 74 71 75 function test_getval() 72 76 { 73 $_SESSION[$this->Auth_SQL->_ sess]['user_data']['testuserkey'] = 'testuserval';77 $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey'] = 'testuserval'; 74 78 $val = $this->Auth_SQL->getVal('testuserkey'); 75 79 $this->assertEquals('testuserval', $val); … … 107 111 $this->assertTrue($true, 'User login failed, but should have succeeded.'); 108 112 109 echo "Testing wrong password...\n";113 // Testing wrong password. 110 114 $false = $this->Auth_SQL->authenticate('testuser', 'wrongpass'); 111 115 … … 122 126 $after_logged_in = $this->Auth_SQL->isloggedin(); 123 127 $this->assertFalse($after_logged_in, '3. User is still logged in but should not be.'); 124 125 echo "Testing wrong password...\n";128 129 // Testing wrong password. 126 130 $login2 = $this->Auth_SQL->login('testuser', 'wrongpass'); 127 131 $this->assertFalse($login2, '4. User login succeeded, but should have failed.'); … … 140 144 function test_blockaccount() 141 145 { 146 $db =& DB::getInstance(); 147 142 148 $this->Auth_SQL->login('testuser', 'testpass'); 143 149 $this->Auth_SQL->blockaccount(null, 'blocktestuser'); 144 $qid = DB::query("150 $qid = $db->query(" 145 151 SELECT blocked_reason 146 152 FROM test_user_tbl … … 152 158 function test_unblockaccount() 153 159 { 154 DB::query(" 160 $db =& DB::getInstance(); 161 162 $db->query(" 155 163 UPDATE test_user_tbl SET blocked_reason = 'blocktestuser' 156 164 "); 157 165 $this->Auth_SQL->unblockaccount(); 158 166 159 $qid = DB::query("167 $qid = $db->query(" 160 168 SELECT blocked_reason 161 169 FROM test_user_tbl … … 185 193 function test_encryptpassword() 186 194 { 195 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_MD5)); 187 196 $result = $this->Auth_SQL->encryptpassword('123'); 188 197 $this->assertEquals('202cb962ac59075b964b07152d234b70', $result); 198 199 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_MD5_HARDENED)); 200 $result = $this->Auth_SQL->encryptpassword('123'); 201 $this->assertEquals('c55e4ac608a8768ecd758fab971b0646', $result); 202 203 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1)); 204 $result = $this->Auth_SQL->encryptpassword('123'); 205 $this->assertEquals('40bd001563085fc35165329ea1ff5c5ecbdbbeef', $result); 206 207 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1_HARDENED)); 208 $result = $this->Auth_SQL->encryptpassword('123'); 209 $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $result); 210 211 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_PLAINTEXT)); 212 $result = $this->Auth_SQL->encryptpassword('123'); 213 $this->assertEquals('123', $result); 214 215 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_CRYPT)); 216 $result = $this->Auth_SQL->encryptpassword('123', 'saltstring'); 217 $this->assertEquals('saEZ6MlWYV9nQ', $result); 189 218 } 190 219 191 220 function test_setpassword() 192 221 { 222 $db =& DB::getInstance(); 223 224 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1_HARDENED)); 193 225 $this->Auth_SQL->setpassword(null, '123'); 194 $qid = DB::query("226 $qid = $db->query(" 195 227 SELECT userpass 196 228 FROM test_user_tbl 197 229 "); 198 230 list($pass) = mysql_fetch_row($qid); 199 $this->assertEquals(' 202cb962ac59075b964b07152d234b70', $pass);231 $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $pass); 200 232 } 201 233
Note: See TracChangeset
for help on using the changeset viewer.