2 # Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
3 # Copyright Nokia 2007-2019
4 # Copyright Siemens AG 2015-2019
6 # Licensed under the Apache License 2.0 (the "License"). You may not use
7 # this file except in compliance with the License. You can obtain a copy
8 # in the file LICENSE in the source distribution or at
9 # https://www.openssl.org/source/license.html
15 use File::Compare qw/compare_text/;
16 use OpenSSL::Test qw/:DEFAULT with srctop_file srctop_dir bldtop_dir result_file/;
17 use OpenSSL::Test::Utils;
20 setup("test_cmp_cli");
22 use lib srctop_dir('Configurations');
23 use lib bldtop_dir('.');
25 plan skip_all => "These tests are not supported in a fuzz build"
26 if config('options') =~ /-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION/;
28 plan skip_all => "These tests are not supported in a no-cmp build"
31 my @app = qw(openssl cmp);
33 my @cmp_basic_tests = (
34 [ "show help", [ "-help" ], 1 ],
35 [ "CLI option not starting with '-'", [ "days", "1" ], 0 ],
36 [ "unknown CLI option", [ "-dayss" ], 0 ],
37 [ "bad int syntax: non-digit", [ "-days", "a/" ], 0 ],
38 [ "bad int syntax: float", [ "-days", "3.14" ], 0 ],
39 [ "bad int syntax: trailing garbage", [ "-days", "314_+" ], 0 ],
40 [ "bad int: out of range", [ "-days", "2147483648" ], 0 ],
43 my @cmp_server_tests = (
44 [ "with polling", [ "-poll_count", "1" ], 1 ]
47 # loader_attic doesn't build on VMS, so we don't test it
48 push @cmp_server_tests, (
49 [ "with loader_attic engine", [ "-engine", "loader_attic"], 1 ]
51 unless disabled('loadereng');
53 plan tests => @cmp_basic_tests + @cmp_server_tests;
55 foreach (@cmp_basic_tests) {
58 my $expected = $$_[2];
59 ok($expected == run(app([@app, "-config", '', @$params])),
63 # these use the mock server directly in the cmp app, without TCP
64 foreach (@cmp_server_tests) {
66 my $extra_args = $$_[1];
67 my $expected = $$_[2];
68 my $secret = "pass:test";
69 my $rsp_cert = srctop_file('test', 'certs', 'ee-cert-1024.pem');
70 my $outfile = result_file("test.certout.pem");
72 run(app([@app, "-config", '', @$extra_args,
73 "-use_mock_srv", "-srv_ref", "mock server",
74 "-srv_secret", $secret,
75 "-rsp_cert", $rsp_cert,
77 "-subject", "/CN=any",
78 "-newkey", srctop_file('test', 'certs', 'ee-key-1024.pem'),
80 "-ref", "client under test",
81 "-certout", $outfile]))
82 && compare_text($outfile, $rsp_cert) == 0,
84 # not unlinking $outfile