~ubuntu-branches/debian/sid/phpldapadmin/sid

« back to all changes in this revision

Viewing changes to tools/unit_test.php

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2009-03-16 14:54:15 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090316145415-7dsvj319dd02h83j
Tags: 1.1.0.6-1
* New upstream release. (Closes: #518578)
* debian/rules: removed "-m 644" from the dh_install call. (Closes: #518847)
* debian/postrm: remove config.php at purge time. (Closes: #519086)
* debian/patches/hungarian.dpatch: fixed a hungarian translation.
  (Closes: #505559)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
// $Header: /cvsroot/phpldapadmin/phpldapadmin/tools/unit_test.php,v 1.20 2005/07/16 16:23:28 wurley Exp $
3
 
 
4
 
/**
5
 
 * @package phpLDAPadmin
6
 
 */
7
 
/**
8
 
 */
9
 
 
10
 
include './common.php';
11
 
include './header.php';
12
 
echo "<pre>";
13
 
 
14
 
require_once realpath( 'functions.php' );
15
 
 
16
 
// test DN sorting
17
 
if( false ) {
18
 
    $dns = array( "ou=people,dc=example,dc=com", 
19
 
                  "cn=Admin,ou=People,dc=example,dc=com", 
20
 
                  "cn=Joe,ou=people,dc=example,dc=com",
21
 
                  "dc=example,dc=com",
22
 
                  "cn=Fred,ou=people,dc=example,dc=org",
23
 
                  "cn=Dave,ou=people,dc=example,dc=org",
24
 
                  "dc=com"
25
 
                  );
26
 
    usort( $dns, "pla_compare_dns" );
27
 
    foreach( $dns as $dn )
28
 
        echo pretty_print_dn( $dn ) . "<br>";
29
 
}
30
 
 
31
 
// test pla_verbose_error() using ldap_error_codes.txt
32
 
if( false) {
33
 
    for( $i=0; $i<255; $i++ ) {
34
 
        $num = "0x" . str_pad( dechex( $i ), 2, "0", STR_PAD_LEFT );
35
 
        var_dump( $num );
36
 
        print_r( pla_verbose_error( $num ) );
37
 
    }
38
 
}
39
 
 
40
 
// tests is_dn_string()
41
 
if( false ) {
42
 
    $dn_strs = array(     ' cn=joe,dc=example,dc=com', 
43
 
                          'cn = joe, dc= example, dc =com', 
44
 
                          '  cn=asdf asdf, ou= foo bar, o =foo bar, dc=com',
45
 
                          'cn=True!=False,dc=example,dc=com' );
46
 
    $not_dn_strs = array( ' asdf asdf ', 
47
 
                          '== asdf asdf ',
48
 
                          ' = = = = = = = =' );
49
 
 
50
 
    echo "All should be true:\n";
51
 
    foreach( $dn_strs as $str ) {
52
 
        echo "\"$str\"\n";
53
 
        var_dump( is_dn_string( $str ) );
54
 
    }
55
 
    echo "\nAll should be false:\n";
56
 
    foreach( $not_dn_strs as $str ) {
57
 
        echo "\"$str\"\n";
58
 
        var_dump( is_dn_string( $str ) );
59
 
    }
60
 
}
61
 
 
62
 
// tests pla_compare_dns()
63
 
if( false ) {
64
 
    echo "Should all be 0:<br>";
65
 
    $dns1 = array( 'cn=joe,dc=example,dc=com', 'cn=joe,dc=example,dc=com', 'cn = bob, dc= example,dc =com' );
66
 
    $dns2 = array( 'cn=joe,dc=example,dc=com', 'CN =joe,dc=Example,dc =com', 'cn= bob, dc= example,dc =com' );
67
 
 
68
 
    for( $i=0; $i<count($dns1); $i++ ) {
69
 
        var_dump( pla_compare_dns( $dns1[$i], $dns2[$i] ) );
70
 
        echo "\n";
71
 
    }
72
 
 
73
 
    echo "Should all be ! 0:<br>";
74
 
    $dns1 = array( 'dc=test,dc=example,dc=com', 'cn=Fred,cn=joe,dc=example,dc=com', 'cn=joe2,dc=example,dc=com', 'cn = bob, dc= example,dc =com' );
75
 
    $dns2 = array( 'dc=example, dc=com', 'cn=joe,dc=example,dc=com', 'CN =joe,dc=Example2,dc =com', 'cn= 2bob, dc= example,dc =com' );
76
 
 
77
 
    for( $i=0; $i<count($dns1); $i++ ) {
78
 
        var_dump( pla_compare_dns( $dns1[$i], $dns2[$i] ) );
79
 
        echo "\n";
80
 
    }
81
 
}
82
 
 
83
 
// testing get_rdn()
84
 
if( false ) {
85
 
    echo "Should be uid=bäb: ";
86
 
    echo get_rdn( "uid=bäb,ou=People-copy1,ou=People-copy2,ou=People2,dc=example,dc=com" );
87
 
    echo "<br>\n";
88
 
    echo "Should be dc=com: ";
89
 
    echo get_rdn( "dc=com" );
90
 
    echo "<br>\n";
91
 
    echo "Should be Fred: ";
92
 
    echo get_rdn( "Fred" );
93
 
    echo "<br>\n";
94
 
}
95
 
 
96
 
// testing get_container()
97
 
if( false ) {
98
 
    echo "Should be ou=People-copy1,ou=People-copy2,ou=People2,dc=example,dc=com: ";
99
 
    var_dump( get_container( "uid=bäb,ou=People-copy1,ou=People-copy2,ou=People2,dc=example,dc=com" ) );
100
 
    echo "<br>\n";
101
 
    echo "Should be null: ";
102
 
    var_dump( get_container( "dc=com" ) );
103
 
    echo "<br>\n";
104
 
    echo "Should be null: ";
105
 
    var_dump( get_container( "Fred" ) );
106
 
    echo "<br>\n";
107
 
}
108
 
 
109
 
// tests pla_explode_dn()
110
 
if( false ) {
111
 
    var_dump( pla_explode_dn( "cn=<stuff>,dc=example,dc=<com>" ) );
112
 
}
113
 
 
114
 
if( false ) {
115
 
    $password = 'asdf@sadf';
116
 
    foreach( array('md5','md5crypt','sha','ssha','smd5','crypt','clear') as $enc_type ) {
117
 
        $crypted_password = password_hash($password,$enc_type);
118
 
        print "[".$enc_type."] ".$crypted_password."<br />";
119
 
        print "  Test: " . (password_check($crypted_password,$password) ? "passed" : "failed" );
120
 
        print "\n";
121
 
        //unset($crypted_password);
122
 
        flush();
123
 
    }
124
 
}
125
 
 
126
 
if( true ) {
127
 
    $secret = "foobar";
128
 
    $passwords = array( 'fun!244A', 'asdf', 'dc=stuff,ou=things', 'y()ikes' );
129
 
 
130
 
    $passwords_encrypted = array();
131
 
    foreach( $passwords as $password ) {
132
 
        $passwords_encrypted[] = pla_blowfish_encrypt( $password, $secret );        
133
 
    }
134
 
 
135
 
    $passwords_decrypted = array();
136
 
    foreach( $passwords_encrypted as $password ) {
137
 
        $passwords_decrypted[] = pla_blowfish_decrypt( $password, $secret );
138
 
    }
139
 
 
140
 
    foreach( $passwords_decrypted as $i => $password ) {
141
 
        echo $passwords[$i] . ': ' . $passwords_encrypted[$i] . '<br />    ';
142
 
        if( $passwords[$i] == $passwords_decrypted[$i] )
143
 
            echo "passed<br />";
144
 
        else
145
 
            echo "<b>failed!</b></br />";
146
 
    }
147
 
}
148
 
 
149
 
print password_generate();
150
 
?>