Apache2-API

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

    Apache::TestMM->import( qw(test clean) ); #enable 'make test'
    $WriteMakefileArgs{PREREQ_PM}->{ 'Apache::Test' } = 0;

    @scripts = qw( t/TEST );
    # accept the configs from command line
    Apache::TestMM::filter_args();
    my $ref = {@Apache::TestMM::Argv};
    $ref->{_HAS_APACHE_TEST} = 1;
    
    my $config = Apache::TestConfig->thaw->httpd_config;
    my( $has_ssl, $has_perl_ssl, $has_error ) = ( 0, '', 0 );
    $ref->{_HAS_SSL} = 0;
    # require Data::Dump;
    if( $MY_DEBUG > 2 )
    {
        require Data::Dump;
        print( STDERR "Apache::TestConfig->thaw->httpd_config yields: ", Data::Dump::dump( $config ), "\n" );
    }
    if( ref( $config ) eq 'Apache::TestConfig' )
    {
        $has_ssl = $config->{modules}->{ $config->{vars}->{ssl_module} } ? 1 : 0;
        my $apache_bin = $config->{vars}->{httpd};
        if( !$apache_bin )
        {
            eval
            {
                require File::Which;
            };
            if( !$@ )
            {
                for( qw( apache2 httpd ) )

Makefile.PL  view on Meta::CPAN

        my $cmd = '';
        if( $apache_bin )
        {
            print( STDERR "Checking Apache2 configuration with binary $apache_bin\n" ) if( $MY_DEBUG );
            $cmd .= ". $config->{vars}->{conf_dir}/envvars; " if( $config->{vars}->{conf_dir} && -e( "$config->{vars}->{conf_dir}/envvars" ) );
            $cmd .= $apache_bin;
            open( my $io, "${cmd} -M 2>&1|" );
            while( <$io> )
            {
                print( STDERR $_ ) if( $MY_DEBUG );
                $has_ssl++, last if( /ssl/i );
                if( /Syntax[[:blank:]]+error[[:blank:]]+(?:on|at)[[:blank:]]+line[[:blank:]]+(\d+)/i )
                {
                    $has_error = $1;
                }
            }
            close( $io );
            print( STDERR "# Done\n" ) if( $MY_DEBUG );
        }
        warn( "[warning] You have syntax error in your Apache configuration file at line $has_error. You might want to do an apache2ctl configtest or (${cmd} -t)\n" ) if( $has_error );
        
        print( STDERR "Checking for SSL modules IO::Socket::SSL or Net::SSL\n" ) if( $MY_DEBUG );
        # IO::Socket::SSL or Net::SSL
        eval( 'require IO::Socket::SSL' );
        if( $@ )
        {
            my $io_ssl_err = $@;
            eval( 'require Net::SSL' );
            unless( $@ )
            {
                $has_perl_ssl = 'Net::SSL';
            }
        }
        else
        {
            $has_perl_ssl = 'IO::Socket::SSL';
        }
        
        if( $has_ssl && $has_perl_ssl )
        {
            print( STDERR "Found Apache module mod_ssl enabled and $has_perl_ssl module installed. Ok\n" ) if( $MY_DEBUG );
            $ref->{_HAS_SSL} = 1;
        }
        elsif( $has_ssl && !$has_perl_ssl )
        {
            print( STDERR "Found Apache module mod_ssl enabled, but missing perl modules (either IO::Socket::SSL or Net::SSL)\n" ) if( $MY_DEBUG );
        }
        elsif( !$has_ssl && $has_perl_ssl )
        {
            print( STDERR "Apache module mod_ssl is not enabled, but found $has_perl_ssl\n" ) if( $MY_DEBUG );
        }
        else
        {
            print( STDERR "Apache module mod_ssl is not enabled and could not find either IO::Socket::SSL nor Net::SSL, deactivating the use of SSL for our tests.\n" ) if( $MY_DEBUG );
        }
    }
    
    print( STDERR "apxs specified? ", ( $ref->{apxs} ? "yes at $ref->{apxs}" : 'no' ), "\n" ) if( $MY_DEBUG );
    if( !$ref->{apxs} )
    {
        my $apxs;
        eval
        {
            require Apache2::BuildConfig;

Makefile.PL  view on Meta::CPAN

location of perl pod documents (for testing downloads)

=head2 -php_module_name

php module name

=head2 -port

Port [port_number|select] (default C<8529>)

=head2 -proxyssl_url

url for testing ProxyPass / https (default is localhost)

=head2 -sbindir

Apache sbin/ dir (default is C<apxs -q SBINDIR>)

=head2 -servername

ServerName (default is localhost)

=head2 -serverroot

ServerRoot (default is C<$t_dir>)

=head2 -src_dir

source directory to look for C<mod_foos.so>

=head2 -ssl_module_name

ssl module name

=head2 -sslca

location of SSL CA (default is C<$t_conf/ssl/ca>)

=head2 -sslcaorg

SSL CA organization to use for tests (default is asf)

=head2 -sslproto

SSL/TLS protocol version(s) to test

=head2 -startup_timeout

seconds to wait for the server to start (default is 60)

=head2 -t_conf

the conf/ test directory (default is C<$t_dir/conf>)

README  view on Meta::CPAN


    "-perlpod"
        location of perl pod documents (for testing downloads)

    "-php_module_name"
        php module name

    "-port"
        Port [port_number|select] (default 8529)

    "-proxyssl_url"
        url for testing ProxyPass / https (default is localhost)

    "-sbindir"
        Apache sbin/ dir (default is "apxs -q SBINDIR")

    "-servername"
        ServerName (default is "localhost")

    "-serverroot"
        ServerRoot (default is $t_dir)

    "-src_dir"
        source directory to look for "mod_foos.so"

    "-ssl_module_name"
        ssl module name

    "-sslca"
        location of SSL CA (default is "$t_conf/ssl/ca")

    "-sslcaorg"
        SSL CA organization to use for tests (default is asf)

    "-sslproto"
        SSL/TLS protocol version(s) to test

    "-startup_timeout"
        seconds to wait for the server to start (default is 60)

    "-t_conf"
        the conf/ test directory (default is "$t_dir/conf")

    "-t_conf_file"
        test httpd.conf file (default is "$t_conf/httpd.conf")

README  view on Meta::CPAN


    "-preamble"
        config to add at the beginning of "httpd.conf"

    "-proxy"
        proxy requests (default proxy is localhost)

    "-run-tests"
        run the tests

    "-ssl"
        run tests through ssl

    "-start-httpd"
        start the test server

    "-stop-httpd"
        stop the test server

    "-trace=T"
        change tracing default to: warning, notice, info, debug, ...

README.md  view on Meta::CPAN

    location of perl pod documents (for testing downloads)

- `-php_module_name`

    php module name

- `-port`

    Port \[port\_number|select\] (default `8529`)

- `-proxyssl_url`

    url for testing ProxyPass / https (default is localhost)

- `-sbindir`

    Apache sbin/ dir (default is `apxs -q SBINDIR`)

- `-servername`

    ServerName (default is `localhost`)

- `-serverroot`

    ServerRoot (default is `$t_dir`)

- `-src_dir`

    source directory to look for `mod_foos.so`

- `-ssl_module_name`

    ssl module name

- `-sslca`

    location of SSL CA (default is `$t_conf/ssl/ca`)

- `-sslcaorg`

    SSL CA organization to use for tests (default is asf)

- `-sslproto`

    SSL/TLS protocol version(s) to test

- `-startup_timeout`

    seconds to wait for the server to start (default is `60`)

- `-t_conf`

    the conf/ test directory (default is `$t_dir/conf`)

README.md  view on Meta::CPAN

    config to add at the beginning of `httpd.conf`

- `-proxy`

    proxy requests (default proxy is localhost)

- `-run-tests`

    run the tests

- `-ssl`

    run tests through ssl

- `-start-httpd`

    start the test server

- `-stop-httpd`

    stop the test server

- `-trace=T`

lib/Apache2/API.pm  view on Meta::CPAN

location of perl pod documents (for testing downloads)

=item C<-php_module_name>

php module name

=item C<-port>

Port [port_number|select] (default C<8529>)

=item C<-proxyssl_url>

url for testing ProxyPass / https (default is localhost)

=item C<-sbindir>

Apache sbin/ dir (default is C<apxs -q SBINDIR>)

=item C<-servername>

ServerName (default is C<localhost>)

=item C<-serverroot>

ServerRoot (default is C<$t_dir>)

=item C<-src_dir>

source directory to look for C<mod_foos.so>

=item C<-ssl_module_name>

ssl module name

=item C<-sslca>

location of SSL CA (default is C<$t_conf/ssl/ca>)

=item C<-sslcaorg>

SSL CA organization to use for tests (default is asf)

=item C<-sslproto>

SSL/TLS protocol version(s) to test

=item C<-startup_timeout>

seconds to wait for the server to start (default is C<60>)

=item C<-t_conf>

the conf/ test directory (default is C<$t_dir/conf>)

lib/Apache2/API.pm  view on Meta::CPAN

config to add at the beginning of C<httpd.conf>

=item C<-proxy>

proxy requests (default proxy is localhost)

=item C<-run-tests>

run the tests

=item C<-ssl>

run tests through ssl

=item C<-start-httpd>

start the test server

=item C<-stop-httpd>

stop the test server

=item C<-trace=T>

lib/Apache2/API/Request.pm  view on Meta::CPAN

    $is_initial = $req->is_initial_req;

Determines whether the current request is the main request or a sub-request.

This returns a boolean value.

See also L<main|/main>, which returns the main request object.

=head2 is_secure

Returns true (1) if the connection is made under ssl, i.e. of the environment variable C<HTTPS> is set to C<on>, other it returns false (0).

This is done by checking if the environment variable C<HTTPS> is set to C<on> or not.

=head2 json

Returns a L<JSON> object with the C<relaxed> attribute enabled so that it allows more relaxed C<JSON> data.

You can provide an optional hash or hash reference of properties to enable or disable:

    my $J = $api->json( pretty => 1, relaxed => 1 );

lib/Apache2/API/Response.pm  view on Meta::CPAN

        name => $name,
        value => $some_value,
        value => 'sid1234567',
        path => '/',
        expires => '+10D',
        # or alternatively
        maxage => 864000
        # to make it exclusively accessible by regular http request and not javascript
        http_only => 1,
        same_site => 'Lax',
        # should it be used under ssl only?
        secure => 1
    );
    $resp->cookie_replace( $cookie );
    $resp->cookie_set( $cookie );
    # Cross-Origin-Embedder-Policy
    my $policy = $resp->cross_origin_embedder_policy;
    # Cross-Origin-Opener-Policy
    my $policy = $resp->cross_origin_opener_policy;
    # Cross-Origin-Resource-Policy
    my $policy = $resp->cross_origin_resource_policy;

lib/Apache2/API/Status.pm  view on Meta::CPAN

        412 => "Förhandsvillkor uppfylldes inte!",
        413 => "Begärans innehåll är för stort!",
        414 => "Efterfrågad URI för lång!",
        415 => "Mediatypen stöds ej!",
        416 => "Begärt intervall kan inte tillgodoses!",
        417 => "Förväntan uppfylldes inte!",
        418 => "Jag är en tekanna",
        421 => "Feladresserad begäran",
        422 => "Obehandlingsbar enhet!",
        423 => "Resursen är låst!",
        424 => "Misslyckat beroende!",
        425 => "För tidigt!",
        426 => "Uppgradering krävs!",
        428 => "Förhandsvillkor krävs",
        429 => "För många förfrågningar!",
        431 => "Begäransrubriker för stora!",
        444 => "Anslutning stängd utan svar",
        451 => "Otillgänglig av juridiska skäl!",
        499 => "Begäran stängd av klienten",
        500 => "Serverfel!",
        501 => "Kan inte behandla begäran!",

t/01.api.t  view on Meta::CPAN

                Host            => "${mp_host}:${port}",
                Accept          => 'application/json; version=1.0; charset=utf-8, text/javascript, */*',
                Accept_Encoding => 'gzip, deflate, br',
                Accept_Language => 'en-GB,fr-FR;q=0.8,fr;q=0.6,ja;q=0.4,en;q=0.2',
            ),
            keep_alive      => 1,
        );
        Apache::TestRequest::user_agent( @ua_args, reset => 1 );
        $ua = Apache::TestRequest->new( @ua_args );
        # To get the fingerprint for the certificate in ./t/server.crt, do:
        # echo "sha1\$$(openssl x509 -noout -in ./t/server.crt -fingerprint -sha1|perl -pE 's/^.*Fingerprint=|(\w{2})(?:\:?|$)/$1/g')"
        $ua->ssl_opts(
            # SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, 
            # SSL_verify_mode => 0x00
            # verify_hostname => 0,
            SSL_fingerprint => 'sha1$DEE8650E44870896E821AAE4A5A24382174D100E',
            # SSL_version     => 'SSLv3',
            # SSL_verfifycn_name => 'localhost',
        );
    }
    $proto = HAS_SSL ? 'https' : 'http';
    diag( "Host: '$host', port '$port'" ) if( $DEBUG );

