Home | History | Annotate | Line # | Download | only in recipes
      1  1.1  christos #! /usr/bin/env perl
      2  1.1  christos # Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
      3  1.1  christos # Copyright Nokia 2007-2019
      4  1.1  christos # Copyright Siemens AG 2015-2019
      5  1.1  christos #
      6  1.1  christos # Licensed under the Apache License 2.0 (the "License").  You may not use
      7  1.1  christos # this file except in compliance with the License.  You can obtain a copy
      8  1.1  christos # in the file LICENSE in the source distribution or at
      9  1.1  christos # https://www.openssl.org/source/license.html
     10  1.1  christos 
     11  1.1  christos use strict;
     12  1.1  christos use warnings;
     13  1.1  christos 
     14  1.1  christos use POSIX;
     15  1.1  christos use File::Compare qw/compare_text/;
     16  1.1  christos use OpenSSL::Test qw/:DEFAULT with srctop_file srctop_dir bldtop_dir result_file/;
     17  1.1  christos use OpenSSL::Test::Utils;
     18  1.1  christos 
     19  1.1  christos BEGIN {
     20  1.1  christos     setup("test_cmp_cli");
     21  1.1  christos }
     22  1.1  christos use lib srctop_dir('Configurations');
     23  1.1  christos use lib bldtop_dir('.');
     24  1.1  christos 
     25  1.1  christos plan skip_all => "These tests are not supported in a fuzz build"
     26  1.1  christos     if config('options') =~ /-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION/;
     27  1.1  christos 
     28  1.1  christos plan skip_all => "These tests are not supported in a no-cmp build"
     29  1.1  christos     if disabled("cmp");
     30  1.1  christos 
     31  1.1  christos # Prevent MSys2 filename munging for arguments that look like file paths but
     32  1.1  christos # aren't
     33  1.1  christos $ENV{MSYS2_ARG_CONV_EXCL} = "/CN=";
     34  1.1  christos 
     35  1.1  christos my @app = qw(openssl cmp);
     36  1.1  christos 
     37  1.1  christos my @cmp_basic_tests = (
     38  1.1  christos     [ "show help",                        [ "-help"               ], 1 ],
     39  1.1  christos     [ "CLI option not starting with '-'", [  "days", "1"          ], 0 ],
     40  1.1  christos     [ "unknown CLI option",               [ "-dayss"              ], 0 ],
     41  1.1  christos     [ "bad int syntax: non-digit",        [ "-days", "a/"         ], 0 ],
     42  1.1  christos     [ "bad int syntax: float",            [ "-days", "3.14"       ], 0 ],
     43  1.1  christos     [ "bad int syntax: trailing garbage", [ "-days", "314_+"      ], 0 ],
     44  1.1  christos     [ "bad int: out of range",            [ "-days", "2147483648" ], 0 ],
     45  1.1  christos     );
     46  1.1  christos 
     47  1.1  christos my @cmp_server_tests = (
     48  1.1  christos     [ "with polling",             [ "-poll_count", "1"       ], 1 ]
     49  1.1  christos     );
     50  1.1  christos 
     51  1.1  christos # loader_attic doesn't build on VMS, so we don't test it
     52  1.1  christos push @cmp_server_tests, (
     53  1.1  christos     [ "with loader_attic engine", [ "-engine", "loader_attic"], 1 ]
     54  1.1  christos     )
     55  1.1  christos     unless disabled('loadereng');
     56  1.1  christos 
     57  1.1  christos plan tests => @cmp_basic_tests + @cmp_server_tests;
     58  1.1  christos 
     59  1.1  christos foreach (@cmp_basic_tests) {
     60  1.1  christos     my $title = $$_[0];
     61  1.1  christos     my $params = $$_[1];
     62  1.1  christos     my $expected = $$_[2];
     63  1.1  christos     ok($expected == run(app([@app, "-config", '', @$params])),
     64  1.1  christos        $title);
     65  1.1  christos }
     66  1.1  christos 
     67  1.1  christos # these use the mock server directly in the cmp app, without TCP
     68  1.1  christos foreach (@cmp_server_tests) {
     69  1.1  christos     my $title = $$_[0];
     70  1.1  christos     my $extra_args = $$_[1];
     71  1.1  christos     my $expected = $$_[2];
     72  1.1  christos     my $secret = "pass:test";
     73  1.1  christos     my $rsp_cert = srctop_file('test',  'certs', 'ee-cert-1024.pem');
     74  1.1  christos     my $outfile = result_file("test.certout.pem");
     75  1.1  christos     ok($expected ==
     76  1.1  christos        run(app([@app, "-config", '', @$extra_args,
     77  1.1  christos                 "-use_mock_srv", "-srv_ref", "mock server",
     78  1.1  christos                 "-srv_secret", $secret,
     79  1.1  christos                 "-rsp_cert", $rsp_cert,
     80  1.1  christos                 "-cmd", "cr",
     81  1.1  christos                 "-subject", "/CN=any",
     82  1.1  christos                 "-newkey", srctop_file('test', 'certs', 'ee-key-1024.pem'),
     83  1.1  christos                 "-secret", $secret,
     84  1.1  christos                 "-ref", "client under test",
     85  1.1  christos                 "-certout", $outfile]))
     86  1.1  christos        && compare_text($outfile, $rsp_cert) == 0,
     87  1.1  christos        $title);
     88  1.1  christos     # not unlinking $outfile
     89  1.1  christos }
     90