Blame test/recipes/80-test_ssl_new.t

Packit c4476c
#! /usr/bin/env perl
Packit c4476c
# Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
#
Packit c4476c
# Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
# this file except in compliance with the License.  You can obtain a copy
Packit c4476c
# in the file LICENSE in the source distribution or at
Packit c4476c
# https://www.openssl.org/source/license.html
Packit c4476c
Packit c4476c
Packit c4476c
use strict;
Packit c4476c
use warnings;
Packit c4476c
Packit c4476c
use File::Basename;
Packit c4476c
use File::Compare qw/compare_text/;
Packit c4476c
use OpenSSL::Glob;
Packit c4476c
use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file/;
Packit c4476c
use OpenSSL::Test::Utils qw/disabled alldisabled available_protocols/;
Packit c4476c
Packit c4476c
setup("test_ssl_new");
Packit c4476c
Packit c4476c
$ENV{TEST_CERTS_DIR} = srctop_dir("test", "certs");
Packit c4476c
$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
Packit c4476c
Packit c4476c
my @conf_srcs =  glob(srctop_file("test", "ssl-tests", "*.conf.in"));
Packit c4476c
map { s/;.*// } @conf_srcs if $^O eq "VMS";
Packit c4476c
my @conf_files = map { basename($_, ".in") } @conf_srcs;
Packit c4476c
map { s/\^// } @conf_files if $^O eq "VMS";
Packit c4476c
Packit c4476c
# We hard-code the number of tests to double-check that the globbing above
Packit c4476c
# finds all files as expected.
Packit c4476c
plan tests => 29;  # = scalar @conf_srcs
Packit c4476c
Packit c4476c
# Some test results depend on the configuration of enabled protocols. We only
Packit c4476c
# verify generated sources in the default configuration.
Packit c4476c
my $is_default_tls = (disabled("ssl3") && !disabled("tls1") &&
Packit c4476c
                      !disabled("tls1_1") && !disabled("tls1_2") &&
Packit c4476c
                      !disabled("tls1_3"));
Packit c4476c
Packit c4476c
my $is_default_dtls = (!disabled("dtls1") && !disabled("dtls1_2"));
Packit c4476c
Packit c4476c
my @all_pre_tls1_3 = ("ssl3", "tls1", "tls1_1", "tls1_2");
Packit c4476c
my $no_tls = alldisabled(available_protocols("tls"));
Packit c4476c
my $no_tls_below1_3 = $no_tls || (disabled("tls1_2") && !disabled("tls1_3"));
Packit c4476c
my $no_pre_tls1_3 = alldisabled(@all_pre_tls1_3);
Packit c4476c
my $no_dtls = alldisabled(available_protocols("dtls"));
Packit c4476c
my $no_npn = disabled("nextprotoneg");
Packit c4476c
my $no_ct = disabled("ct");
Packit c4476c
my $no_ec = disabled("ec");
Packit c4476c
my $no_dh = disabled("dh");
Packit c4476c
my $no_dsa = disabled("dsa");
Packit c4476c
my $no_ec2m = disabled("ec2m");
Packit c4476c
my $no_ocsp = disabled("ocsp");
Packit c4476c
Packit c4476c
# Add your test here if the test conf.in generates test cases and/or
Packit c4476c
# expectations dynamically based on the OpenSSL compile-time config.
Packit c4476c
my %conf_dependent_tests = (
Packit c4476c
  "02-protocol-version.conf" => !$is_default_tls,
Packit c4476c
  "04-client_auth.conf" => !$is_default_tls || !$is_default_dtls
Packit c4476c
                           || !disabled("sctp"),
Packit c4476c
  "05-sni.conf" => disabled("tls1_1"),
Packit c4476c
  "07-dtls-protocol-version.conf" => !$is_default_dtls || !disabled("sctp"),
Packit c4476c
  "10-resumption.conf" => !$is_default_tls,
Packit c4476c
  "11-dtls_resumption.conf" => !$is_default_dtls || !disabled("sctp"),
Packit c4476c
  "16-dtls-certstatus.conf" => !$is_default_dtls || !disabled("sctp"),
Packit c4476c
  "17-renegotiate.conf" => disabled("tls1_2"),
Packit c4476c
  "18-dtls-renegotiate.conf" => disabled("dtls1_2") || !disabled("sctp"),
Packit c4476c
  "19-mac-then-encrypt.conf" => !$is_default_tls,
Packit c4476c
  "20-cert-select.conf" => !$is_default_tls || $no_dh || $no_dsa,
Packit c4476c
  "22-compression.conf" => !$is_default_tls,
Packit c4476c
  "25-cipher.conf" => disabled("poly1305") || disabled("chacha"),
Packit c4476c
  "27-ticket-appdata.conf" => !$is_default_tls,
Packit c4476c
  "28-seclevel.conf" => disabled("tls1_2") || $no_ec,
Packit c4476c
);
Packit c4476c
Packit c4476c
# Add your test here if it should be skipped for some compile-time
Packit c4476c
# configurations. Default is $no_tls but some tests have different skip
Packit c4476c
# conditions.
Packit c4476c
my %skip = (
Packit c4476c
  "06-sni-ticket.conf" => $no_tls_below1_3,
Packit c4476c
  "07-dtls-protocol-version.conf" => $no_dtls,
Packit c4476c
  "08-npn.conf" => (disabled("tls1") && disabled("tls1_1")
Packit c4476c
                    && disabled("tls1_2")) || $no_npn,
Packit c4476c
  "10-resumption.conf" => disabled("tls1_1") || disabled("tls1_2"),
Packit c4476c
  "11-dtls_resumption.conf" => disabled("dtls1") || disabled("dtls1_2"),
Packit c4476c
  "12-ct.conf" => $no_tls || $no_ct || $no_ec,
Packit c4476c
  # We could run some of these tests without TLS 1.2 if we had a per-test
Packit c4476c
  # disable instruction but that's a bizarre configuration not worth
Packit c4476c
  # special-casing for.
Packit c4476c
  # TODO(TLS 1.3): We should review this once we have TLS 1.3.
Packit c4476c
  "13-fragmentation.conf" => disabled("tls1_2"),
Packit c4476c
  "14-curves.conf" => disabled("tls1_2") || $no_ec || $no_ec2m,
Packit c4476c
  "15-certstatus.conf" => $no_tls || $no_ocsp,
Packit c4476c
  "16-dtls-certstatus.conf" => $no_dtls || $no_ocsp,
Packit c4476c
  "17-renegotiate.conf" => $no_tls_below1_3,
Packit c4476c
  "18-dtls-renegotiate.conf" => $no_dtls,
Packit c4476c
  "19-mac-then-encrypt.conf" => $no_pre_tls1_3,
Packit c4476c
  "20-cert-select.conf" => disabled("tls1_2") || $no_ec,
Packit c4476c
  "21-key-update.conf" => disabled("tls1_3"),
Packit c4476c
  "22-compression.conf" => disabled("zlib") || $no_tls,
Packit c4476c
  "23-srp.conf" => (disabled("tls1") && disabled ("tls1_1")
Packit c4476c
                    && disabled("tls1_2")) || disabled("srp"),
Packit c4476c
  "24-padding.conf" => disabled("tls1_3"),
Packit c4476c
  "25-cipher.conf" => disabled("ec") || disabled("tls1_2"),
Packit c4476c
  "26-tls13_client_auth.conf" => disabled("tls1_3"),
Packit c4476c
  "29-dtls-sctp-label-bug.conf" => disabled("sctp") || disabled("sock"),
Packit c4476c
);
Packit c4476c
Packit c4476c
foreach my $conf (@conf_files) {
Packit c4476c
    subtest "Test configuration $conf" => sub {
Packit c4476c
        test_conf($conf,
Packit c4476c
                  $conf_dependent_tests{$conf} || $^O eq "VMS" ?  0 : 1,
Packit c4476c
                  defined($skip{$conf}) ? $skip{$conf} : $no_tls);
Packit c4476c
    }
Packit c4476c
}
Packit c4476c
Packit c4476c
sub test_conf {
Packit c4476c
    plan tests => 3;
Packit c4476c
Packit c4476c
    my ($conf, $check_source, $skip) = @_;
Packit c4476c
Packit c4476c
    my $conf_file = srctop_file("test", "ssl-tests", $conf);
Packit c4476c
    my $tmp_file = "${conf}.$$.tmp";
Packit c4476c
    my $run_test = 1;
Packit c4476c
Packit c4476c
  SKIP: {
Packit c4476c
      # "Test" 1. Generate the source.
Packit c4476c
      my $input_file = $conf_file . ".in";
Packit c4476c
Packit c4476c
      skip 'failure', 2 unless
Packit c4476c
        ok(run(perltest(["generate_ssl_tests.pl", $input_file],
Packit c4476c
                        interpreter_args => [ "-I", srctop_dir("util", "perl")],
Packit c4476c
                        stdout => $tmp_file)),
Packit c4476c
           "Getting output from generate_ssl_tests.pl.");
Packit c4476c
Packit c4476c
    SKIP: {
Packit c4476c
        # Test 2. Compare against existing output in test/ssl_tests.conf.
Packit c4476c
        skip "Skipping generated source test for $conf", 1
Packit c4476c
          if !$check_source;
Packit c4476c
Packit c4476c
        $run_test = is(cmp_text($tmp_file, $conf_file), 0,
Packit c4476c
                       "Comparing generated sources.");
Packit c4476c
      }
Packit c4476c
Packit c4476c
      # Test 3. Run the test.
Packit c4476c
      skip "No tests available; skipping tests", 1 if $skip;
Packit c4476c
      skip "Stale sources; skipping tests", 1 if !$run_test;
Packit c4476c
Packit c4476c
      ok(run(test(["ssl_test", $tmp_file])), "running ssl_test $conf");
Packit c4476c
    }
Packit c4476c
Packit c4476c
    unlink glob $tmp_file;
Packit c4476c
}
Packit c4476c
Packit c4476c
sub cmp_text {
Packit c4476c
    return compare_text(@_, sub {
Packit c4476c
        $_[0] =~ s/\R//g;
Packit c4476c
        $_[1] =~ s/\R//g;
Packit c4476c
        return $_[0] ne $_[1];
Packit c4476c
    });
Packit c4476c
}