t/conf/extra.conf.in  view on Meta::CPAN

# -*- conf -*-
# this file will be Include-d by @ServerRoot@/conf/httpd.conf

<IfModule mod_ssl.c>
    SSLEngine on
    SSLCertificateFile    @ServerRoot@/server.crt
    SSLCertificateKeyFile @ServerRoot@/server.key
</IfModule>
# See <https://httpd.apache.org/docs/2.4/en/mod/core.html#loglevel>
LogLevel debug
# where Apache2::API can be found
PerlSwitches -I@ServerRoot@/lib
PerlSwitches -I@ServerRoot@/../lib
PerlSwitches -I@ServerRoot@/..

t/lib/Test/Apache2/API.pm  view on Meta::CPAN

    use Apache::Test;
    use Apache::TestRequest;
    use HTTP::Request;

    my $hostport = Apache::TestRequest::hostport( $config ) || '';
    my( $host, $port ) = split( ':', ( $hostport ) );
    my $mp_host = 'www.example.org';
    Apache::TestRequest::user_agent(reset => 1, keep_alive => 1 );
    my $ua = Apache::TestRequest->new;
    # To get the fingerprint for the certificate in ./t/server.crt, do:
    # echo "sha1\$$(openssl x509 -noout -in ./t/server.crt -fingerprint -sha1|perl -pE 's/^.*Fingerprint=|(\w{2})(?:\:?|$)/$1/g')"
    $ua->ssl_opts(
        # SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, 
        # SSL_verify_mode => 0x00
        # verify_hostname => 0,
        SSL_fingerprint => 'sha1$DEE8650E44870896E821AAE4A5A24382174D100E',
        # SSL_version     => 'SSLv3',
        # SSL_verfifycn_name => 'localhost',
    );
    my $req = HTTP::Request->new( 'GET' => "${proto}://${hostport}/tests/api/some_method" );
    my $resp = $ua->request( $req );
    is( $resp->code, Apache2::Const::HTTP_OK, 'some test name' );

