Skip to content
Snippets Groups Projects
Commit 9b452738 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

add a bunch of live object creation tests

parent 2803a3da
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,11 @@ use strict;
use warnings;
use English qw(-no_match_vars);
use File::Temp;
use IPC::Run qw(run);
use Test::More;
plan tests => 6;
plan tests => 48;
my ($out, $err, $rc);
......@@ -29,6 +30,128 @@ like(
);
is($out, '', 'no action stdout');
SKIP: {
skip 'live database required', 15 unless
$ENV{TEST_DB_TYPE} &&
$ENV{TEST_DB_HOST} &&
$ENV{TEST_DB_NAME} &&
$ENV{TEST_DB_USER} &&
$ENV{TEST_DB_PASSWORD};
my $configuration = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
print {$configuration} <<EOF;
[database]
type = $ENV{TEST_DB_TYPE}
host = $ENV{TEST_DB_HOST}
name = $ENV{TEST_DB_NAME}
user = $ENV{TEST_DB_USER}
password = $ENV{TEST_DB_PASSWORD}
EOF
# reset database content
($out, $err, $rc) = run_executable('account-manager.pl', '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');
ok($rc == 0, 'delete tokens exit status');
is($err, '', 'delete tokens stderr output');
($out, $err, $rc) = run_executable('account-manager.pl', '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');
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');
ok($rc == 2, 'add account without mandatory option exit status');
is($out, '', 'add account without mandatory option stdin output');
like(
$err,
qr/missing profile option, aborting/,
'add account without mandatory option stderr output'
);
# creation success
($out, $err, $rc) = run_executable('account-manager.pl', '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');
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');
# services
# initial list
($out, $err, $rc) = run_executable('account-manager.pl', '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');
ok($rc == 2, 'add service without mandatory option exit status');
is($out, '', 'add service without mandatory option stdin output');
like(
$err,
qr/missing sp_entityid option, aborting/,
'add service without mandatory option stderr output'
);
# creation success
($out, $err, $rc) = run_executable('account-manager.pl', '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');
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');
# tokens
# initial list
($out, $err, $rc) = run_executable('account-manager.pl', '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');
ok($rc == 2, 'add token without mandatory option exit status');
is($out, '', 'add token without mandatory option stdin output');
like(
$err,
qr/missing email_address option, aborting/,
'add token without mandatory option stderr output'
);
# creation success
($out, $err, $rc) = run_executable('account-manager.pl', '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');
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');
}
sub run_executable {
my ($executable, $args) = @_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment