Port SRP tests to the new test framework
[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 @ciphers =
32     grep(! /wrap|^$|^[^-]/,
33          (map { split /\s+/ }
34               run(app([$cmd, "enc", "-ciphers"]), capture => 1)));
35
36 plan tests => 1 + scalar @ciphers;
37
38 my $init = ok(copy($testsrc, $plaintext));
39
40 SKIP: {
41     skip "Not initialized, skipping...", (scalar @ciphers) unless $init;
42
43     foreach my $cipher (@ciphers) {
44         my $ciphername = substr $cipher, 1;
45         my $cipherfile = "$plaintext.$ciphername.cipher";
46         my $clearfile = "$plaintext.$ciphername.clear";
47         my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
48
49         ok(run(app([@common, "-e", "-in", $plaintext, "-out", $cipherfile]))
50            && compare_text($plaintext, $cipherfile) != 0
51            && run(app([@common, "-d", "-in", $cipherfile, "-out", $clearfile]))
52            && compare_text($plaintext, $clearfile) == 0
53            , $ciphername);
54         unlink $cipherfile, $clearfile;
55     }
56 }
57
58 unlink $plaintext;