Skip to content
Snippets Groups Projects
cgi.t 4.92 KiB
#!/usr/bin/perl

use strict;
use warnings;

use feature qw(state);

use English qw(-no_match_vars);
use File::Temp;
use HTML::Tidy5;
use IPC::Run qw(run);
use Test::HTML::Tidy5 qw();
use Test::More;
use Test::Mojo::WithRoles 'SubmitForm';

plan(skip_all => 'live database required') unless
    $ENV{TEST_DB_HOST} &&
    $ENV{TEST_DB_NAME} &&
    $ENV{TEST_DB_TYPE} &&
    $ENV{TEST_DB_USERNAME} &&
    $ENV{TEST_DB_PASSWORD};

plan tests => 4;

sub named_subtest {
    my ($name, $code, @args) = @_;

    my $tb = Test::More->builder();
    return $tb->subtest($name, $code, @args, $name);
}

sub setup {
    my %args = @_;

    my $name = $args{name};
    my $host = $args{host};
    my $type = $args{type};
    my $username = $args{username};
    my $password = $args{password};

    system("mysqladmin --host=$host --user=$username --password=$password --force drop $name >/dev/null");
    system("mysqladmin --host=$host --user=$username --password=$password create $name >/dev/null") == 0
        or die "can't run mysqladmin: $CHILD_ERROR\n";
    system("mysql --host=$host --user=$username --password=$password $name < conf/manager.sql") == 0
        or die "can't run mysql: $CHILD_ERROR\n";

    my $temp_dir = File::Temp->newdir(CLEANUP => $ENV{TEST_DEBUG} ? 0 : 1);
    diag("temp dir: $temp_dir") if $ENV{TEST_DEBUG};

    my $log_file  = sprintf("%s/test.log", $temp_dir);
    my $conf_file = sprintf("%s/test.conf", $temp_dir);

    open(my $handle, '>', $conf_file);
    print {$handle} <<EOF;
[setup]
templates_theme = edugain

[federations]
edugain = t/edugain.xml

[app]
url = https://my.fqdn/accountmanager
support_email = support\@my.fqdn
name = eduGAIN Access Check

[logger]
file = $log_file
level = debug

[mailer]