| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# myproxy test script |
| 4 |
# written by Jim Basney <[email protected]> |
| 5 |
|
| 6 |
# Requires a valid proxy credential with lifetime of atleast 3 hours. |
| 7 |
# |
| 8 |
# Test cases are: |
| 9 |
# 1. Store a credential on master (myproxy-init). |
| 10 |
# 2. Get info on the stored credential (myproxy-info). |
| 11 |
# 3. Retrieve stored credential from master (myproxy-get-delegation). |
| 12 |
# 4. Replicate to slaves (myproxy-replicate). |
| 13 |
# 5. Retrieve stored credential from slave (myproxy-get-delegation). |
| 14 |
# 6. Change passphrase on master (myproxy-change-pass-phrase). |
| 15 |
# 7. Retrieve from master with new passphrase. |
| 16 |
# 8. Replicate to slaves (myproxy-replicate). |
| 17 |
# 9. Remove credential from repository (myproxy-destroy). |
| 18 |
# 10. Verify credential is removed from master(myproxy_info). |
| 19 |
# 11. Replicate to slaves (myproxy-replicate). |
| 20 |
# 12. Verify credential is removed from slave(myproxy_info). |
| 21 |
# |
| 22 |
# 13. Store credential (myproxy-store -v -t 1) |
| 23 |
# 14. Get info on the stored credential (myproxy-info) |
| 24 |
# 15. Create proxy from stored credential (myproxy-get-delegation). |
| 25 |
# 16. Replicate to slaves (myproxy-replicate). |
| 26 |
# 17. Retrieve stored credential from master (myproxy-retrieve) |
| 27 |
# 18. Retrieve stored credential from slave (myproxy-retrieve) |
| 28 |
# |
| 29 |
# Test server failure. |
| 30 |
# |
| 31 |
# 20. Store a credential (myproxy-store -v -t 1) |
| 32 |
# 21. Shutdown one slave server and replicate (myproxy-replicate) |
| 33 |
# Should get one failure: STATUS: 256 |
| 34 |
# Unable to connect to 141.142.96.61:60503 |
| 35 |
# .myproxy_replicate and .myproxy_deleted should not update |
| 36 |
# 22. Restart slave server and and replicate (myproxy-replicate) |
| 37 |
# 23. Shutdown one slave server and destroy cred (myproxy-destroy) |
| 38 |
# Should get one failure: STATUS: 256 |
| 39 |
# error in myproxy_init_client(): Unable to connect to 141.142.96.61:60503 |
| 40 |
# .myproxy_replicate and .myproxy_deleted should not update |
| 41 |
# 24. Restart slave server and and replicate (myproxy-replicate) |
| 42 |
# 25. Store a credential (myproxy-store -v -t 1) |
| 43 |
# 26. Shutdown one slave server and replicate (myproxy-replicate) |
| 44 |
# Should get one failure: STATUS: 256 |
| 45 |
# Unable to connect to 141.142.96.61:60503 |
| 46 |
# .myproxy_replicate and .myproxy_deleted should not update |
| 47 |
# 27. Restart slave server and destroy cred (myproxy-destroy) |
| 48 |
|
| 49 |
use File::Temp qw(tempdir); |
| 50 |
use File::Copy; |
| 51 |
use IPC::Open3; |
| 52 |
use Socket; |
| 53 |
|
| 54 |
$tmpdir = tempdir(CLEANUP => 1); |
| 55 |
|
| 56 |
$PROXYBITS = "-bits 2048"; |
| 57 |
|
| 58 |
# |
| 59 |
# handle cmdline options |
| 60 |
# |
| 61 |
$usage = "usage: myproxy-test-replicate [-help] [-verbose] [-keepfiles]\n"; |
| 62 |
$verbose = 0; |
| 63 |
$cleanupfiles = 1; |
| 64 |
while (($arg = shift @ARGV)) { |
| 65 |
if ($arg eq "-h" || $arg eq "-help") { |
| 66 |
print STDERR $usage; |
| 67 |
exit 1; |
| 68 |
} elsif ($arg eq "-v" || $arg eq "-verbose") { |
| 69 |
$verbose = 1; |
| 70 |
} elsif ($arg eq "-k" || $arg eq "-keepfiles") { |
| 71 |
$cleanupfiles = 0; |
| 72 |
} else { |
| 73 |
print STDERR $usage; |
| 74 |
exit 1; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
# Create a private CA and proxy locally and use them. |
| 79 |
my $privcerts = "$tmpdir/privcerts.$$" ; |
| 80 |
print STDERR "creating a CA in ", $privcerts, "\n" if ($verbose); |
| 81 |
mkdir("$privcerts") || |
| 82 |
die("failed to create $privcerts directory, stopped") ; |
| 83 |
open(SSLCNF, ">$privcerts/openssl.cnf") || |
| 84 |
die("failed to create $privcerts/openssl.cnf: $!"); |
| 85 |
print SSLCNF <<EOF; |
| 86 |
[ ca ] |
| 87 |
default_ca = CA_default # The default ca section |
| 88 |
|
| 89 |
[ CA_default ] |
| 90 |
dir = $privcerts # top dir |
| 91 |
database = $privcerts/index.txt # index file. |
| 92 |
new_certs_dir = $privcerts/ # new certs dir |
| 93 |
|
| 94 |
certificate = $privcerts/cacert.pem # The CA cert |
| 95 |
serial = $privcerts/serial # serial no file |
| 96 |
private_key = $privcerts/cakey.pem # CA private key |
| 97 |
RANDFILE = $privcerts/.rand # random number file |
| 98 |
default_md = sha256 # md to use |
| 99 |
[ req ] |
| 100 |
distinguished_name = req_distinguished_name |
| 101 |
|
| 102 |
[ req_distinguished_name ] |
| 103 |
commonName = Common Name (hostname, IP, or your name) |
| 104 |
commonName_max = 64 |
| 105 |
|
| 106 |
[ v3_ca ] |
| 107 |
basicConstraints = CA:TRUE |
| 108 |
subjectKeyIdentifier = hash |
| 109 |
authorityKeyIdentifier = keyid:always,issuer:always |
| 110 |
|
| 111 |
[ policy_anything ] |
| 112 |
commonName = supplied |
| 113 |
|
| 114 |
EOF |
| 115 |
|
| 116 |
close(SSLCNF); |
| 117 |
open(CAINDEX,">$privcerts/index.txt") || |
| 118 |
die("failed to create $privcerts/index.txt"); |
| 119 |
close(CAINDEX); |
| 120 |
open(SERIAL,">$privcerts/serial") || |
| 121 |
die("failed to create $privcerts/serial"); |
| 122 |
print SERIAL "01\n"; |
| 123 |
close(SERIAL); |
| 124 |
&runcmd("openssl req -batch -subj '/CN=MyProxy Test CA' -config $privcerts/openssl.cnf -new -x509 -extensions v3_ca -nodes -keyout $privcerts/cakey.pem -out $privcerts/cacert.pem -days 30"); |
| 125 |
|
| 126 |
chomp($hash = `openssl x509 -in $privcerts/cacert.pem -hash -noout`) ; |
| 127 |
mkdir("$privcerts/grid-security") || |
| 128 |
die("failed to create $privcerts/grid-security"); |
| 129 |
copy("$privcerts/cacert.pem","$privcerts/grid-security/$hash.0") || |
| 130 |
die("failed to copy $privcerts/cacert.pem","$privcerts/grid-security/$hash.0"); |
| 131 |
open(POLICY,">$privcerts/grid-security/$hash.signing_policy") || |
| 132 |
die("failed to create $privcerts/grid-security/$hash.signing_policy"); |
| 133 |
print POLICY "access_id_CA X509 '/CN=MyProxy Test CA'\n"; |
| 134 |
print POLICY "pos_rights globus CA:sign\n"; |
| 135 |
print POLICY "cond_subjects globus '\"/*\"'\n"; |
| 136 |
close(POLICY); |
| 137 |
print STDERR "creating a user certificate request ", $privcerts, "\n" if ($verbose); |
| 138 |
&runcmd("openssl req -batch -subj '/CN=MyProxy Test User' -config $privcerts/openssl.cnf -new -nodes -keyout $privcerts/userkey.pem -out $privcerts/usercert.csr -days 7") ; |
| 139 |
print STDERR "signing user certificate with by CA in ", $privcerts, "\n" if ($verbose); |
| 140 |
&runcmd("openssl ca -batch -days 7 -config $privcerts/openssl.cnf -policy policy_anything -out $privcerts/usercert.pem -infiles $privcerts/usercert.csr"); |
| 141 |
chmod(oct("0600"),"$privcerts/userkey.pem","$privcerts/usercert.pem") || |
| 142 |
die("failed to chmod $privcerts/userkey.pem or $privcerts/usercert.pem"); |
| 143 |
$ENV{'X509_USER_CERT'} = "$privcerts/usercert.pem" ; |
| 144 |
$ENV{'X509_USER_KEY'} = "$privcerts/userkey.pem" ; |
| 145 |
$ENV{'X509_CERT_DIR'} = "$privcerts/grid-security" ; |
| 146 |
print STDERR "generating a user proxy\n" if ($verbose); |
| 147 |
chomp($grid_proxy_init = `which grid-proxy-init 2>/dev/null`); |
| 148 |
die "grid-proxy-init not found, stopped" if (!(-x $grid_proxy_init)); |
| 149 |
&runcmd("$grid_proxy_init -debug $PROXYBITS"); |
| 150 |
#end of generatecerts. |
| 151 |
|
| 152 |
# |
| 153 |
# make sure I have a valid proxy |
| 154 |
# |
| 155 |
chomp($grid_proxy_init = `which grid-proxy-init 2>/dev/null`); |
| 156 |
die "grid-proxy-init not found, stopped" if (!(-x $grid_proxy_init)); |
| 157 |
chomp($grid_proxy_info = `which grid-proxy-info 2>/dev/null`); |
| 158 |
die "grid-proxy-info not found, stopped" if (!(-x $grid_proxy_info)); |
| 159 |
$timeleft = `$grid_proxy_info -timeleft 2>/dev/null`; |
| 160 |
if (!defined($timeleft) || $timeleft eq "" || ($timeleft < 60*60*3)) { |
| 161 |
&debug("Problem with proxy. Will try to create a new one."); |
| 162 |
`$grid_proxy_init -pwstdin </dev/null >/dev/null 2>&1`; |
| 163 |
$timeleft = `$grid_proxy_info -timeleft 2>/dev/null`; |
| 164 |
} |
| 165 |
die "grid-proxy-info failed, stopped" |
| 166 |
if (!defined($timeleft) || $timeleft eq ""); |
| 167 |
die "proxy expired, stopped" if ($timeleft < 60); |
| 168 |
die "proxy lifetime too short, stopped" if ($timeleft < 60*60*3); |
| 169 |
chomp($cert_subject = `$grid_proxy_info -identity`); |
| 170 |
die "grid-proxy-info -identity failed, stopped" |
| 171 |
if (!defined($cert_subject) || $cert_subject eq ""); |
| 172 |
|
| 173 |
# |
| 174 |
# check for the commands I want to run |
| 175 |
# |
| 176 |
chomp($myproxy_store = `which myproxy-store 2>/dev/null`); |
| 177 |
die "myproxy-store not in PATH, stopped" if (!(-x $myproxy_store)); |
| 178 |
chomp($myproxy_init = `which myproxy-init 2>/dev/null`); |
| 179 |
die "myproxy-init not in PATH, stopped" if (!(-x $myproxy_init)); |
| 180 |
chomp($myproxy_retrieve = `which myproxy-retrieve 2>/dev/null`); |
| 181 |
die "myproxy-retrieve not in PATH, stopped" if (!(-x $myproxy_retrieve)); |
| 182 |
chomp($myproxy_info = `which myproxy-info 2>/dev/null`); |
| 183 |
die "myproxy-info not in PATH, stopped" if (!(-x $myproxy_info)); |
| 184 |
chomp($myproxy_destroy = `which myproxy-destroy 2>/dev/null`); |
| 185 |
die "myproxy-destroy not in PATH, stopped" if (!(-x $myproxy_destroy)); |
| 186 |
chomp($myproxy_get = `which myproxy-get-delegation 2>/dev/null`); |
| 187 |
die "myproxy-get-delegation not in PATH, stopped" if (!(-x $myproxy_get)); |
| 188 |
chomp($myproxy_passwd = `which myproxy-change-pass-phrase 2>/dev/null`); |
| 189 |
die "myproxy-change-pass-phrase not in PATH, stopped" |
| 190 |
if (!(-x $myproxy_passwd)); |
| 191 |
|
| 192 |
# |
| 193 |
# setup environment variables |
| 194 |
# |
| 195 |
if (!defined($ENV{'X509_USER_PROXY'})) { |
| 196 |
$ENV{'X509_USER_PROXY'} = "/tmp/x509up_u$<"; |
| 197 |
} |
| 198 |
# make proxy from existing proxy, so we don't need to deal with long-term cred |
| 199 |
$ENV{'X509_USER_CERT'} = $ENV{'X509_USER_PROXY'}; |
| 200 |
$ENV{'X509_USER_KEY'} = $ENV{'X509_USER_PROXY'}; |
| 201 |
|
| 202 |
srand(time||$$); |
| 203 |
$passphrase = sprintf "%010d", int(rand(0x7fffffff)); |
| 204 |
|
| 205 |
my $mport = undef; |
| 206 |
my $s1port = undef; |
| 207 |
my $s2port = undef; |
| 208 |
my $s3port = undef; |
| 209 |
|
| 210 |
my $masterpid = undef; |
| 211 |
my $masterdir = undef; |
| 212 |
my $masterconf = undef; |
| 213 |
my $masterpidfile = undef; |
| 214 |
|
| 215 |
my $slconf = undef; |
| 216 |
|
| 217 |
my $sl1pid = undef; |
| 218 |
my $sl1dir = undef; |
| 219 |
my $sl1pidfile = undef; |
| 220 |
my $sl1portfile = undef; |
| 221 |
|
| 222 |
my $sl2pid = undef; |
| 223 |
my $sl2dir = undef; |
| 224 |
my $sl2pidfile = undef; |
| 225 |
my $sl2portfile = undef; |
| 226 |
|
| 227 |
my $sl3pid = undef; |
| 228 |
my $sl3dir = undef; |
| 229 |
my $sl3pidfile = undef; |
| 230 |
my $sl3portfile = undef; |
| 231 |
|
| 232 |
# |
| 233 |
# start servers |
| 234 |
# |
| 235 |
$ENV{'MYPROXY_SERVER'} = "localhost"; |
| 236 |
$ENV{'MYPROXY_SERVER_DN'} = $cert_subject; |
| 237 |
|
| 238 |
chomp($myproxy_server = `which myproxy-server 2>/dev/null`); |
| 239 |
die "myproxy-server not in PATH, stopped" if (!(-x $myproxy_server)); |
| 240 |
|
| 241 |
$slconf = "$tmpdir/myproxy-test.serverconf.sl.$$"; |
| 242 |
open(CONF, ">$slconf") || |
| 243 |
die "failed to open $slconf, stopped"; |
| 244 |
print CONF "accepted_credentials \"$ENV{MYPROXY_SERVER_DN}\"\n"; |
| 245 |
print CONF "authorized_retrievers \"*\"\n"; |
| 246 |
print CONF "default_retrievers \"*\"\n"; |
| 247 |
print CONF "authorized_renewers \"*\"\n"; |
| 248 |
print CONF "default_renewers \"none\"\n"; |
| 249 |
print CONF "authorized_key_retrievers \"*\"\n"; |
| 250 |
print CONF "default_key_retrievers \"*\"\n"; |
| 251 |
print CONF "allow_self_authorization true\n"; # temporary workaround |
| 252 |
close(CONF); |
| 253 |
|
| 254 |
$sl1dir = "$tmpdir/myproxy-test.serverdir.sl1.$$"; |
| 255 |
mkdir($sl1dir) || |
| 256 |
die "failed to create $sl1dir, stopped"; |
| 257 |
chmod(0700, $sl1dir) || |
| 258 |
die "failed to chmod $sl1dir, stopped"; |
| 259 |
$sl1pidfile = "$tmpdir/myproxy-test.serverpid.sl1.$$"; |
| 260 |
$sl1portfile = "$tmpdir/myproxy-test.serverport.sl1.$$"; |
| 261 |
$servercmd = "$myproxy_server -s $sl1dir -c $slconf"; |
| 262 |
$servercmd .= " -l $ENV{'MYPROXY_SERVER'} -p 0"; |
| 263 |
$servercmd .= " -P $sl1pidfile -z $sl1portfile"; |
| 264 |
&debug("running '$servercmd'"); |
| 265 |
`$servercmd`; |
| 266 |
sleep(2); # give server a chance to startup |
| 267 |
if (open SERVERPIDFILE, $sl1pidfile) { |
| 268 |
$sl1pid = <SERVERPIDFILE>; |
| 269 |
close SERVERPIDFILE; |
| 270 |
} |
| 271 |
if (!defined($sl1pid) || $sl1pid eq "") { |
| 272 |
print STDERR "failed to start slave 1:\n"; |
| 273 |
`$servercmd -d`; # show output on terminal |
| 274 |
&docleanup(); |
| 275 |
exit 1; |
| 276 |
} |
| 277 |
if (open SERVERPORTFILE, $sl1portfile) { |
| 278 |
chomp($s1port = <SERVERPORTFILE>); |
| 279 |
close SERVERPORTFILE; |
| 280 |
} |
| 281 |
|
| 282 |
$sl2dir = "$tmpdir/myproxy-test.serverdir.sl2.$$"; |
| 283 |
mkdir($sl2dir) || |
| 284 |
die "failed to create $sl2dir, stopped"; |
| 285 |
chmod(0700, $sl2dir) || |
| 286 |
die "failed to chmod $sl2dir, stopped"; |
| 287 |
$sl2pidfile = "$tmpdir/myproxy-test.serverpid.sl2.$$"; |
| 288 |
$sl2portfile = "$tmpdir/myproxy-test.serverport.sl2.$$"; |
| 289 |
$servercmd = "$myproxy_server -s $sl2dir -c $slconf"; |
| 290 |
$servercmd .= " -p 0 -P $sl2pidfile -z $sl2portfile"; |
| 291 |
&debug("running '$servercmd'"); |
| 292 |
`$servercmd`; |
| 293 |
sleep(2); # give server a chance to startup |
| 294 |
if (open SERVERPIDFILE, $sl2pidfile) { |
| 295 |
$sl2pid = <SERVERPIDFILE>; |
| 296 |
close SERVERPIDFILE; |
| 297 |
} |
| 298 |
if (!defined($sl2pid) || $sl2pid eq "") { |
| 299 |
print STDERR "failed to start slave 2:\n"; |
| 300 |
`$servercmd -d`; # show output on terminal |
| 301 |
&docleanup(); |
| 302 |
exit 1; |
| 303 |
} |
| 304 |
if (open SERVERPORTFILE, $sl2portfile) { |
| 305 |
chomp($s2port = <SERVERPORTFILE>); |
| 306 |
close SERVERPORTFILE; |
| 307 |
} |
| 308 |
|
| 309 |
start_sl3(); |
| 310 |
|
| 311 |
sub start_sl3 { |
| 312 |
$sl3dir = "$tmpdir/myproxy-test.serverdir.sl3.$$"; |
| 313 |
if( !(-d $sl3dir) ) { |
| 314 |
mkdir($sl3dir) || |
| 315 |
die "failed to create $sl3dir, stopped"; |
| 316 |
} |
| 317 |
chmod(0700, $sl3dir) || |
| 318 |
die "failed to chmod $sl3dir, stopped"; |
| 319 |
$sl3pidfile = "$tmpdir/myproxy-test.serverpid.sl3.$$"; |
| 320 |
$sl3portfile = "$tmpdir/myproxy-test.serverport.sl3.$$"; |
| 321 |
$servercmd = "$myproxy_server -s $sl3dir -c $slconf"; |
| 322 |
if (defined($s3port)) { |
| 323 |
$servercmd .= " -p $s3port -P $sl3pidfile"; |
| 324 |
} else { |
| 325 |
$servercmd .= " -p 0 -P $sl3pidfile -z $sl3portfile"; |
| 326 |
} |
| 327 |
&debug("running '$servercmd'"); |
| 328 |
`$servercmd`; |
| 329 |
sleep(2); # give server a chance to startup |
| 330 |
if (open SERVERPIDFILE, $sl3pidfile) { |
| 331 |
$sl3pid = <SERVERPIDFILE>; |
| 332 |
close SERVERPIDFILE; |
| 333 |
} |
| 334 |
if (!defined($sl3pid) || $sl3pid eq "") { |
| 335 |
print STDERR "failed to start slave 3:\n"; |
| 336 |
`$servercmd -d`; # show output on terminal |
| 337 |
&docleanup(); |
| 338 |
exit 1; |
| 339 |
} |
| 340 |
|
| 341 |
if (!defined($s3port)) { |
| 342 |
if (open SERVERPORTFILE, $sl3portfile) { |
| 343 |
chomp($s3port = <SERVERPORTFILE>); |
| 344 |
close SERVERPORTFILE; |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
$masterconf = "$tmpdir/myproxy-test.serverconf.master.$$"; |
| 350 |
open(CONF, ">$masterconf") || |
| 351 |
die "failed to open $masterconf, stopped"; |
| 352 |
print CONF "accepted_credentials \"*\"\n"; |
| 353 |
print CONF "authorized_retrievers \"*\"\n"; |
| 354 |
print CONF "default_retrievers \"*\"\n"; |
| 355 |
print CONF "authorized_renewers \"*\"\n"; |
| 356 |
print CONF "default_renewers \"none\"\n"; |
| 357 |
print CONF "authorized_key_retrievers \"*\"\n"; |
| 358 |
print CONF "default_key_retrievers \"*\"\n"; |
| 359 |
print CONF "allow_self_authorization true\n"; # temporary workaround |
| 360 |
print CONF "slave_servers localhost:$s1port;localhost:$s2port;localhost:$s3port"; |
| 361 |
close(CONF); |
| 362 |
|
| 363 |
$masterdir = "$tmpdir/myproxy-test.serverdir.master.$$"; |
| 364 |
mkdir($masterdir) || |
| 365 |
die "failed to create $masterdir, stopped"; |
| 366 |
chmod(0700, $masterdir) || |
| 367 |
die "failed to chmod $masterdir, stopped"; |
| 368 |
$masterpidfile = "$tmpdir/myproxy-test.serverpid.master.$$"; |
| 369 |
$masterportfile = "$tmpdir/myproxy-test.serverport.master.$$"; |
| 370 |
$servercmd = "$myproxy_server -s $masterdir -c $masterconf"; |
| 371 |
$servercmd .= " -p 0 -P $masterpidfile -z $masterportfile"; |
| 372 |
&debug("running '$servercmd'"); |
| 373 |
`$servercmd`; |
| 374 |
sleep(2); # give server a chance to startup |
| 375 |
if (open SERVERPIDFILE, $masterpidfile) { |
| 376 |
$masterpid = <SERVERPIDFILE>; |
| 377 |
close SERVERPIDFILE; |
| 378 |
} |
| 379 |
if (!defined($masterpid) || $masterpid eq "") { |
| 380 |
print STDERR "failed to start master:\n"; |
| 381 |
`$servercmd -d`; # show output on terminal |
| 382 |
&docleanup(); |
| 383 |
exit 1; |
| 384 |
} |
| 385 |
if (open SERVERPORTFILE, $masterportfile) { |
| 386 |
chomp($mport = <SERVERPORTFILE>); |
| 387 |
close SERVERPORTFILE; |
| 388 |
} |
| 389 |
|
| 390 |
# |
| 391 |
# BEGIN TESTS |
| 392 |
# |
| 393 |
$SUCCESSES = $FAILURES = 0; |
| 394 |
|
| 395 |
# commands to test: myproxy-init, myproxy-info, myproxy-destroy, |
| 396 |
# myproxy-get-delegation, and myproxy-change-pass-phrase |
| 397 |
|
| 398 |
## |
| 399 |
## Test 1 |
| 400 |
## |
| 401 |
($exitstatus, $output) = |
| 402 |
&runtest("myproxy-init -s localhost -p $mport -v -a -c 1 -t 1 -S -d -k \"test credential\"", |
| 403 |
$passphrase . "\n"); |
| 404 |
print "MyProxy Test 1 (store credential): "; |
| 405 |
if ($exitstatus == 0) { |
| 406 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 407 |
} else { |
| 408 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 409 |
} |
| 410 |
|
| 411 |
## |
| 412 |
## Test 2 |
| 413 |
## |
| 414 |
($exitstatus, $output) = &runtest("myproxy-info -s localhost -p $mport -v -d", undef); |
| 415 |
print "MyProxy Test 2 (get info for stored credential): "; |
| 416 |
if ($exitstatus == 0 && $output =~ /username/) { |
| 417 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 418 |
} else { |
| 419 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 420 |
} |
| 421 |
|
| 422 |
## |
| 423 |
## Test 3 |
| 424 |
## |
| 425 |
($exitstatus, $output) = |
| 426 |
&runtest("myproxy-get-delegation -s localhost -p $mport -t 1 -o $tmpdir/myproxy-test.$$ -v -S -d -k \"test credential\"", |
| 427 |
$passphrase . "\n"); |
| 428 |
print "MyProxy Test 3 (retrieve stored credential): "; |
| 429 |
if ($exitstatus == 0) { |
| 430 |
($exitstatus, $output) = |
| 431 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 432 |
} |
| 433 |
if ($exitstatus == 0) { |
| 434 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 435 |
} else { |
| 436 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 437 |
} |
| 438 |
|
| 439 |
## |
| 440 |
## Test 4 |
| 441 |
## |
| 442 |
($exitstatus, $output) = |
| 443 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 444 |
undef); |
| 445 |
print "MyProxy Test 4 (Replicate master server to all slaves): "; |
| 446 |
if ($exitstatus == 0) { |
| 447 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 448 |
} else { |
| 449 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 450 |
goto end_of_tests; |
| 451 |
} |
| 452 |
|
| 453 |
## |
| 454 |
## Test 5 |
| 455 |
## |
| 456 |
($exitstatus, $output) = |
| 457 |
&runtest("myproxy-get-delegation -s localhost -p $s1port -t 1 -o $tmpdir/myproxy-test.$$ -v -S -d -k \"test credential\"", |
| 458 |
$passphrase . "\n"); |
| 459 |
print "MyProxy Test 5 (retrieve stored credential from slave): "; |
| 460 |
if ($exitstatus == 0) { |
| 461 |
($exitstatus, $output) = |
| 462 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 463 |
} |
| 464 |
if ($exitstatus == 0) { |
| 465 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 466 |
} else { |
| 467 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 468 |
} |
| 469 |
|
| 470 |
## |
| 471 |
## Test 6 |
| 472 |
## |
| 473 |
$old_passphrase = $passphrase; |
| 474 |
$passphrase = sprintf "%010d", int(rand(0x7fffffff)); |
| 475 |
($exitstatus, $output) = |
| 476 |
&runtest("myproxy-change-pass-phrase -s localhost -p $mport -v -S -d -k \"test credential\"", |
| 477 |
"$old_passphrase\n$passphrase\n"); |
| 478 |
print "MyProxy Test 6 (change passphrase for credential): "; |
| 479 |
if ($exitstatus == 0 && $output =~ /Pass phrase changed/) { |
| 480 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 481 |
} else { |
| 482 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 483 |
} |
| 484 |
|
| 485 |
## |
| 486 |
## Test 7 |
| 487 |
## |
| 488 |
($exitstatus, $output) = |
| 489 |
&runtest("myproxy-get-delegation -s localhost -p $mport -t 1 -o $tmpdir/myproxy-test.$$ -v -S -d -k \"test credential\"", |
| 490 |
$passphrase . "\n"); |
| 491 |
print "MyProxy Test 7 (verify new passphrase): "; |
| 492 |
if ($exitstatus == 0) { |
| 493 |
($exitstatus, $output) = |
| 494 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 495 |
} |
| 496 |
if ($exitstatus == 0) { |
| 497 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 498 |
} else { |
| 499 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 500 |
} |
| 501 |
|
| 502 |
## |
| 503 |
## Test 8 |
| 504 |
## |
| 505 |
($exitstatus, $output) = |
| 506 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 507 |
undef); |
| 508 |
print "MyProxy Test 8 (Replicate master server to all slaves): "; |
| 509 |
if ($exitstatus == 0) { |
| 510 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 511 |
} else { |
| 512 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 513 |
} |
| 514 |
|
| 515 |
## |
| 516 |
## Test 9 |
| 517 |
## |
| 518 |
($exitstatus, $output) = |
| 519 |
&runtest("myproxy-get-delegation -s localhost -p $s2port -t 1 -o $tmpdir/myproxy-test.$$ -v -S -d -k \"test credential\"", |
| 520 |
$passphrase . "\n"); |
| 521 |
print "MyProxy Test 9 (verify new passphrase has been replicated to slaves): "; |
| 522 |
if ($exitstatus == 0) { |
| 523 |
($exitstatus, $output) = |
| 524 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 525 |
} |
| 526 |
if ($exitstatus == 0) { |
| 527 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 528 |
} else { |
| 529 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 530 |
} |
| 531 |
|
| 532 |
## |
| 533 |
## Test 10 |
| 534 |
## |
| 535 |
($exitstatus, $output) = |
| 536 |
&runtest("myproxy-get-delegation -s localhost -p $s3port -a \$X509_USER_PROXY -t 1 -o $tmpdir/myproxy-test.$$ -v -d -k \"test credential\"", undef); |
| 537 |
print "MyProxy Test 10 (verify default renewal policy on slave): "; |
| 538 |
if ($exitstatus != 0) { |
| 539 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 540 |
} else { |
| 541 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 542 |
} |
| 543 |
|
| 544 |
## |
| 545 |
## Test 11 |
| 546 |
## |
| 547 |
($exitstatus, $output) = |
| 548 |
&runtest("myproxy-destroy -s localhost -p $mport -v -d -k \"test credential\"", undef); |
| 549 |
print "MyProxy Test 11 (remove credential from master repository): "; |
| 550 |
if ($exitstatus == 0 && $output =~ /was successfully removed/) { |
| 551 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 552 |
} else { |
| 553 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 554 |
} |
| 555 |
|
| 556 |
## |
| 557 |
## Test 12 |
| 558 |
## |
| 559 |
($exitstatus, $output) = |
| 560 |
&runtest("myproxy-info -v -d", undef); |
| 561 |
print "MyProxy Test 12 (verify credentials are removed from master): "; |
| 562 |
if (!($output =~ /default credential/)) { |
| 563 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 564 |
} else { |
| 565 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 566 |
} |
| 567 |
|
| 568 |
## |
| 569 |
## Test 13 |
| 570 |
## |
| 571 |
($exitstatus, $output) = |
| 572 |
&runtest("myproxy-replicate -d -v -c $tmpdir/myproxy-test.serverconf.$mport.master.$$ -r $masterdir", |
| 573 |
undef); |
| 574 |
print "MyProxy Test 13 (Replicate destroy to all slaves): "; |
| 575 |
if ($exitstatus == 0) { |
| 576 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 577 |
} else { |
| 578 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 579 |
} |
| 580 |
|
| 581 |
## |
| 582 |
## Test 14 |
| 583 |
## |
| 584 |
($exitstatus, $output) = |
| 585 |
&runtest("myproxy-get-delegation -s localhost -p $s2port -t 1 -o $tmpdir/myproxy-test.$$ -v -S -d -k \"test credential\"", |
| 586 |
$passphrase . "\n"); |
| 587 |
print "MyProxy Test 14 (verify destroy has been replicated to slaves): "; |
| 588 |
if ($exitstatus != 0 && $output =~ /exist/) { |
| 589 |
($exitstatus, $output) = |
| 590 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 591 |
} |
| 592 |
if ($exitstatus == 0) { |
| 593 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 594 |
} else { |
| 595 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 596 |
} |
| 597 |
|
| 598 |
## |
| 599 |
## Test 15 |
| 600 |
## |
| 601 |
($exitstatus, $output) = |
| 602 |
&runtest("myproxy-init -s localhost -p $mport -v -R 'nobody' -k 'nobody' -c 1 -t 1 -d -S", |
| 603 |
$passphrase . "\n"); |
| 604 |
print "MyProxy Test 15 (store credentials with renewal policies): "; |
| 605 |
if ($exitstatus == 0) { |
| 606 |
($exitstatus, $output) = |
| 607 |
&runtest("myproxy-init -s localhost -p $mport -v -x -R '$cert_subject' -k 'mine' -c 1 -t 1 -d -S", |
| 608 |
$passphrase . "\n"); |
| 609 |
} |
| 610 |
if ($exitstatus == 0) { |
| 611 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 612 |
} else { |
| 613 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 614 |
} |
| 615 |
|
| 616 |
## |
| 617 |
## Test 16 |
| 618 |
## |
| 619 |
($exitstatus, $output) = &runtest("myproxy-info -s localhost -p $mport -v -d", undef); |
| 620 |
print "MyProxy Test 16 (get info for stored renewal credentials): "; |
| 621 |
if ($exitstatus == 0 && $output =~ /username/) { |
| 622 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 623 |
} else { |
| 624 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 625 |
} |
| 626 |
|
| 627 |
## |
| 628 |
## Test 17 |
| 629 |
## |
| 630 |
($exitstatus, $output) = |
| 631 |
&runtest("myproxy-get-delegation -s localhost -p $mport -k 'mine' -a $ENV{'X509_USER_PROXY'} -t 1 -o $tmpdir/myproxy-test.$$ -v -d", |
| 632 |
undef); |
| 633 |
print "MyProxy Test 17 (verify renewal policies): "; |
| 634 |
if ($exitstatus == 0) { |
| 635 |
($exitstatus, $output) = |
| 636 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 637 |
} |
| 638 |
if ($exitstatus == 0) { |
| 639 |
($exitstatus, $output) = |
| 640 |
&runtest("myproxy-get-delegation -s localhost -p $mport -k 'nobody' -a $ENV{'X509_USER_PROXY'} -t 1 -o $tmpdir/myproxy-test.$$ -v -d", |
| 641 |
undef); |
| 642 |
if ($exitstatus != 0) { |
| 643 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 644 |
} else { |
| 645 |
print "FAILED\n"; $FAILURES++; |
| 646 |
print STDERR "Shouldn't have allowed retrieval.\n"; |
| 647 |
print STDERR $output; |
| 648 |
} |
| 649 |
} else { |
| 650 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 651 |
} |
| 652 |
|
| 653 |
## |
| 654 |
## Test 18 |
| 655 |
## |
| 656 |
($exitstatus, $output) = |
| 657 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 658 |
undef); |
| 659 |
print "MyProxy Test 18 (Replicate to all slaves): "; |
| 660 |
if ($exitstatus == 0) { |
| 661 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 662 |
} else { |
| 663 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 664 |
} |
| 665 |
|
| 666 |
## |
| 667 |
## Test 19 |
| 668 |
## |
| 669 |
($exitstatus, $output) = |
| 670 |
&runtest("myproxy-get-delegation -s localhost -p $s1port -k 'mine' -a $ENV{'X509_USER_PROXY'} -t 1 -o $tmpdir/myproxy-test.$$ -v -d", |
| 671 |
undef); |
| 672 |
print "MyProxy Test 19 (verify renewal policies on slave): "; |
| 673 |
if ($exitstatus == 0) { |
| 674 |
($exitstatus, $output) = |
| 675 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 676 |
} |
| 677 |
if ($exitstatus == 0) { |
| 678 |
($exitstatus, $output) = |
| 679 |
&runtest("myproxy-get-delegation -s localhost -p $s1port -k 'nobody' -a $ENV{'X509_USER_PROXY'} -t 1 -o $tmpdir/myproxy-test.$$ -v -d", |
| 680 |
undef); |
| 681 |
if ($exitstatus != 0) { |
| 682 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 683 |
} else { |
| 684 |
print "FAILED\n"; $FAILURES++; |
| 685 |
print STDERR "Shouldn't have allowed retrieval.\n"; |
| 686 |
print STDERR $output; |
| 687 |
} |
| 688 |
} else { |
| 689 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 690 |
} |
| 691 |
|
| 692 |
&runtest("myproxy-destroy -s localhost -p $mport -v -k 'mine' -d", undef); |
| 693 |
&runtest("myproxy-destroy -s localhost -p $mport -v -k 'nobody' -d", undef); |
| 694 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", undef); |
| 695 |
|
| 696 |
## |
| 697 |
## Test replication failure handling |
| 698 |
## |
| 699 |
|
| 700 |
## |
| 701 |
## Test 20 |
| 702 |
## |
| 703 |
($exitstatus, $output) = |
| 704 |
&runtest("myproxy-init -s localhost -p $mport -v -a -c 1 -t 1 -S", |
| 705 |
$passphrase . "\n"); |
| 706 |
print "MyProxy Test 20 (store credential with default name): "; |
| 707 |
if ($exitstatus == 0) { |
| 708 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 709 |
} else { |
| 710 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 711 |
} |
| 712 |
|
| 713 |
## |
| 714 |
## Test 21 |
| 715 |
## |
| 716 |
kill('TERM', $sl3pid) if (defined($sl3pid)); |
| 717 |
|
| 718 |
($exitstatus, $output) = |
| 719 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 720 |
undef); |
| 721 |
print "MyProxy Test 21 (Replicate master server to all slaves): "; |
| 722 |
|
| 723 |
if ($exitstatus != 0 && $output =~ /Unable to connect to/) { |
| 724 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 725 |
} else { |
| 726 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 727 |
} |
| 728 |
|
| 729 |
## |
| 730 |
## Test 22 |
| 731 |
## |
| 732 |
start_sl3(); |
| 733 |
|
| 734 |
($exitstatus, $output) = |
| 735 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 736 |
undef); |
| 737 |
print "MyProxy Test 22 (Replicate master server to all slaves): "; |
| 738 |
if ($exitstatus == 0) { |
| 739 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 740 |
} else { |
| 741 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 742 |
} |
| 743 |
|
| 744 |
## |
| 745 |
## Test 23 |
| 746 |
## |
| 747 |
kill('TERM', $sl3pid) if (defined($sl3pid)); |
| 748 |
|
| 749 |
($exitstatus, $output) = |
| 750 |
&runtest("myproxy-destroy -s localhost -p $mport -v", undef); |
| 751 |
print "MyProxy Test 23 (remove credential from master repository): "; |
| 752 |
if ($exitstatus == 0 && $output =~ /was successfully removed/) { |
| 753 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 754 |
} else { |
| 755 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 756 |
} |
| 757 |
|
| 758 |
($exitstatus, $output) = |
| 759 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 760 |
undef); |
| 761 |
print "\t(Replicate master server to all slaves): "; |
| 762 |
if ($exitstatus != 0 && $output =~ /Unable to connect to/) { |
| 763 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 764 |
} else { |
| 765 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 766 |
} |
| 767 |
|
| 768 |
## |
| 769 |
## Test 24 |
| 770 |
## |
| 771 |
start_sl3(); |
| 772 |
|
| 773 |
($exitstatus, $output) = |
| 774 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 775 |
undef); |
| 776 |
print "MyProxy Test 24 (Replicate master server to all slaves): "; |
| 777 |
if ($exitstatus == 0) { |
| 778 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 779 |
} else { |
| 780 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 781 |
goto end_of_tests; |
| 782 |
} |
| 783 |
|
| 784 |
## |
| 785 |
## Test 25 |
| 786 |
## |
| 787 |
kill('TERM', $sl3pid) if (defined($sl3pid)); |
| 788 |
|
| 789 |
($exitstatus, $output) = |
| 790 |
&runtest("myproxy-init -s localhost -p $mport -v -a -c 1 -t 1 -S", |
| 791 |
$passphrase . "\n"); |
| 792 |
print "MyProxy Test 25 (store credential with default name): "; |
| 793 |
if ($exitstatus == 0) { |
| 794 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 795 |
} else { |
| 796 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 797 |
} |
| 798 |
|
| 799 |
($exitstatus, $output) = |
| 800 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 801 |
undef); |
| 802 |
print "\t(Replicate master server to all slaves): "; |
| 803 |
if ($exitstatus != 0 && $output =~ /Unable to connect to/) { |
| 804 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 805 |
} else { |
| 806 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 807 |
} |
| 808 |
|
| 809 |
($exitstatus, $output) = |
| 810 |
&runtest("myproxy-destroy -s localhost -p $mport -v", undef); |
| 811 |
print "\t(remove credential from master repository): "; |
| 812 |
if ($exitstatus == 0 && $output =~ /was successfully removed/) { |
| 813 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 814 |
} else { |
| 815 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 816 |
} |
| 817 |
|
| 818 |
start_sl3(); |
| 819 |
|
| 820 |
($exitstatus, $output) = |
| 821 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 822 |
undef); |
| 823 |
print "\t(Replicate master server to all slaves): "; |
| 824 |
if ($exitstatus == 0) { |
| 825 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 826 |
} else { |
| 827 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 828 |
} |
| 829 |
|
| 830 |
# |
| 831 |
# Start of myproxy-store and myproxy-retrieve tests |
| 832 |
# |
| 833 |
|
| 834 |
# commands to test: myproxy-store, myproxy-info, myproxy-destroy, |
| 835 |
# myproxy-get-delegation, myproxy-retrieve, and |
| 836 |
# myproxy-change-pass-phrase |
| 837 |
|
| 838 |
# For myproxy-store, we need an encrypted key to store. |
| 839 |
# So, let's encrypt our proxy key. |
| 840 |
$passphrase = sprintf "%010d", int(rand(0x7fffffff)); |
| 841 |
$testkey = "$tmpdir/myproxy-test.$$.key"; |
| 842 |
&runtest("openssl rsa -des3 -passout stdin -in \$X509_USER_KEY -out $testkey", |
| 843 |
$passphrase . "\n"); |
| 844 |
chmod(0600, $testkey); |
| 845 |
|
| 846 |
# |
| 847 |
# Test 26 |
| 848 |
# |
| 849 |
($exitstatus, $output) = |
| 850 |
&runtest("myproxy-store -s localhost -p $mport -v -t 1 -y $testkey", undef); |
| 851 |
print "MyProxy Test 26 (store credential with default name): "; |
| 852 |
if ($exitstatus == 0) { |
| 853 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 854 |
} elsif (($output =~ /Error checking authorization/) || |
| 855 |
($output =~ /unknown command/)) { |
| 856 |
print "UNSUPPORTED\n"; $FAILURES++; |
| 857 |
print "Server does not support myproxy-store. Skipping futher myproxy-store tests.\n"; |
| 858 |
goto end_of_tests; |
| 859 |
} else { |
| 860 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 861 |
print "Skipping futher myproxy-store tests.\n"; |
| 862 |
goto end_of_tests; |
| 863 |
} |
| 864 |
|
| 865 |
# |
| 866 |
# Test 27 |
| 867 |
# |
| 868 |
($exitstatus, $output) = &runtest("myproxy-info -s localhost -p $mport -v", undef); |
| 869 |
print "MyProxy Test 27 (get info for stored credential): "; |
| 870 |
if ($exitstatus == 0 && $output =~ /username/) { |
| 871 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 872 |
} else { |
| 873 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 874 |
} |
| 875 |
|
| 876 |
# |
| 877 |
# Test 28 |
| 878 |
# |
| 879 |
($exitstatus, $output) = |
| 880 |
&runtest("myproxy-get-delegation -s localhost -p $mport -t 1 -o $tmpdir/myproxy-test.$$ -v -S", |
| 881 |
$passphrase . "\n"); |
| 882 |
print "MyProxy Test 28 (create proxy from stored credential on master): "; |
| 883 |
if ($exitstatus == 0) { |
| 884 |
($exitstatus, $output) = |
| 885 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 886 |
} |
| 887 |
if ($exitstatus == 0) { |
| 888 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 889 |
} else { |
| 890 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 891 |
} |
| 892 |
|
| 893 |
# |
| 894 |
# Test 29 |
| 895 |
# |
| 896 |
|
| 897 |
($exitstatus, $output) = |
| 898 |
&runtest("myproxy-retrieve -s localhost -p $mport -c $tmpdir/myproxy-test.cert.$$ -y $tmpdir/myproxy-test.key.$$ -v -S", |
| 899 |
$passphrase . "\n"); |
| 900 |
print "MyProxy Test 29 (retrieve stored credential from master): "; |
| 901 |
if ($exitstatus == 0) { |
| 902 |
($exitstatus, $output) = |
| 903 |
&verifycert("$tmpdir/myproxy-test.cert.$$", "$tmpdir/myproxy-test.key.$$"); |
| 904 |
} |
| 905 |
if ($exitstatus == 0) { |
| 906 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 907 |
} else { |
| 908 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 909 |
} |
| 910 |
unlink( "$tmpdir/myproxy-test.cert.$$" ); |
| 911 |
unlink( "$tmpdir/myproxy-test.key.$$" ); |
| 912 |
|
| 913 |
## |
| 914 |
## Test 30 |
| 915 |
## |
| 916 |
($exitstatus, $output) = |
| 917 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 918 |
undef); |
| 919 |
print "MyProxy Test 30 (Replicate to all slaves): "; |
| 920 |
if ($exitstatus == 0) { |
| 921 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 922 |
} else { |
| 923 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 924 |
} |
| 925 |
|
| 926 |
# |
| 927 |
# Test 31 |
| 928 |
# |
| 929 |
($exitstatus, $output) = |
| 930 |
&runtest("myproxy-get-delegation -s localhost -p $s1port -t 1 -o $tmpdir/myproxy-test.$$ -v -S", $passphrase . "\n"); |
| 931 |
print "MyProxy Test 31 (create proxy from stored credential on slave): "; |
| 932 |
if ($exitstatus == 0) { |
| 933 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 934 |
} else { |
| 935 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 936 |
} |
| 937 |
|
| 938 |
# |
| 939 |
# Test 32 |
| 940 |
# |
| 941 |
($exitstatus, $output) = |
| 942 |
&runtest("myproxy-retrieve -s localhost -p $s2port -c $tmpdir/myproxy-test-cert.$$ -y $tmpdir/myproxy-test-key.$$ -v -S", |
| 943 |
$passphrase . "\n"); |
| 944 |
print "MyProxy Test 32 (retrieve stored credential from slave): "; |
| 945 |
if ($exitstatus == 0) { |
| 946 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 947 |
} else { |
| 948 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 949 |
} |
| 950 |
unlink( "$tmpdir/myproxy-test.cert.$$" ); |
| 951 |
unlink( "$tmpdir/myproxy-test.key.$$" ); |
| 952 |
|
| 953 |
# |
| 954 |
# Test 33 |
| 955 |
# |
| 956 |
($exitstatus, $output) = |
| 957 |
&runtest("myproxy-destroy -s localhost -p $mport -v", undef); |
| 958 |
print "MyProxy Test 33 (remove credential from master repository): "; |
| 959 |
if ($exitstatus == 0 && $output =~ /was successfully removed/) { |
| 960 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 961 |
} else { |
| 962 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 963 |
} |
| 964 |
|
| 965 |
# |
| 966 |
# Test 34 |
| 967 |
# |
| 968 |
($exitstatus, $output) = |
| 969 |
&runtest("myproxy-info -v", undef); |
| 970 |
print "MyProxy Test 34 (verify credentials are removed from master): "; |
| 971 |
if (!($output =~ /default credential/)) { |
| 972 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 973 |
} else { |
| 974 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 975 |
} |
| 976 |
|
| 977 |
## |
| 978 |
## Test 35 |
| 979 |
## |
| 980 |
($exitstatus, $output) = |
| 981 |
&runtest("myproxy-replicate -d -v -c $masterconf -r $masterdir", |
| 982 |
undef); |
| 983 |
print "MyProxy Test 35 (Replicate to all slaves): "; |
| 984 |
if ($exitstatus == 0) { |
| 985 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 986 |
} else { |
| 987 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 988 |
} |
| 989 |
|
| 990 |
## |
| 991 |
## Test 36 |
| 992 |
## |
| 993 |
($exitstatus, $output) = |
| 994 |
&runtest("myproxy-get-delegation -s localhost -p $s3port -t 1 -o $tmpdir/myproxy-test.$$ -v -S", |
| 995 |
$passphrase . "\n"); |
| 996 |
print "MyProxy Test 36 (verify destroy has been replicated to slaves): "; |
| 997 |
if ($exitstatus != 0 && $output =~ /exist/) { |
| 998 |
($exitstatus, $output) = |
| 999 |
&verifyproxy("$tmpdir/myproxy-test.$$"); |
| 1000 |
} |
| 1001 |
if ($exitstatus == 0) { |
| 1002 |
print "SUCCEEDED\n"; $SUCCESSES++; |
| 1003 |
} else { |
| 1004 |
print "FAILED\n"; $FAILURES++; print STDERR $output; |
| 1005 |
} |
| 1006 |
|
| 1007 |
end_of_tests: |
| 1008 |
&runtest("myproxy-destroy -v -k 'mine' -d", undef); |
| 1009 |
&runtest("myproxy-destroy -v -k 'nobody' -d", undef); |
| 1010 |
`rm -f $tmpdir/myproxy-test.*.12.*.$$`; |
| 1011 |
unlink("$tmpdir/myproxy-test.$$.key"); |
| 1012 |
|
| 1013 |
# |
| 1014 |
# END TESTS |
| 1015 |
# |
| 1016 |
|
| 1017 |
&docleanup(); |
| 1018 |
|
| 1019 |
print "MyProxy Tests Complete: ", $SUCCESSES, " tests passed, "; |
| 1020 |
print $FAILURES, " tests failed\n"; |
| 1021 |
exit $FAILURES; |
| 1022 |
|
| 1023 |
# |
| 1024 |
# SUBROUTINES |
| 1025 |
# |
| 1026 |
|
| 1027 |
sub runtest { |
| 1028 |
local($command, $input) = @_; |
| 1029 |
|
| 1030 |
$pid = open3(*Writer, *Reader, 0, "exec $command") || |
| 1031 |
die "failed to run $command"; |
| 1032 |
print Writer $input if (defined($input)); |
| 1033 |
close(Writer); |
| 1034 |
@output = <Reader>; |
| 1035 |
close(Reader); |
| 1036 |
waitpid($pid, 0); |
| 1037 |
$exitstatus = $?; |
| 1038 |
$output = join('', @output); |
| 1039 |
|
| 1040 |
return ($exitstatus, $output); |
| 1041 |
} |
| 1042 |
|
| 1043 |
# |
| 1044 |
# verify_proxy |
| 1045 |
# |
| 1046 |
# Check to see if user has a valid proxy, and verify proxy is usable |
| 1047 |
# |
| 1048 |
# Dependencies: (-x grid-proxy-info) |
| 1049 |
# |
| 1050 |
# grid-proxy-info -timeleft |
| 1051 |
# die if no output, or output is less than 60 seconds |
| 1052 |
# $proxy = grid-proxy-info -path |
| 1053 |
# grid-proxy-init -debug -verify -cert $proxy -key $proxy |
| 1054 |
# if $? == 0 then proxy is valid |
| 1055 |
# if $? != 0, die, b/c proxy is invalid and won't work |
| 1056 |
# |
| 1057 |
sub verifyproxy { |
| 1058 |
local($proxyfile) = @_; |
| 1059 |
|
| 1060 |
chomp (my $timeleft = `$grid_proxy_info -file $proxyfile -timeleft`); |
| 1061 |
if (!defined($timeleft) || $timeleft eq "") { |
| 1062 |
$output = "failed to verify proxy\n"; |
| 1063 |
$output .= "'grid-proxy-info -timeleft' failed\n"; |
| 1064 |
return (1, $output); |
| 1065 |
} |
| 1066 |
if ($timeleft < 1) { |
| 1067 |
$output = "proxy is expired\n"; |
| 1068 |
return (1, $output); |
| 1069 |
} |
| 1070 |
chomp (my $proxytype = `$grid_proxy_info -file $proxyfile -type`); |
| 1071 |
local($oldproxy) = ""; |
| 1072 |
if ($proxytype =~ /legacy/) { |
| 1073 |
$oldproxy = "-old"; |
| 1074 |
} |
| 1075 |
local($output) = '$grid_proxy_init $oldproxy -debug -verify -cert $proxyfile -key $proxyfile -valid 0:1 -out $tmpdir/tmpproxy.$$'; |
| 1076 |
if ($? != 0) { |
| 1077 |
$output = "failed to verify proxy\n" . $output; |
| 1078 |
unlink("$tmpdir/tmpproxy.$$"); |
| 1079 |
return (1, $output); |
| 1080 |
} |
| 1081 |
|
| 1082 |
# remove the new proxy we created for validation |
| 1083 |
# NOTE: this does not affect the user's original proxy in any way |
| 1084 |
unlink("$tmpdir/tmpproxy.$$"); |
| 1085 |
|
| 1086 |
return (0, ""); |
| 1087 |
} |
| 1088 |
|
| 1089 |
# |
| 1090 |
# verifycert |
| 1091 |
# |
| 1092 |
# Check to see if user has a valid usable certificate |
| 1093 |
# |
| 1094 |
# Dependencies: (-x grid-proxy-int) |
| 1095 |
# |
| 1096 |
# grid-proxy-init -debug -verify -cert $certfile -key $keyfile |
| 1097 |
# if $? == 0 then proxy is valid |
| 1098 |
# if $? != 0, die, b/c proxy is invalid and won't work |
| 1099 |
# |
| 1100 |
sub verifycert { |
| 1101 |
local($certfile, $keyfile) = @_; |
| 1102 |
|
| 1103 |
local($output) = '$grid_proxy_init $oldproxy -debug -verify -cert $certfile -key $keyfile -valid 0:1 -out $tmpdir/tmpproxy.$$'; |
| 1104 |
if ($? != 0) { |
| 1105 |
$output = "failed to verify certificate from: $certfile and $keyfile\n" . $output; |
| 1106 |
unlink("$tmpdir/tmpproxy.$$"); |
| 1107 |
return (1, $output); |
| 1108 |
} |
| 1109 |
|
| 1110 |
# remove the new proxy we created for validation |
| 1111 |
# NOTE: this does not affect the user's original proxy in any way |
| 1112 |
unlink("$tmpdir/tmpproxy.$$"); |
| 1113 |
|
| 1114 |
return (0, ""); |
| 1115 |
} |
| 1116 |
|
| 1117 |
sub debug { |
| 1118 |
print STDERR join('', @_), "\n" if ($verbose); |
| 1119 |
} |
| 1120 |
|
| 1121 |
sub docleanup { |
| 1122 |
unlink("$tmpdir/myproxy-test.$$"); |
| 1123 |
unlink("$tmpdir/myproxy-test-cert.$$"); |
| 1124 |
unlink("$tmpdir/myproxy-test-key.$$"); |
| 1125 |
|
| 1126 |
# Kill off servers... |
| 1127 |
kill('TERM', $masterpid) if (defined($masterpid)); |
| 1128 |
kill('TERM', $sl1pid) if (defined($sl1pid)); |
| 1129 |
kill('TERM', $sl2pid) if (defined($sl2pid)); |
| 1130 |
kill('TERM', $sl3pid) if (defined($sl3pid)); |
| 1131 |
|
| 1132 |
# Get rid of pid files... |
| 1133 |
unlink($masterpidfile) if (defined($masterpidfile)); |
| 1134 |
unlink($sl1pidfile) if (defined($sl1pidfile)); |
| 1135 |
unlink($sl2pidfile) if (defined($sl2pidfile)); |
| 1136 |
unlink($sl3pidfile) if (defined($sl3pidfile)); |
| 1137 |
|
| 1138 |
if ($cleanupfiles) { |
| 1139 |
# Remove configuration files... |
| 1140 |
unlink($masterconf) if (defined($masterconf)); |
| 1141 |
unlink($slconf) if (defined($slconf)); |
| 1142 |
|
| 1143 |
# Get rid of left over creds and dirs... |
| 1144 |
`rm -rf $masterdir` if (defined($masterdir)); |
| 1145 |
`rm -rf $sl1dir` if (defined($sl1dir)); |
| 1146 |
`rm -rf $sl2dir` if (defined($sl2dir)); |
| 1147 |
`rm -rf $sl3dir` if (defined($sl3dir)); |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
sub openport { |
| 1152 |
$sockaddr = 'S n a4 x8'; |
| 1153 |
$host = "127.0.0.1"; |
| 1154 |
local($port) = @_; |
| 1155 |
@list = getprotobyname('tcp'); |
| 1156 |
$proto = $list[2]; |
| 1157 |
@list = gethostbyaddr(inet_aton($host), AF_INET); |
| 1158 |
$addr = $list[4]; |
| 1159 |
while ($port < 65535) { |
| 1160 |
$destaddr = pack($sockaddr, AF_INET, $port, $addr); |
| 1161 |
socket(S, AF_INET, SOCK_STREAM, $proto) || die $!; |
| 1162 |
connect(S, $destaddr); |
| 1163 |
if ($! =~ /Connection refused/) { |
| 1164 |
return $port; |
| 1165 |
} |
| 1166 |
close(S); |
| 1167 |
$port++; |
| 1168 |
} |
| 1169 |
die "failed to find available port"; |
| 1170 |
} |
| 1171 |
|
| 1172 |
sub runcmd { |
| 1173 |
local($command, $input) = @_; |
| 1174 |
|
| 1175 |
print STDERR "running: ", $command, "\n" if ($verbose); |
| 1176 |
$pid = open3(*Writer, *Reader, '', "exec $command") || |
| 1177 |
die "failed to run $command"; |
| 1178 |
print Writer $input if (defined($input)); |
| 1179 |
close(Writer); |
| 1180 |
@output = <Reader>; |
| 1181 |
close(Reader); |
| 1182 |
waitpid($pid, 0); |
| 1183 |
$exitstatus = $?; |
| 1184 |
$output = join('', @output); |
| 1185 |
print STDERR $output if ($verbose); |
| 1186 |
|
| 1187 |
return ($exitstatus, $output); |
| 1188 |
} |