Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
require_once 'PHPUnit.php';
4
require_once 'File/Passwd.php';
5
 
6
$GLOBALS['_EXT_'] = array('Unix', 'Cvs', 'Smb', 'Authbasic', 'Authdigest');
7
 
8
/**
9
 * TestCase for File_PasswdTest class
10
 * Generated by PHPEdit.XUnit Plugin
11
 *
12
 */
13
class File_PasswdTest extends PHPUnit_TestCase{
14
    /**
15
     * Constructor
16
     * @param string $name The name of the test.
17
     * @access protected
18
     */
19
    function File_PasswdTest($name){
20
        $this->PHPUnit_TestCase($name);
21
    }
22
 
23
    /**
24
     * Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
25
     * @access protected
26
     */
27
    function setUp(){
28
 
29
    }
30
 
31
    /**
32
     * Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
33
     * @access protected
34
     */
35
    function tearDown(){
36
 
37
    }
38
 
39
    /**
40
     * Regression test for File_Passwd.apiVersion method
41
     * @access public
42
     */
43
    function testapiVersion(){
44
        $this->assertEquals('1.0.0', File_Passwd::apiVersion());
45
    }
46
 
47
    /**
48
     * Regression test for File_Passwd.salt method
49
     * @access public
50
     */
51
    function testsalt(){
52
        $this->assertEquals(strlen(File_Passwd::salt()), strlen(File_Passwd::salt(2)));
53
        $regex = '/^[' . preg_quote($GLOBALS['_FILE_PASSWD_64'], '/') . ']+$/';
54
        $this->assertTrue(preg_match($regex, File_Passwd::salt(20)));
55
    }
56
 
57
    /**
58
     * Regression test for File_Passwd.crypt_des method
59
     * @access public
60
     */
61
    function testcrypt_des(){
62
        $this->assertEquals(crypt('a','ab'), File_Passwd::crypt_des('a', 'ab'));
63
    }
64
 
65
    /**
66
     * Regression test for File_Passwd.crypt_md5 method
67
     * @access public
68
     */
69
    function testcrypt_md5(){
70
        $this->assertEquals(crypt('a','$1$ab'), File_Passwd::crypt_des('a', '$1$ab'));
71
    }
72
 
73
    /**
74
     * Regression test for File_Passwd.crypt_sha method
75
     * @access public
76
     */
77
    function testcrypt_sha(){
78
        $sha = '{SHA}2iNhTgJGmg18e9G9q1ycR0sZBNw=';
79
        $this->assertEquals($sha, File_Passwd::crypt_sha('ab'));
80
    }
81
 
82
    /**
83
     * Regression test for File_Passwd.crypt_apr_md5 method
84
     * @access public
85
     */
86
    function testcrypt_apr_md5(){
87
        $apr = '$apr1$ab$KfzLTsXi6eQkfErEn8CHY.';
88
        $this->assertEquals($apr, File_Passwd::crypt_apr_md5('ab', 'ab'));
89
    }
90
 
91
    /**
92
     * Regression test for File_Passwd.factory method
93
     * @access public
94
     */
95
    function testfactory(){
96
        foreach($GLOBALS['_EXT_'] as $ext){
97
            $o = File_Passwd::factory($ext);
98
            $this->assertTrue(is_a($o, "File_Passwd_$ext"));
99
        }
100
    }
101
 
102
    /**
103
     * Regression test for File_Passwd.staticAuth method
104
     * @access public
105
     */
106
    function teststaticAuth(){
107
        foreach($GLOBALS['_EXT_'] as $ext){
108
            $pwfile = 'passwd.' . strToLower($ext) . '.txt';
109
            $option = (($ext == 'Authdigest') ? 'realm1' : (($ext == 'Smb') ? 'nt' : 'des'));
110
            $error = File_Passwd::staticAuth($ext, $pwfile, 'mike', 123, $option);
111
            $this->assertTrue($error);
112
            if (PEAR::isError($error)) {
113
                echo "File_Passwd_$ext::staticAuth() ". $error->getMessage() . "\n";
114
            }
115
        }
116
 
117
    }
118
 
119
}
120
 
121
?>