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/Authdigest.php';
5
 
6
$GLOBALS['tmpfile'] = System::mktemp();
7
$GLOBALS['user']    = array (
8
    'mike' => array('realm1' => 'bbcaa08c9944893b29376d9536a5c0d8'),
9
    'pete' => array('realm1' => 'd5ae80288114955ea9d71fcbd8ca4b7d'),
10
    'mary' => array('realm1' => 'f6b5c730306e1860292640d7be039680')
11
);
12
 
13
/**
14
 * TestCase for File_Passwd_AuthdigestTest class
15
 * Generated by PHPEdit.XUnit Plugin
16
 *
17
 */
18
class File_Passwd_AuthdigestTest extends PHPUnit_TestCase{
19
 
20
    var $pwd;
21
 
22
    /**
23
     * Constructor
24
     * @param string $name The name of the test.
25
     * @access protected
26
     */
27
    function File_Passwd_AuthdigestTest($name){
28
        $this->PHPUnit_TestCase($name);
29
    }
30
 
31
    /**
32
     * Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
33
     * @access protected
34
     */
35
    function setUp(){
36
        $this->pwd = &new File_Passwd_Authdigest();
37
    }
38
 
39
    /**
40
     * Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
41
     * @access protected
42
     */
43
    function tearDown(){
44
        $this->pwd = null;
45
    }
46
 
47
    /**
48
     * Regression test for File_Passwd_Authdigest.File_Passwd_Authdigest method
49
     * @access public
50
     */
51
    function testFile_Passwd_Authdigest(){
52
        $this->assertTrue(is_a($this->pwd, 'File_Passwd_Authdigest'));
53
    }
54
 
55
    /**
56
     * Regression test for File_Passwd_Authdigest.save method
57
     * @access public
58
     */
59
    function testsave(){
60
        $this->pwd->setFile($GLOBALS['tmpfile']);
61
        $this->pwd->_users = $GLOBALS['user'];
62
        $this->assertTrue($this->pwd->save());
63
        $this->assertEquals(file('passwd.authdigest.txt'), file($GLOBALS['tmpfile']));
64
    }
65
 
66
    /**
67
     * Regression test for File_Passwd_Authdigest.addUser method
68
     * @access public
69
     */
70
    function testaddUser(){
71
        $this->assertTrue($this->pwd->addUser('add', 'realm2', 123));
72
        $this->assertTrue($this->pwd->userExists('add'));
73
    }
74
 
75
    /**
76
     * Regression test for File_Passwd_Authdigest.listUserInRealm method
77
     * @access public
78
     */
79
    function testlistUserInRealm(){
80
        $this->pwd->_users = $GLOBALS['user'];
81
        $array = array(
82
            'realm1' => array(
83
                'mike' => 'bbcaa08c9944893b29376d9536a5c0d8',
84
                'pete' => 'd5ae80288114955ea9d71fcbd8ca4b7d',
85
                'mary' => 'f6b5c730306e1860292640d7be039680'
86
            )
87
        );
88
        $this->assertEquals($array, $this->pwd->listUserInRealm('realm1'));
89
        $this->assertEquals($array, $this->pwd->listUserInRealm());
90
    }
91
 
92
    /**
93
     * Regression test for File_Passwd_Authdigest.changePasswd method
94
     * @access public
95
     */
96
    function testchangePasswd(){
97
        $this->pwd->addUser('change', 'realm2', 123);
98
        $this->assertTrue($this->pwd->changePasswd('change', 'realm2', 'abc'));
99
    }
100
 
101
    /**
102
     * Regression test for File_Passwd_Authdigest.verifyPasswd method
103
     * @access public
104
     */
105
    function testverifyPasswd(){
106
        $this->pwd->addUser('verify', 'realm2', 12345);
107
        $this->assertTrue($this->pwd->verifyPasswd('verify', 'realm2', 12345));
108
        $this->assertFalse($this->pwd->verifyPasswd('verify', 'realm2', ''));
109
    }
110
 
111
    /**
112
     * Regression test for File_Passwd_Authdigest.userInRealm method
113
     * @access public
114
     */
115
    function testuserInRealm(){
116
        $this->pwd->_users = $GLOBALS['user'];
117
        $this->assertTrue($this->pwd->userInRealm('mike', 'realm1'));
118
        $this->assertFalse($this->pwd->userInRealm('sam', 'realm1'));
119
    }
120
 
121
    /**
122
     * Regression test for File_Passwd_Authdigest.delUserInRealm method
123
     * @access public
124
     */
125
    function testdelUserInRealm(){
126
        $this->pwd->_users = $GLOBALS['user'];
127
        $this->assertTrue($this->pwd->delUserInRealm('mike', 'realm1'));
128
        $this->assertTrue(PEAR::isError($this->pwd->delUserInRealm('sam', 'realm2')));
129
    }
130
 
131
    /**
132
     * Regression test for File_Passwd_Authdigest.parse method
133
     * @access public
134
     */
135
    function testparse(){
136
        $this->pwd->setFile('passwd.authdigest.txt');
137
        $this->assertTrue($this->pwd->load());
138
        $this->assertEquals($GLOBALS['user'], $this->pwd->_users);
139
    }
140
 
141
    function teststaticAuth(){
142
        $this->assertTrue(true === File_Passwd::staticAuth('authdigest', 'passwd.authdigest.txt', 'mike', 123, 'realm1'));
143
        $this->assertTrue(false === File_Passwd::staticAuth('authdigest', 'passwd.authdigest.txt', 'mike', 'abc', 'realm1'));
144
        $this->assertFalse((File_Passwd::staticAuth('authdigest', 'passwd.authdigest.txt', 'nonexist', 'asd', 'norealm')));
145
    }
146
}
147
 
148
?>