t/lib/Test/Apache2/API/Request.pm  view on Meta::CPAN

Test::Apache2::API::Request - Apache2::API::Request Testing Class

=head1 SYNOPSIS

    my $hostport = Apache::TestRequest::hostport( $config ) || '';
    my( $host, $port ) = split( ':', ( $hostport ) );
    my $mp_host = 'www.example.org';
    Apache::TestRequest::user_agent(reset => 1, keep_alive => 1 );
    my $ua = Apache::TestRequest->new;
    # To get the fingerprint for the certificate in ./t/server.crt, do:
    # echo "sha1\$$(openssl x509 -noout -in ./t/server.crt -fingerprint -sha1|perl -pE 's/^.*Fingerprint=|(\w{2})(?:\:?|$)/$1/g')"
    $ua->ssl_opts(
        # SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, 
        # SSL_verify_mode => 0x00
        # verify_hostname => 0,
        SSL_fingerprint => 'sha1$DEE8650E44870896E821AAE4A5A24382174D100E',
        # SSL_version     => 'SSLv3',
        # SSL_verfifycn_name => 'localhost',
    );
    my $req = HTTP::Request->new( 'GET' => "${proto}://${hostport}/tests/request/some_method" );
    my $resp = $ua->request( $req );
    is( $resp->code, Apache2::Const::HTTP_OK, 'some test name' );

