Fix test/recipes/95-test_external_krb5.t
[openssl.git] / test / recipes / 20-test_enc_more.t
1 #! /usr/bin/env perl
2 # Copyright 2017 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 # ======================================================================
10 # Copyright (c) 2017 Oracle and/or its affiliates.  All rights reserved.
11
12
13 use strict;
14 use warnings;
15
16 use File::Spec::Functions qw/catfile/;
17 use File::Copy;
18 use File::Compare qw/compare_text/;
19 use File::Basename;
20 use OpenSSL::Test qw/:DEFAULT srctop_file/;
21
22 setup("test_evp_more");
23
24 my $testsrc = srctop_file("test", "recipes", basename($0));
25
26 my $cipherlist = undef;
27 my $plaintext = catfile(".", "testdatafile");
28 my $fail = "";
29 my $cmd = "openssl";
30
31 my $ciphersstatus = undef;
32 my @ciphers =
33     grep(! /wrap|^$|^[^-]/,
34          (map { split /\s+/ }
35           run(app([$cmd, "enc", "-ciphers"]),
36               capture => 1, statusvar => \$ciphersstatus)));
37
38 plan tests => 2 + scalar @ciphers;
39
40 SKIP: {
41     skip "Problems getting ciphers...", 1 + scalar(@ciphers)
42         unless ok($ciphersstatus, "Running 'openssl enc -ciphers'");
43     unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
44         diag($!);
45         skip "Not initialized, skipping...", scalar(@ciphers);
46     }
47
48     foreach my $cipher (@ciphers) {
49         my $ciphername = substr $cipher, 1;
50         my $cipherfile = "$plaintext.$ciphername.cipher";
51         my $clearfile = "$plaintext.$ciphername.clear";
52         my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
53
54         ok(run(app([@common, "-e", "-in", $plaintext, "-out", $cipherfile]))
55            && compare_text($plaintext, $cipherfile) != 0
56            && run(app([@common, "-d", "-in", $cipherfile, "-out", $clearfile]))
57            && compare_text($plaintext, $clearfile) == 0
58            , $ciphername);
59         unlink $cipherfile, $clearfile;
60     }
61 }
62
63 unlink $plaintext;