Apache2-API

 view release on metacpan or  search on metacpan

t/06.apr1.t  view on Meta::CPAN

#!perl
BEGIN
{
    use strict;
    use warnings;
    use lib './lib';
    use open ':std' => ':utf8';
    use Test::Mock::Apache2;
    no strict 'subs';
    use Test::MockObject;
    # use Test2::V0;
    use Test::More;
    use vars qw( $DEBUG $HAVE_REF );
    our $DEBUG = exists( $ENV{AUTHOR_TESTING} ) ? $ENV{AUTHOR_TESTING} : 0;
    our $HAVE_REF = eval{ require Crypt::PasswdMD5; Crypt::PasswdMD5->import('apache_md5_crypt'); 1 } || 0;
};

BEGIN
{
    # use_ok( 'Apache2::API' ) || BAIL_OUT( 'Unable to load Apache2::API' );
    use ok( 'Apache2::API' ) || BAIL_OUT( 'Unable to load Apache2::API' );
};

use strict;
use warnings;

# my $api = Apache2::API->new( debug => $DEBUG );
my $api = Apache2::API->new;

sub verify_apr1
{
    my( $passwd, $hash ) = @_;
    return(0) unless( defined( $passwd ) && defined( $hash ) );
    return(0) unless( $hash =~ m!\A\$apr1\$([./0-9A-Za-z]{1,8})\$([./0-9A-Za-z]{22})\z! );
    my( $salt, $body ) = ( $1, $2 );
    my $calc = apr1_md5( $passwd, $salt );
    return( $hash eq $calc );
}

sub _have_module
{
    my( $m ) = @_;
    local $@;
    return( eval( "require $m; 1" ) ? 1 : 0 );
}

sub _crypt_supports
{
    my( $setting_re, $setting_example ) = @_;
    local $@;
    my $out = eval{ crypt( 'x', $setting_example ); };
    return( !$@ && defined( $out ) && $out =~ $setting_re );
}

# quick helpers to craft settings
sub _bcrypt_setting
{
    my( $cost, $salt22 ) = @_;
    return( sprintf( '$2y$%02d$%s$', $cost, $salt22 ) );
}

sub _sha256_setting
{
    my( $rounds, $salt ) = @_;
    return defined( $rounds )
        ? sprintf( '$5$rounds=%d$%s$', $rounds, $salt )
        : sprintf( '$5$%s$', $salt )



( run in 0.649 second using v1.01-cache-2.11-cpan-39bf76dae61 )