Unified copyright for test recipes
[openssl.git] / test / recipes / 90-test_networking.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 use strict;
10 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_file bldtop_dir/;
11 use OpenSSL::Test::Utils;
12 use TLSProxy::Proxy;
13
14 my $test_name = "test_networking";
15 setup($test_name);
16
17 plan skip_all => "TLSProxy isn't usable on $^O"
18     if $^O =~ /^(VMS|MSWin32)$/;
19
20 plan skip_all => "$test_name needs the dynamic engine feature enabled"
21     if disabled("engine") || disabled("dynamic-engine");
22
23 plan skip_all => "$test_name needs the sock feature enabled"
24     if disabled("sock");
25
26 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
27
28 my $proxy = TLSProxy::Proxy->new(
29     undef,
30     cmdstr(app(["openssl"]), display => 1),
31     srctop_file("apps", "server.pem"),
32     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
33 );
34
35 plan tests => 2;
36
37 #Test 1: Try IPv4
38 $proxy->clear();
39 $proxy->serverflags("-4");
40 $proxy->clientflags("-4");
41 $proxy->server_addr("127.0.0.1");
42 $proxy->proxy_addr("127.0.0.1");
43 ok(check_connection(), "Trying IPv4");
44
45  SKIP: {
46      skip "No IPv6 support", 1 unless $proxy->supports_IPv6();
47
48      #Test 2: Try IPv6
49      $proxy->clear();
50      $proxy->serverflags("-6");
51      $proxy->clientflags("-6");
52      $proxy->server_addr("[::1]");
53      $proxy->proxy_addr("[::1]");
54      ok(check_connection(), "Trying IPv6");
55 }
56
57 sub check_connection
58 {
59     eval { $proxy->start(); };
60
61     if ($@ ne "") {
62         print STDERR "Proxy connection failed: $@\n";
63         return 0;
64     }
65
66     1;
67 }