Add checks for IPv4 and IPv6 in OpenSSL::Test::Utils and use them
authorRichard Levitte <levitte@openssl.org>
Thu, 4 Feb 2016 22:22:52 +0000 (23:22 +0100)
committerRichard Levitte <levitte@openssl.org>
Thu, 4 Feb 2016 22:45:03 +0000 (23:45 +0100)
This uilds on the same way of checking for availability as we do in
TLSProxy.  We use all IP factories we know of, starting with those who
know both IPv6 and IPv4 and ending with the one that only knows IPv4
and cache their possible success as foundation for checking the
available of each IP domain.

80-test_ssl.t has bigger chances of working on platforms that do not
run both IP domains.

Reviewed-by: Rich Salz <rsalz@openssl.org>
test/recipes/80-test_ssl.t
test/testlib/OpenSSL/Test/Utils.pm

index 32616f01953c9aff9c4ef2a60dda3b0b07497d6d..e84d3cce54bdf2b65855cb6bcbff1e50a9291e06 100644 (file)
@@ -431,12 +431,20 @@ sub testssl {
          ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
             'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
 
          ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
             'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
 
-         ok(run(test([@ssltest, "-ipv4", @extra])),
-            'test TLS via IPv4');
-         ok(run(test([@ssltest, "-ipv6", @extra])),
-            'test TLS via IPv6');
-
-       }
+        SKIP: {
+            skip "No IPv4 available on this machine", 1
+                unless have_IPv4();
+            ok(run(test([@ssltest, "-ipv4", @extra])),
+               'test TLS via IPv4');
+          }
+          
+        SKIP: {
+            skip "No IPv6 available on this machine", 1
+                unless have_IPv6();
+            ok(run(test([@ssltest, "-ipv6", @extra])),
+               'test TLS via IPv6');
+          }
+        }
     };
 
     subtest "Testing ciphersuites" => sub {
     };
 
     subtest "Testing ciphersuites" => sub {
index 8f75013a6c55bc7949ca0549fe33fc32676436e8..2b2cfcd0a8d943d483aa619cb7f536ee6adb6a2e 100644 (file)
@@ -7,7 +7,8 @@ use Exporter;
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 $VERSION = "0.1";
 @ISA = qw(Exporter);
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 $VERSION = "0.1";
 @ISA = qw(Exporter);
-@EXPORT = qw(alldisabled anydisabled disabled config available_protocols);
+@EXPORT = qw(alldisabled anydisabled disabled config available_protocols
+             have_IPv4 have_IPv6);
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -24,6 +25,9 @@ OpenSSL::Test::Utils - test utility functions
 
   config("fips");
 
 
   config("fips");
 
+  have_IPv4();
+  have_IPv6();
+
 =head1 DESCRIPTION
 
 This module provides utility functions for the testing framework.
 =head1 DESCRIPTION
 
 This module provides utility functions for the testing framework.
@@ -55,6 +59,11 @@ disabled.
 
 Returns an item from the %config hash in \$TOP/configdata.pm.
 
 
 Returns an item from the %config hash in \$TOP/configdata.pm.
 
+=item B<have_IPv4>
+=item B<have_IPv6>
+
+Return true if IPv4 / IPv6 is possible to use on the current system.
+
 =back
 
 =cut
 =back
 
 =cut
@@ -142,6 +151,73 @@ sub config {
     return $config{$_[0]};
 }
 
     return $config{$_[0]};
 }
 
+# IPv4 / IPv6 checker
+my $have_IPv4 = -1;
+my $have_IPv6 = 1;
+my $IP_factory;
+sub check_IP {
+    my $listenaddress = shift;
+
+    eval {
+        require IO::Socket::IP;
+        my $s = IO::Socket::IP->new(
+            LocalAddr => $listenaddress,
+            LocalPort => 0,
+            Listen=>1,
+            );
+        $s or die "\n";
+        $s->close();
+    };
+    if ($@ eq "") {
+        return 1;
+    }
+
+    eval {
+        require IO::Socket::INET6;
+        my $s = IO::Socket::INET6->new(
+            LocalAddr => $listenaddress,
+            LocalPort => 0,
+            Listen=>1,
+            );
+        $s or die "\n";
+        $s->close();
+    };
+    if ($@ eq "") {
+        return 1;
+    }
+
+    eval {
+        require IO::Socket::INET;
+        my $s = IO::Socket::INET->new(
+            LocalAddr => $listenaddress,
+            LocalPort => 0,
+            Listen=>1,
+            );
+        $s or die "\n";
+        $s->close();
+    };
+    if ($@ eq "") {
+        return 1;
+    }
+
+    return 0;
+}
+
+sub have_IPv4 {
+    if ($have_IPv4 < 0) {
+        $have_IPv4 = check_IP("127.0.0.1");
+    }
+    return $have_IPv4;
+}
+
+sub have_IPv6 {
+    if ($have_IPv6 < 0) {
+        $have_IPv6 = check_IP("::1");
+    }
+    return $have_IPv6;
+}
+
+
 =head1 SEE ALSO
 
 L<OpenSSL::Test>
 =head1 SEE ALSO
 
 L<OpenSSL::Test>