Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
require_once 'System.php';
3
require_once 'PHPUnit.php';
4
require_once 'File/Passwd/Authbasic.php';
5
 
6
$GLOBALS['tmpfile'] = System::mktemp();
7
 
8
$GLOBALS['user']    = array(
9
'mike' => 'q4M4mpfilkNnU',
10
'pete' => 'dS80VTLQHZ6VM',
11
'mary' => 'jHSiqFjaEiKPM'
12
);
13
 
14
/**
15
 * TestCase for File_Passwd_AuthbasicTest class
16
 * Generated by PHPEdit.XUnit Plugin
17
 *
18
 */
19
class File_Passwd_AuthbasicTest extends PHPUnit_TestCase{
20
 
21
    var $pwd;
22
 
23
    /**
24
     * Constructor
25
     * @param string $name The name of the test.
26
     * @access protected
27
     */
28
    function File_Passwd_AuthbasicTest($name){
29
        $this->PHPUnit_TestCase($name);
30
    }
31
 
32
    /**
33
     * Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
34
     * @access protected
35
     */
36
    function setUp(){
37
        $this->pwd = &new File_Passwd_Authbasic();
38
    }
39
 
40
    /**
41
     * Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
42
     * @access protected
43
     */
44
    function tearDown(){
45
        $this->pwd = null;
46
    }
47
 
48
    /**
49
     * Regression test for File_Passwd_Authbasic.File_Passwd_Authbasic method
50
     * @access public
51
     */
52
    function testFile_Passwd_Authbasic(){
53
        $this->assertTrue(is_a($this->pwd, 'File_Passwd_Authbasic'));
54
    }
55
 
56
    /**
57
     * Regression test for File_Passwd_Authbasic.save method
58
     * @access public
59
     */
60
    function testsave(){
61
        $this->pwd->setFile($GLOBALS['tmpfile']);
62
        $this->pwd->_users = $GLOBALS['user'];
63
        $this->assertTrue($this->pwd->save());
64
        $this->assertEquals(file('passwd.authbasic.txt'), file($GLOBALS['tmpfile']));
65
    }
66
 
67
    /**
68
     * Regression test for File_Passwd_Authbasic.addUser method
69
     * @access public
70
     */
71
    function testaddUser(){
72
        $this->assertTrue($this->pwd->addUser('add', 123));
73
        $this->assertTrue($this->pwd->userExists('add'));
74
    }
75
 
76
    /**
77
     * Regression test for File_Passwd_Authbasic.changePasswd method
78
     * @access public
79
     */
80
    function testchangePasswd(){
81
        $this->pwd->addUser('change', 123);
82
        $this->assertTrue($this->pwd->changePasswd('change', 'abc'));
83
    }
84
 
85
    /**
86
     * Regression test for File_Passwd_Authbasic.verifyPasswd method
87
     * @access public
88
     */
89
    function testverifyPasswd(){
90
        // DES
91
        $e = $this->pwd->setMode('des');
92
        if (strToUpper(substr(PHP_OS, 0,3)) == 'WIN') {
93
            $this->assertTrue(PEAR::isError($e));
94
        } else {
95
            $this->assertTrue($e);
96
            $this->pwd->addUser('des', 12345);
97
            $this->assertTrue($this->pwd->verifyPasswd('des', 12345));
98
            $this->assertFalse($this->pwd->verifyPasswd('des', ''));
99
        }
100
        // SHA
101
        $this->pwd->setMode('sha');
102
        $this->pwd->addUser('sha', 12345);
103
        $this->assertTrue($this->pwd->verifyPasswd('sha', 12345));
104
        $this->assertFalse($this->pwd->verifyPasswd('sha', ''));
105
        // MD5
106
        $this->pwd->setMode('md5');
107
        $this->pwd->addUser('md5', 12345);
108
        $this->assertTrue($this->pwd->verifyPasswd('md5', 12345));
109
        $this->assertFalse($this->pwd->verifyPasswd('md5', 2));
110
    }
111
 
112
    /**
113
     * Regression test for File_Passwd_Authbasic.getMode method
114
     * @access public
115
     */
116
    function testgetMode(){
117
        $this->pwd->setMode('md5');
118
        $this->assertEquals('md5', $this->pwd->getMode());
119
        $this->pwd->setMode('sha');
120
        $this->assertEquals('sha', $this->pwd->getMode());
121
    }
122
 
123
    /**
124
     * Regression test for File_Passwd_Authbasic.listModes method
125
     * @access public
126
     */
127
    function testlistModes(){
128
        $array = array('md5' => 'm', 'des' => 'd', 'sha' => 's');
129
        if (strToUpper(substr(PHP_OS, 0,3)) == 'WIN') {
130
            unset($array['des']);
131
        }
132
        $this->assertEquals(array_keys($array), $this->pwd->listModes());
133
    }
134
 
135
    /**
136
     * Regression test for File_Passwd_Authbasic.setMode method
137
     * @access public
138
     */
139
    function testsetMode(){
140
        $this->pwd->setMode('md5');
141
        $this->assertEquals('md5', $this->pwd->getMode());
142
        $this->pwd->setMode('sha');
143
        $this->assertEquals('sha', $this->pwd->getMode());
144
    }
145
 
146
    /**
147
     * Regression test for File_Passwd_Authbasic.parse method
148
     * @access public
149
     */
150
    function testparse(){
151
        $this->pwd->setFile('passwd.authbasic.txt');
152
        $this->assertTrue($this->pwd->load());
153
        $this->assertEquals($GLOBALS['user'], $this->pwd->_users);
154
    }
155
 
156
    function teststaticAuth(){
157
        $this->assertTrue(true === File_Passwd::staticAuth('authbasic', 'passwd.authbasic.txt', 'mike', 123, 'des'));
158
        $this->assertTrue(false === File_Passwd::staticAuth('authbasic', 'passwd.authbasic.txt', 'mike', 'abc', 'des'));
159
        $this->assertFalse((File_Passwd::staticAuth('authbasic', 'passwd.authbasic.txt', 'nonexist', 'asd', 'des')));
160
    }
161
}
162
?>