diff --git a/Makefile.am b/Makefile.am index 05db79940a62e35893896fcffe1330b7d20ebf78..7667f228672cf1d86875d5846cec5cc8159dfba8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,5 +17,4 @@ EXTRA_DIST = \ README.md \ CHANGES.md \ t/edugain.xml \ - t/manager.conf \ $(TESTS) diff --git a/t/cgi.t b/t/cgi.t index 9b732d4f53f745a0e5740539a9f1636bf3ae46d6..e903072c1177239232384b40fd32e99c3036b5d4 100755 --- a/t/cgi.t +++ b/t/cgi.t @@ -8,18 +8,44 @@ use File::Temp; use IPC::Run qw(run); use Test::More; -plan tests => 4; +plan tests => 5; -$ENV{ACCOUNTMANAGER_CONFIG} = 't/manager.conf'; +my $log = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); +diag("log file: $log") if $ENV{TEST_DEBUG}; -my $has_database = - $ENV{TEST_DB_TYPE} && - $ENV{TEST_DB_HOST} && - $ENV{TEST_DB_NAME} && - $ENV{TEST_DB_USER} && - $ENV{TEST_DB_PASSWORD}; +my $config = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); +print {$config} <<EOF; +[setup] +templates_dir = templates -subtest start_page => sub { +[federations] +edugain = t/edugain.xml + +[app] +url = https://my.fqdn/accountmanager +support_email = support\@my.fqdn + +[logger] +file = $log +level = debug + +[mailer] + +[idp] + +[database] +type = mysql +host = localhost +name = account_manager +username = user +password = password +EOF +$config->flush(); +diag("test configuration: $config") if $ENV{TEST_DEBUG}; + +$ENV{ACCOUNTMANAGER_CONFIG} = $config; + +subtest "index page" => sub { plan tests => 4; @@ -27,10 +53,9 @@ subtest start_page => sub { local $ENV{QUERY_STRING} = ''; my ($out, $err, $rc) = run_executable('access-check-manager.cgi'); - diag($out) if $ENV{TEST_DEBUG}; like( $out, - qr{^Content-Type: text/html; charset=utf8\r\n\r\n}, + qr{^Content-Type: text/html; charset=utf8\r\n\r\n}m, 'HTTP headers' ); like( @@ -40,24 +65,49 @@ subtest start_page => sub { ); like( $out, - qr{<a href="\?action=select_sp" class="button">Get started</a>}, + qr{<a href="\?action=start" class="button">Get started</a>}, 'start button' ); is($err, '', 'empty stderr'); }; -subtest sp_selection_page => sub { +subtest "SP selection page, implicit federation selection" => sub { + + plan tests => 4; + + local $ENV{REQUEST_METHOD} = 'GET'; + local $ENV{QUERY_STRING} = 'action=start'; + + my ($out, $err, $rc) = run_executable('access-check-manager.cgi'); + like( + $out, + qr{^Content-Type: text/html; charset=utf8\r\n\r\n}m, + 'HTTP headers' + ); + like( + $out, + qr{<title>eduGAIN Access Check</title>}, + 'page title' + ); + like( + $out, + qr{<select id="entityid" name="entityid" class="required">}, + 'page content contains SP list' + ); + is($err, '', 'empty stderr'); +}; + +subtest "SP selection page, explicit federation selection" => sub { plan tests => 4; local $ENV{REQUEST_METHOD} = 'GET'; - local $ENV{QUERY_STRING} = 'action=select_sp'; + local $ENV{QUERY_STRING} = 'action=select_sp&federation=edugain'; my ($out, $err, $rc) = run_executable('access-check-manager.cgi'); - diag($out) if $ENV{TEST_DEBUG}; like( $out, - qr{^Content-Type: text/html; charset=utf8\r\n\r\n}, + qr{^Content-Type: text/html; charset=utf8\r\n\r\n}m, 'HTTP headers' ); like( @@ -73,24 +123,23 @@ subtest sp_selection_page => sub { is($err, '', 'empty stderr'); }; -subtest email_selection_page_missing_parameter => sub { +subtest "email selection page, missing entityid parameter" => sub { plan tests => 4; local $ENV{REQUEST_METHOD} = 'GET'; - local $ENV{QUERY_STRING} = 'action=select_email'; + local $ENV{QUERY_STRING} = 'action=select_email&federation=edugain'; my ($out, $err, $rc) = run_executable('access-check-manager.cgi'); - diag($out) if $ENV{TEST_DEBUG}; like( $out, - qr{^Content-Type: text/html; charset=utf8\r\n\r\n}, + qr{^Content-Type: text/html; charset=utf8\r\n\r\n}m, 'HTTP headers' ); - unlike( + like( $out, qr{<title>eduGAIN Access Check</title>}, - 'no page title' + 'page title' ); like( $out, @@ -100,24 +149,23 @@ subtest email_selection_page_missing_parameter => sub { is($err, '', 'empty stderr'); }; -subtest email_selection_page_wrong_parameter => sub { +subtest "email selection page, invalid entityid parameter" => sub { plan tests => 4; local $ENV{REQUEST_METHOD} = 'GET'; - local $ENV{QUERY_STRING} = 'action=select_email&entityid=foo'; + local $ENV{QUERY_STRING} = 'action=select_email&federation=edugain&entityid=foo'; my ($out, $err, $rc) = run_executable('access-check-manager.cgi'); - diag($out) if $ENV{TEST_DEBUG}; like( $out, - qr{^Content-Type: text/html; charset=utf8\r\n\r\n}, + qr{^Content-Type: text/html; charset=utf8\r\n\r\n}m, 'HTTP headers' ); - unlike( + like( $out, qr{<title>eduGAIN Access Check</title>}, - 'no page title' + 'page title' ); like( $out, diff --git a/t/manager.conf b/t/manager.conf deleted file mode 100755 index c1a031e1b4d89deb8487d14075edefe53529ace9..0000000000000000000000000000000000000000 --- a/t/manager.conf +++ /dev/null @@ -1,23 +0,0 @@ -[setup] -templates_dir = templates -federation_metadata_file = t/edugain.xml - -[app] -url = https://my.fqdn/accountmanager -support_email = support@my.fqdn - -[logger] -file = /dev/null -level = debug - -[mailer] -sendmail_path = /bin/true - -[database] -type = mysql -host = localhost -name = account_manager -user = user -password = password - -[idp]