Skip to content
Snippets Groups Projects
account-manager.cgi.t 1.68 KiB
Newer Older
Guillaume ROUSSE's avatar
Guillaume ROUSSE committed
#!/usr/bin/perl

use strict;
use warnings;

use English qw(-no_match_vars);
use File::Temp;
use IPC::Run qw(run);
use Test::More;

plan tests => 2;

$ENV{ACCOUNTMANAGER_CONFIG} = 't/manager.conf';

subtest start_page => sub {

    plan tests => 4;

    local $ENV{REQUEST_METHOD} = 'GET';
    local $ENV{QUERY_STRING}   = '';

    my ($out, $err, $rc) = run_executable('account-manager.cgi');
    diag($out) if $ENV{TEST_DEBUG};
    like(
        $out,
        qr{^Content-Type: text/html\n\n},
        'HTTP headers'
    );
    like(
        $out,
        qr{<title>eduGAIN Access Check</title>},
        'page title'
    );
    like(
        $out,
        qr{<button id="start_testing">Go on testing the service</button>},
        'start button'
    );
    is($err, '', 'empty stderr');
};

subtest sp_selection_page => sub {

    plan tests => 4;

    local $ENV{REQUEST_METHOD} = 'GET';
    local $ENV{QUERY_STRING}   = 'action=account_wizard';

    my ($out, $err, $rc) = run_executable('account-manager.cgi');
    diag($out) if $ENV{TEST_DEBUG};
    like(
        $out,
        qr{^Content-Type: text/html\n\n},
        'HTTP headers'
    );
    like(
        $out,
        qr{<title>eduGAIN Access Check - Select your Service Provider</title>},
        'page title'
    );
    like(
        $out,
        qr{<select id="sp_entityid" name="sp_entityid" class="required">},
        'selection list'
    );
    is($err, '', 'empty stderr');
};

sub run_executable {
    my ($executable, $args) = @_;

    my @args = $args ? split(/\s+/, $args) : ();
    run(
        [ $EXECUTABLE_NAME, '-I', 'lib', 'bin/' . $executable, @args ],
        \my ($in, $out, $err)
    );
    return ($out, $err, $CHILD_ERROR >> 8);
}