App-CamelPKI

 view release on metacpan or  search on metacpan

t/lib/App/CamelPKI/Test.pm  view on Meta::CPAN

    my $asn = Convert::ASN1->new;
    $asn->prepare(x509_schema());
    die $asn->error if $asn->error;

    my $retval = $asn->find($name);
    die "$name not found in X509 schema" if ! defined $retval;
    return $retval;
}

=item I<server_start>

Start the Catalyst server on the port number specified in C<camel_pki.yml>
(and readable in L</server_port>), do nothing if already started.

=cut

sub server_start {
    system("./script/start_stop_camel_pki.pl", "start");
    die if $?;
}

=item I<server_stop>

Stop the Catalyst server, do nothing if already stopped.

=cut

sub server_stop {
    system("./script/start_stop_camel_pki.pl", "stop");
    die if $?;
}

=item I<server_port>

Returns the port number on which the Catalyst server is (supposed) to
be running.

=cut

sub server_port {
    require App::CamelPKI;
    return App::CamelPKI->model("WebServer")->apache->https_port;
}

=item I<create_camel_pki_conf_php()>

Creates a file named C<t/php/tmp/camel_pki_conf.inc.php> which contains
PHP declarations for the host name and port number of the server, and
the administrator's certficate and private key, to be used by the PHP
tests.

=cut

sub create_camel_pki_conf_php {
    require App::CamelPKI;
    my $webserver = App::CamelPKI->model("WebServer")->apache;
    my $host = $webserver->certificate->get_subject_CN();
    my $port = $webserver->https_port();

    my ($admincert, $adminkey) = App::CamelPKI->model("CA")
        ->make_admin_credentials;

    my $admin_key_pem = $adminkey->serialize;
    my $admin_cert_pem = $admincert->serialize;
	#TODO créer le répertoire si il existe pas !!
	if (! -d "t/php/tmp"){
		 mkdir ("t/php/tmp") or die "Could not create t/php/tmp directory. Tests will fail.";
	}
    write_file("t/php/tmp/camel_pki_conf.inc.php", <<"CONF_DEFINES");
<?php

/* Camel-PKI test configuration file - auto generated. */

function camel_pki_https_host() { return "$host"; }
function camel_pki_https_port() { return $port; }
function camel_pki_key_pem() { return "$admin_key_pem"; }
function camel_pki_certificate_pem() { return "$admin_cert_pem"; }

?>
CONF_DEFINES

    return;
}

=item I<is_php_cli_present()>

Returns true if the php executable (php-cli) is found on the system using File::Which.
It searches for exectables named "php" or "php5".

=cut

sub is_php_cli_present(){
	my ($php) = (File::Which::which("php"), File::Which::which("php5"));
	if ($php){
		my @mods = `$php -m`;
		foreach(@mods){
			$_ =~ s/\n//g;
			return 1 if $_ =~ /curl/;
		}
	}
	return 0;
}

=item I<run_php($script)>

=item I<run_php_script($path)>

Run the script, either in its patch ($path) or in integral phat ($script),
and returns STDERR and STDOUT combined in one unique string. The command
line executrable C<php> (or C<php4>) is used. If $path a file name, the
path C<t/php> is added just before.

Note that an ad-hoc C<php.ini> script is needed; it's embeded in Camel-PKI
in C<t/php/php-json.ini>.

=back

=back

=cut



( run in 1.224 second using v1.01-cache-2.11-cpan-d8267643d1d )