<commit_before>package TestAPR::util;

# test APR::Util

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

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

use APR::Util ();

use Apache::Const -compile => 'OK';

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=',
);

sub handler {
    my $r = shift;

    plan $r, tests => 4;

    # 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;

    Apache::OK;
}

1;<commit_msg>sha1 support added in 2.0.50 PR: Obtained from: Submitted by: Reviewed by:<commit_after>package TestAPR::util;

# test APR::Util

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

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

use APR::Util ();

use Apache::Const -compile => 'OK';

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_apache_version('2.0.50');

my $password_validate_tests = 1 + scalar keys %hashes;

sub handler {
    my $r = shift;

    plan $r, tests => $password_validate_tests;

    # 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;

    Apache::OK;
}

1;
{'fraction_non_alphanumeric': 0.15163934426229508, 'fraction_numerical': 0.02347242921013413, 'mean_word_length': 2.6630286493860846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5495012', 'n_tokens_mistral': 1044, 'n_tokens_neox': 971, 'n_words': 244}