Skip PSK tests for no-psk
[openssl.git] / test / recipes / 20-test_enc.t
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use File::Spec::Functions qw/catfile/;
7 use File::Copy;
8 use File::Compare qw/compare_text/;
9 use File::Basename;
10 use OpenSSL::Test qw/:DEFAULT top_file/;
11
12 setup("test_enc");
13
14 # We do it this way, because setup() may have moved us around,
15 # so the directory portion of $0 might not be correct any more.
16 # However, the name hasn't changed.
17 my $testsrc = top_file("test","recipes",basename($0));
18
19 my $test = catfile(".", "p");
20
21 my $cmd = "openssl";
22
23 my @ciphers =
24     map { chomp; s/^\s+//; s/\s+$//; split /\s+/ }
25     run(app([$cmd, "list", "-cipher-commands"]), capture => 1);
26
27 plan tests => 1 + (scalar @ciphers)*2;
28
29 my $init = ok(copy($testsrc,$test));
30
31 if (!$init) {
32     diag("Trying to copy $testsrc to $test : $!");
33 }
34
35  SKIP: {
36      skip "Not initialized, skipping...", 11 unless $init;
37
38      foreach my $c (@ciphers) {
39          my %variant = ("$c" => [],
40                         "$c base64" => [ "-a" ]);
41
42          foreach my $t (sort keys %variant) {
43              my $cipherfile = "$test.$c.cipher";
44              my $clearfile = "$test.$c.clear";
45              my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
46              my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
47              if ($c eq "cat") {
48                  $cipherfile = "$test.cipher";
49                  $clearfile = "$test.clear";
50                  @e = ( "enc", @{$variant{$t}}, "-e" );
51                  @d = ( "enc", @{$variant{$t}}, "-d" );
52              }
53
54              ok(run(app([$cmd, @e],
55                         stdin => $test, stdout => $cipherfile))
56                 && run(app([$cmd, @d],
57                            stdin => $cipherfile, stdout => $clearfile))
58                 && compare_text($test,$clearfile) == 0, $t);
59              unlink $cipherfile, $clearfile;
60          }
61      }
62 }
63
64 unlink $test;