Blame test/recipes/20-test_enc_more.t

Packit c4476c
#! /usr/bin/env perl
Packit c4476c
# Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
# Copyright (c) 2017, Oracle and/or its affiliates.  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::Spec::Functions qw/catfile/;
Packit c4476c
use File::Copy;
Packit c4476c
use File::Compare qw/compare_text/;
Packit c4476c
use File::Basename;
Packit c4476c
use OpenSSL::Test qw/:DEFAULT srctop_file/;
Packit c4476c
Packit c4476c
setup("test_evp_more");
Packit c4476c
Packit c4476c
my $testsrc = srctop_file("test", "recipes", basename($0));
Packit c4476c
Packit c4476c
my $cipherlist = undef;
Packit c4476c
my $plaintext = catfile(".", "testdatafile");
Packit c4476c
my $fail = "";
Packit c4476c
my $cmd = "openssl";
Packit c4476c
Packit c4476c
my $ciphersstatus = undef;
Packit c4476c
my @ciphers =
Packit c4476c
    grep(! /wrap|^$|^[^-]/,
Packit c4476c
         (map { split /\s+/ }
Packit c4476c
          run(app([$cmd, "enc", "-ciphers"]),
Packit c4476c
              capture => 1, statusvar => \$ciphersstatus)));
Packit c4476c
Packit c4476c
plan tests => 2 + scalar @ciphers;
Packit c4476c
Packit c4476c
SKIP: {
Packit c4476c
    skip "Problems getting ciphers...", 1 + scalar(@ciphers)
Packit c4476c
        unless ok($ciphersstatus, "Running 'openssl enc -ciphers'");
Packit c4476c
    unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
Packit c4476c
        diag($!);
Packit c4476c
        skip "Not initialized, skipping...", scalar(@ciphers);
Packit c4476c
    }
Packit c4476c
Packit c4476c
    foreach my $cipher (@ciphers) {
Packit c4476c
        my $ciphername = substr $cipher, 1;
Packit c4476c
        my $cipherfile = "$plaintext.$ciphername.cipher";
Packit c4476c
        my $clearfile = "$plaintext.$ciphername.clear";
Packit c4476c
        my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
Packit c4476c
Packit c4476c
        ok(run(app([@common, "-e", "-in", $plaintext, "-out", $cipherfile]))
Packit c4476c
           && compare_text($plaintext, $cipherfile) != 0
Packit c4476c
           && run(app([@common, "-d", "-in", $cipherfile, "-out", $clearfile]))
Packit c4476c
           && compare_text($plaintext, $clearfile) == 0
Packit c4476c
           , $ciphername);
Packit c4476c
        unlink $cipherfile, $clearfile;
Packit c4476c
    }
Packit c4476c
}
Packit c4476c
Packit c4476c
unlink $plaintext;