Skip the TLSProxy tests if environmental problems are an issue
[oweals/openssl.git] / test / recipes / 70-test_sslrecords.t
1 #! /usr/bin/env perl
2 # Copyright 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_dir/;
11 use OpenSSL::Test::Utils;
12 use TLSProxy::Proxy;
13
14 my $test_name = "test_sslrecords";
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 plan skip_all => "$test_name needs TLS enabled"
27     if alldisabled(available_protocols("tls"));
28
29 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
30 my $proxy = TLSProxy::Proxy->new(
31     \&add_empty_recs_filter,
32     cmdstr(app(["openssl"]), display => 1),
33     srctop_file("apps", "server.pem"),
34     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
35 );
36
37 #Test 1: Injecting out of context empty records should fail
38 my $content_type = TLSProxy::Record::RT_APPLICATION_DATA;
39 my $inject_recs_num = 1;
40 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
41 plan tests => 3;
42 ok(TLSProxy::Message->fail(), "Out of context empty records test");
43
44 #Test 2: Injecting in context empty records should succeed
45 $proxy->clear();
46 $content_type = TLSProxy::Record::RT_HANDSHAKE;
47 $proxy->start();
48 ok(TLSProxy::Message->success(), "In context empty records test");
49
50 #Test 3: Injecting too many in context empty records should fail
51 $proxy->clear();
52 #We allow 32 consecutive in context empty records
53 $inject_recs_num = 33;
54 $proxy->start();
55 ok(TLSProxy::Message->fail(), "Too many in context empty records test");
56
57 sub add_empty_recs_filter
58 {
59     my $proxy = shift;
60
61     # We're only interested in the initial ClientHello
62     if ($proxy->flight != 0) {
63         return;
64     }
65
66     for (my $i = 0; $i < $inject_recs_num; $i++) {
67         my $record = TLSProxy::Record->new(
68             0,
69             $content_type,
70             TLSProxy::Record::VERS_TLS_1_2,
71             0,
72             0,
73             0,
74             "",
75             ""
76         );
77
78         push @{$proxy->record_list}, $record;
79     }
80 }