t/lib/Test/Apache2/API/Response.pm  view on Meta::CPAN

Test::Apache2::API::Response - Apache2::API::Response Testing Class

=head1 SYNOPSIS

    my $hostport = Apache::TestRequest::hostport( $config ) || '';
    my( $host, $port ) = split( ':', ( $hostport ) );
    my $mp_host = 'www.example.org';
    Apache::TestRequest::user_agent(reset => 1, keep_alive => 1 );
    my $ua = Apache::TestRequest->new;
    # To get the fingerprint for the certificate in ./t/server.crt, do:
    # echo "sha1\$$(openssl x509 -noout -in ./t/server.crt -fingerprint -sha1|perl -pE 's/^.*Fingerprint=|(\w{2})(?:\:?|$)/$1/g')"
    $ua->ssl_opts(
        # SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, 
        # SSL_verify_mode => 0x00
        # verify_hostname => 0,
        SSL_fingerprint => 'sha1$DEE8650E44870896E821AAE4A5A24382174D100E',
        # SSL_version     => 'SSLv3',
        # SSL_verfifycn_name => 'localhost',
    );
    my $req = HTTP::Request->new( 'GET' => "${proto}://${hostport}/tests/response/some_method" );
    my $resp = $ua->request( $req );
    is( $resp->code, Apache2::Const::HTTP_OK, 'some test name' );



( run in 1.440 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )