Ignore:
Timestamp:
Jun 3, 2006 7:47:48 PM (18 years ago)
Author:
scdev
Message:

Q - Merged branches/2.0singleton into trunk. Completed updating classes to use singleton methods. Implemented tests. Fixed some bugs. Changed some interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/Auth_SQLTest.php

    r42 r136  
    2121    function setUp()
    2222    {
    23         require dirname(__FILE__) . '/_config.inc.php';
     23        require dirname(__FILE__) . '/_config.inc.php';
    2424        require_once '../lib/Auth_SQL.inc.php';
    2525        $this->Auth_SQL =& new Auth_SQL('testauth');
     
    2929            'db_login_table'    => 'test_login_tbl',
    3030            'login_url'         => '/login.php',
    31             'blocking'          => true
     31            'blocking'          => true,
     32            'encryption_type' => AUTH_ENCRYPT_MD5_HARDENED,
    3233        ));
    3334
     
    3637
    3738        // Insert test data.
    38         DB::query("
     39        $db =& DB::getInstance();
     40        $db->query("
    3941            INSERT INTO test_user_tbl (
    4042                username,
     
    4648            ) VALUES (
    4749                'testuser',
    48                 md5('testpass'),
     50                '" . $this->Auth_SQL->encryptPassword('testpass') . "',
    4951                'John',
    5052                'Doe',
     
    5860    function tearDown()
    5961    {
    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");
    6367    }
    6468
     
    6670    {
    6771        $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']);
    6973    }
    7074
    7175    function test_getval()
    7276    {
    73         $_SESSION[$this->Auth_SQL->_sess]['user_data']['testuserkey'] = 'testuserval';
     77        $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey'] = 'testuserval';
    7478        $val = $this->Auth_SQL->getVal('testuserkey');
    7579        $this->assertEquals('testuserval', $val);
     
    107111        $this->assertTrue($true, 'User login failed, but should have succeeded.');
    108112
    109         echo "Testing wrong password...\n";
     113        // Testing wrong password.
    110114        $false = $this->Auth_SQL->authenticate('testuser', 'wrongpass');
    111115
     
    122126        $after_logged_in = $this->Auth_SQL->isloggedin();
    123127        $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.
    126130        $login2 = $this->Auth_SQL->login('testuser', 'wrongpass');
    127131        $this->assertFalse($login2, '4. User login succeeded, but should have failed.');
     
    140144    function test_blockaccount()
    141145    {
     146        $db =& DB::getInstance();
     147   
    142148        $this->Auth_SQL->login('testuser', 'testpass');
    143149        $this->Auth_SQL->blockaccount(null, 'blocktestuser');
    144         $qid = DB::query("
     150        $qid = $db->query("
    145151            SELECT blocked_reason
    146152            FROM test_user_tbl
     
    152158    function test_unblockaccount()
    153159    {
    154         DB::query("
     160        $db =& DB::getInstance();
     161   
     162        $db->query("
    155163            UPDATE test_user_tbl SET blocked_reason = 'blocktestuser'
    156164        ");
    157165        $this->Auth_SQL->unblockaccount();
    158166
    159         $qid = DB::query("
     167        $qid = $db->query("
    160168            SELECT blocked_reason
    161169            FROM test_user_tbl
     
    185193    function test_encryptpassword()
    186194    {
     195        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_MD5));
    187196        $result = $this->Auth_SQL->encryptpassword('123');
    188197        $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);
    189218    }
    190219
    191220    function test_setpassword()
    192221    {
     222        $db =& DB::getInstance();
     223   
     224        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1_HARDENED));
    193225        $this->Auth_SQL->setpassword(null, '123');
    194         $qid = DB::query("
     226        $qid = $db->query("
    195227            SELECT userpass
    196228            FROM test_user_tbl
    197229        ");
    198230        list($pass) = mysql_fetch_row($qid);
    199         $this->assertEquals('202cb962ac59075b964b07152d234b70', $pass);
     231        $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $pass);
    200232    }
    201233
Note: See TracChangeset for help on using the changeset viewer.