File: util.pm

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,912 kB
  • ctags: 4,588
  • sloc: perl: 95,064; ansic: 14,527; makefile: 49; sh: 18
file content (57 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
package TestAPRlib::util;

# test APR::Util

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;

use APR::Util ();

use constant CRYPT_WORKS => $^O !~ /^(MSWin32|beos|NetWare)$/;

my $clear = "this is some text";
# to get the hash values used:
# htpasswd -nb[sm] user "this is some text"
my %hashes = (
    crypt => 'pHM3JfnL6isho',
    md5   => '$apr1$Kld6H/..$o5OPPPWslI3zB20S54u9s1',
    sha1  => '{SHA}A5NpTRa4TethLkfOYlK9NfDYbAY=',
);

# BACK_COMPAT_MARKER (sha1 support added in 2.0.50)
delete $hashes{sha1} unless have_min_apache_version('2.0.50');

sub num_of_tests {
    return 1 + scalar keys %hashes;
}

sub test {

    # password_validate
    {
        ok ! APR::Util::password_validate("one", "two");

        while (my ($mode, $hash) = each %hashes) {
            t_debug($mode);
            if ($mode eq 'crypt' && !CRYPT_WORKS) {
                t_debug("crypt is not supported on $^O");
                ok 1; # don't make noise
            }
            else {
                ok APR::Util::password_validate($clear, $hash);
            }
        }
    }

#this function seems unstable on certain platforms
#    my $blen = 10;
#    my $bytes = APR::generate_random_bytes($blen);
#    ok length($bytes) == $blen;

}

1;