Răsfoiți Sursa

Convert all tests to use short options

Not all getopt implementations support long form options, including AIX.
Doug Nazar 2 săptămâni în urmă
părinte
comite
fe1bc1f226
9 a modificat fișierele cu 32 adăugiri și 32 ștergeri
  1. 1 1
      src/nrpe.c
  2. 7 7
      tests/000-startup.t
  3. 1 1
      tests/001-normal.t
  4. 1 1
      tests/002-ipv6.t
  5. 3 3
      tests/010-no-ssl.t
  6. 6 6
      tests/020-ssl.t
  7. 5 5
      tests/050-misc.t
  8. 4 4
      tests/configs/check_nrpe.cfg
  9. 4 4
      tests/nrpe.pm

+ 1 - 1
src/nrpe.c

@@ -2971,7 +2971,7 @@ int process_arguments(int argc, char **argv)
 	if (argc < 2)
 		return ERROR;
 
-	snprintf(optchars, MAX_INPUT_BUFFER, "c:hVldi46nsf");
+	snprintf(optchars, MAX_INPUT_BUFFER, "c:hVldi46nsfC");
 
 	while (1) {
 #ifdef HAVE_GETOPT_LONG

+ 7 - 7
tests/000-startup.t

@@ -17,7 +17,7 @@ my @output;
 is($?, STATE_UNKNOWN, 'nrpe executes');
 like($output[0], qr/NRPE - Nagios Remote Plugin Executor/, 'nrpe banner');
 
-@output = `$nrpe --license`;
+@output = `$nrpe -l`;
 is($?, STATE_UNKNOWN, 'license') || diag @output;
 
 @output = `$checknrpe -V`;
@@ -25,21 +25,21 @@ is($?, STATE_UNKNOWN, 'check_nrpe executes');
 like($output[0], qr/NRPE Plugin for Nagios/, 'check_nrpe banner');
 
 
-@output = `$nrpe --daemon --dont-chdir --config configs/missing.cfg`;
+@output = `$nrpe -d -C -c configs/missing.cfg`;
 is($?, STATE_CRITICAL, 'missing config') || diag @output;
 
 SKIP: {
     skip 'no SSL', 5 if ! supports_ssl();
 
-    @output = `$nrpe --daemon --dont-chdir --config configs/ssl-invalid.cfg`;
+    @output = `$nrpe -d -C -c configs/ssl-invalid.cfg`;
     is($?, STATE_CRITICAL, 'invalid ssl config 1') || diag @output;
-    @output = `$nrpe --daemon --dont-chdir --config configs/ssl-invalid2.cfg`;
+    @output = `$nrpe -d -C -c configs/ssl-invalid2.cfg`;
     is($?, STATE_CRITICAL, 'invalid ssl config 2') || diag @output;
-    @output = `$nrpe --daemon --dont-chdir --config configs/ssl-invalid3.cfg`;
+    @output = `$nrpe -d -C -c configs/ssl-invalid3.cfg`;
     is($?, STATE_CRITICAL, 'invalid ssl config 3') || diag @output;
-    @output = `$nrpe --daemon --dont-chdir --config configs/ssl-invalid4.cfg`;
+    @output = `$nrpe -d -C -c configs/ssl-invalid4.cfg`;
     is($?, STATE_CRITICAL, 'invalid ssl config 4') || diag @output;
-    @output = `$nrpe --daemon --dont-chdir --config configs/ssl-invalid5.cfg`;
+    @output = `$nrpe -d -C -c configs/ssl-invalid5.cfg`;
     is($?, STATE_CRITICAL, 'invalid ssl config 5') || diag @output;
 }
 

+ 1 - 1
tests/001-normal.t

@@ -44,7 +44,7 @@ SKIP: {
 
 SKIP: {
     @output = `$checknrpe -H 127.0.0.1 -p 40321 -c state_ok`;
-    is($?, STATE_OK, "state_ok exec") || diag @output && skip 'failed exec', 2;
+    is($?, STATE_OK, "state_ok exec") || diag explain @output && skip 'failed exec', 2;
 
     is(@output, 1, 'state_ok result lines');
     is($output[0], "OK: Everything is normal\n", 'state_ok result');

+ 1 - 1
tests/002-ipv6.t

@@ -47,7 +47,7 @@ restart_daemon();
 is($?, STATE_OK, 'connection ipv6 only') || diag @output;
 like($output[0], qr/NRPE v.*/, 'connection ipv6 only response') || diag @output;
 
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --stderr-to-stdout`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -E`;
 is($?, STATE_CRITICAL, 'connection ipv4 on ipv6 only') || diag @output;
 like($output[0], qr/connect to .*: Connection refused/, 'connection ipv6 only response') || diag @output;
 

+ 3 - 3
tests/010-no-ssl.t

@@ -29,17 +29,17 @@ is($?, STATE_UNKNOWN, 'connect ssl') || diag @output;
 like($output[0], qr/CHECK_NRPE:.* Error - Could not .*: /, 'connect ssl response') || diag @output;
 
 
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --no-ssl`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -n`;
 is($?, STATE_OK, 'connect without ssl') || diag @output;
 like($output[0], qr/NRPE v.*/, 'connect without ssl response') || diag @output;
 
 
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --no-ssl -2`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -n -2`;
 is($?, 0, 'version check - v2 packet') || diag @output;
 like($output[0], qr/NRPE v.*/, 'version check response - v2 packet') || diag @output;
 
 # Note: Server may fail v3 packet and we'll retry with a v2 packet. Could check log for difference if we care.
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --no-ssl -3`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -n -3`;
 is($?, 0, 'version check - v3 packet') || diag @output;
 like($output[0], qr/NRPE v.*/, 'version check response - v3 packet') || diag @output;
 

+ 6 - 6
tests/020-ssl.t

@@ -32,36 +32,36 @@ restart_daemon();
 is($?, STATE_OK, 'connect ssl') || diag @output;
 like($output[0], qr/NRPE v.*/, 'connect ssl response') || diag @output;
 
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --ca-cert-file=configs/certs/nrpe.crt`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -A configs/certs/nrpe.crt`;
 is($?, STATE_OK, 'connect ssl ca') || diag @output;
 like($output[0], qr/NRPE v.*/, 'connect ssl ca response') || diag @output;
 
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --ca-cert-file=configs/certs/nrpe.crt --client-cert=configs/certs/nrpe.crt --key-file=configs/certs/nrpe.key`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -A configs/certs/nrpe.crt -C configs/certs/nrpe.crt -K configs/certs/nrpe.key`;
 is($?, STATE_OK, 'connect ssl cert') || diag @output;
 like($output[0], qr/NRPE v.*/, 'connect ssl cert response') || diag @output;
 
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --ca-cert-file=configs/certs/other.crt`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -A configs/certs/other.crt`;
 is($?, STATE_UNKNOWN, 'connect ssl other ca') || diag @output;
 like($output[0], qr/CHECK_NRPE: \(ssl_err != 5\) Error - Could not complete SSL handshake with/, 'connect ssl other ca response') || diag @output;
 
 # --log-file=logs/check_nrpe_ssl.log --ssl-logging=255 
 #  openssl: CHECK_NRPE: Error - Could not connect to .*
 # libressl: CHECK_NRPE: Error sending query to host.
-@output = `$checknrpe -H 127.0.0.1 -p 40321 --ca-cert-file=configs/certs/nrpe.crt --client-cert=configs/certs/other.crt --key-file=configs/certs/other.key`;
+@output = `$checknrpe -H 127.0.0.1 -p 40321 -A configs/certs/nrpe.crt -C configs/certs/other.crt -K configs/certs/other.key`;
 is($?, STATE_UNKNOWN, 'connect ssl other cert') || diag @output;
 like($output[0], qr/CHECK_NRPE: Error /, 'connect ssl other cert response') || diag @output;
 
 
 foreach ( @SSL_Versions_Bad ) {
     my $ver = $_;
-    @output = `$checknrpe -H 127.0.0.1 -p 40321 --ca-cert-file=configs/certs/nrpe.crt --ssl-version=$ver`;
+    @output = `$checknrpe -H 127.0.0.1 -p 40321 -A configs/certs/nrpe.crt -S $ver`;
     is($?, STATE_UNKNOWN, "connect ssl $ver") || diag @output;
     like($output[0], qr/CHECK_NRPE: \(ssl_err != 5\) Error - Could not complete SSL handshake with/, "connect ssl $ver response") || diag @output;
 }
 
 foreach ( @SSL_Versions_Good ) {
     my $ver = $_;
-    @output = `$checknrpe -H 127.0.0.1 -p 40321 --ca-cert-file=configs/certs/nrpe.crt --ssl-version=$ver`;
+    @output = `$checknrpe -H 127.0.0.1 -p 40321 -A configs/certs/nrpe.crt -S $ver`;
     is($?, STATE_OK, "connect ssl $ver") || diag @output;
     like($output[0], qr/NRPE v.*/, "connect ssl $ver response") || diag @output;
 }

+ 5 - 5
tests/050-misc.t

@@ -17,15 +17,15 @@ my @output;
 
 @output = `$checknrpe`;
 is($?, STATE_UNKNOWN, 'usage') || diag @output;
-@output = `$checknrpe --license`;
+@output = `$checknrpe -l`;
 is($?, STATE_UNKNOWN, 'license') || diag @output;
-@output = `$checknrpe --config-file=configs/check_nrpe.cfg`;
+@output = `$checknrpe -f configs/check_nrpe.cfg`;
 is($?, STATE_UNKNOWN, 'config') || diag @output;
-@output = `$checknrpe --config-file=configs/nonexistant.cfg`;
+@output = `$checknrpe -f configs/nonexistant.cfg`;
 is($?, STATE_UNKNOWN, 'config nonexistant') || diag @output;
-@output = `$checknrpe --config-file=configs/check_nrpe.cfg -H 127.0.0.1 -p 40000`;
+@output = `$checknrpe -f configs/check_nrpe.cfg -H 127.0.0.1 -p 40000`;
 is($?, STATE_CRITICAL, 'invalid port') || diag @output;
 
 # We're trying to invoke alarm_handler() due to a timeout. Use an IP address that shouldn't be in use
-@output = `$checknrpe --config-file=configs/check_nrpe.cfg --timeout=1:WARNING -H 0.0.0.111 -p 40000`;
+@output = `$checknrpe -f configs/check_nrpe.cfg -t 1:WARNING -H 0.0.0.111 -p 40000`;
 is($?, STATE_WARNING, 'invalid ip') || diag @output;

+ 4 - 4
tests/configs/check_nrpe.cfg

@@ -1,5 +1,5 @@
---stderr-to-stdout
---disable-syslog
+-E
+-D
 
---ssl-version=TLSv1.2+
---timeout=15:CRITICAL
+-S TLSv1.2+
+-t 15:CRITICAL

+ 4 - 4
tests/nrpe.pm

@@ -30,8 +30,8 @@ defined($ARGV[0]) or die "Usage: $0 <top build dir>";
 
 my $top_builddir = $ARGV[0]; # shift @ARGV;
 our $nrpe = "$top_builddir/src/nrpe";
-our $checknrpe = "$top_builddir/src/check_nrpe --disable-syslog";
-#our $checknrpe = "valgrind --leak-check=full --log-file=logs/valgrind-check-%p.log $top_builddir/src/check_nrpe --disable-syslog";
+our $checknrpe = "$top_builddir/src/check_nrpe -D";
+#our $checknrpe = "valgrind --leak-check=full --log-file=logs/valgrind-check-%p.log $top_builddir/src/check_nrpe -D";
 my $nrpe_pid = 0;
 
 use constant {
@@ -89,7 +89,7 @@ sub wait_for_daemon {
 }
 
 sub launch_daemon {
-    my @output = `$nrpe --daemon --dont-chdir --config nrpe.cfg`;
+    my @output = `$nrpe -d -C -c nrpe.cfg`;
 #    my @output = `valgrind --leak-check=full --show-leak-kinds=all --log-file=logs/valgrind-%p.log $nrpe --daemon --dont-chdir --config nrpe.cfg`;
     my $pid = 0;
 
@@ -136,7 +136,7 @@ sub kill_daemon {
 }
 
 sub supports_ssl {
-    my @output = `$nrpe --help`;
+    my @output = `$nrpe -h`;
     return grep(m'^SSL/TLS Available', @output);
 }