diff --git a/t/account-manager.t b/t/account-manager.t index 5e414c11f3f3df9cb58d44617b2894ac915ab379..4a8363fb0fdc2e62f3e150caedb5b110deb8b5b7 100755 --- a/t/account-manager.t +++ b/t/account-manager.t @@ -38,9 +38,18 @@ SKIP: { $ENV{TEST_DB_USER} && $ENV{TEST_DB_PASSWORD}; - my $configuration = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); - print {$configuration} <<EOF; + my $config_file = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); + my $accounts_file = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); + print {$config_file} <<EOF; tokens_validity_period = 2 +templates_dir = templates + +[idp] +accounts_file = $accounts_file +scope = localhost + +[service] +account_validity_period = 2 [database] type = $ENV{TEST_DB_TYPE} @@ -49,30 +58,46 @@ name = $ENV{TEST_DB_NAME} user = $ENV{TEST_DB_USER} password = $ENV{TEST_DB_PASSWORD} EOF + $config_file->flush(); # reset database content - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_accounts --delete'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_accounts --delete" + ); ok($rc == 0, 'delete accounts exit status'); is($err, '', 'delete accounts stderr output'); - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_tokens --delete'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_tokens --delete" + ); ok($rc == 0, 'delete tokens exit status'); is($err, '', 'delete tokens stderr output'); - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_services --delete'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_services --delete" + ); ok($rc == 0, 'delete services exit status'); is($err, '', 'delete services stderr output'); # accounts # initial list - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_accounts'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_accounts" + ); ok($rc == 0, 'list accounts exit status'); is($out, "No matching test account in DB\n", 'list accounts stdin output'); is($err, '', 'list accounts stderr output'); # creation failure - ($out, $err, $rc) = run_executable('account-manager.pl', 'add_account'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file add_account" + ); ok($rc == 2, 'add account without mandatory option exit status'); is($out, '', 'add account without mandatory option stdin output'); like( @@ -82,13 +107,19 @@ EOF ); # creation success - ($out, $err, $rc) = run_executable('account-manager.pl', 'add_account --profile foo --sp_entityid bar'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file add_account --profile foo --sp_entityid bar" + ); ok($rc == 0, 'add account with mandatory option exit status'); like($out, qr/Account created/, 'add account with mandatory option stdin output'); is($err, '', 'add account with mandatory option stderr output'); # final list - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_accounts'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_accounts" + ); ok($rc == 0, 'list accounts exit status'); like($out, qr/Account ID=\d+; password_hash=/, 'list accounts stdin output'); is($err, '', 'list accounts stderr output'); @@ -96,13 +127,19 @@ EOF # services # initial list - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_services'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_services" + ); ok($rc == 0, 'list services exit status'); is($out, "No service provider in DB\n", 'list services stdin output'); is($err, '', 'list services stderr output'); # creation failure - ($out, $err, $rc) = run_executable('account-manager.pl', 'add_service'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file add_service" + ); ok($rc == 2, 'add service without mandatory option exit status'); is($out, '', 'add service without mandatory option stdin output'); like( @@ -112,13 +149,19 @@ EOF ); # creation success - ($out, $err, $rc) = run_executable('account-manager.pl', 'add_service --sp_entityid bar --contacts joe,bob'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file add_service --sp_entityid bar --contacts joe,bob" + ); ok($rc == 0, 'add service with mandatory option exit status'); like($out, qr/Service Provider created/, 'add service with mandatory option stdin output'); is($err, '', 'add service with mandatory option stderr output'); # final list - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_services'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_services" + ); ok($rc == 0, 'list services exit status'); like($out, qr/Service ID=\d+; entityid=bar; displayname=; contacts=joe,bob/, 'list services stdin output'); is($err, '', 'list services stderr output'); @@ -126,13 +169,19 @@ EOF # tokens # initial list - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_tokens'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_tokens" + ); ok($rc == 0, 'list tokens exit status'); is($out, "No corresponding token found in DB\n", 'list tokens stdin output'); is($err, '', 'list tokens stderr output'); # creation failure - ($out, $err, $rc) = run_executable('account-manager.pl', 'add_token'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file add_token" + ); ok($rc == 2, 'add token without mandatory option exit status'); is($out, '', 'add token without mandatory option stdin output'); like( @@ -142,13 +191,19 @@ EOF ); # creation success - ($out, $err, $rc) = run_executable('account-manager.pl', 'add_token --sp_entityid bar --email_address joe'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file add_token --sp_entityid bar --email_address joe" + ); ok($rc == 0, 'add token with mandatory option exit status'); like($out, qr/Authentication token created/, 'add token with mandatory option stdin output'); is($err, '', 'add token with mandatory option stderr output'); # final list - ($out, $err, $rc) = run_executable('account-manager.pl', 'list_tokens'); + ($out, $err, $rc) = run_executable( + 'account-manager.pl', + "--config $config_file list_tokens" + ); ok($rc == 0, 'list tokens exit status'); like($out, qr/Token ID=\d+; token=\w+; email_address=joe; sp_entityid=bar/, 'list tokens stdin output'); is($err, '', 'list tokens stderr output');