]>
Commit | Line | Data |
---|---|---|
168c595b | 1 | #! /usr/bin/env perl |
a28d06f3 | 2 | # Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved. |
168c595b DDO |
3 | # Copyright Nokia 2007-2019 |
4 | # Copyright Siemens AG 2015-2019 | |
5 | # | |
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 | |
10 | ||
11 | use strict; | |
12 | use warnings; | |
13 | ||
14 | use POSIX; | |
168c595b | 15 | use File::Compare qw/compare_text/; |
c87bcdbd | 16 | use OpenSSL::Test qw/:DEFAULT with srctop_file srctop_dir bldtop_dir result_file/; |
168c595b | 17 | use OpenSSL::Test::Utils; |
168c595b | 18 | |
5b393802 MC |
19 | BEGIN { |
20 | setup("test_cmp_cli"); | |
21 | } | |
22 | use lib srctop_dir('Configurations'); | |
23 | use lib bldtop_dir('.'); | |
24 | use platform; | |
f91624d3 DDO |
25 | plan skip_all => "These tests are not supported in a fuzz build" |
26 | if config('options') =~ /-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION/; | |
168c595b | 27 | |
713b3f76 | 28 | plan skip_all => "These tests are not supported in a no-cmp build" |
168c595b | 29 | if disabled("cmp"); |
f91624d3 | 30 | |
c87bcdbd | 31 | my $app = bldtop_dir("apps/openssl cmp"); |
168c595b DDO |
32 | |
33 | my @cmp_basic_tests = ( | |
c87bcdbd DDO |
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 ], | |
41 | ); | |
42 | ||
43 | my @cmp_server_tests = ( | |
44 | [ "with polling", [ "-poll_count", "1" ], 1 ], | |
45 | [ "with loader_attic engine", [ "-engine", "loader_attic"], | |
46 | !disabled('dynamic-engine') && | |
47 | !disabled("deprecated-3.0") ] | |
48 | ); | |
49 | ||
50 | plan tests => @cmp_basic_tests + @cmp_server_tests; | |
51 | ||
52 | foreach (@cmp_basic_tests) { | |
53 | my $title = $$_[0]; | |
54 | my $params = $$_[1]; | |
55 | my $expected = $$_[2]; | |
56 | ok($expected == run(cmd([$app, "-config", '""', @$params])), | |
57 | $title); | |
58 | } | |
168c595b | 59 | |
c87bcdbd DDO |
60 | # these use the mock server directly in the cmp app, without TCP |
61 | foreach (@cmp_server_tests) { | |
62 | my $title = $$_[0]; | |
63 | my $extra_args = $$_[1]; | |
64 | my $expected = $$_[2]; | |
c5fc6754 | 65 | my $secret = "pass:test"; |
c87bcdbd | 66 | my $rsp_cert = srctop_file('test', 'certs', 'ee-cert-1024.pem'); |
c5fc6754 | 67 | my $outfile = result_file("test.certout.pem"); |
c87bcdbd DDO |
68 | ok($expected == |
69 | run(cmd([$app, "-config", '""', @$extra_args, | |
168c595b | 70 | "-use_mock_srv", "-srv_ref", "mock server", |
168c595b | 71 | "-srv_secret", $secret, |
168c595b DDO |
72 | "-rsp_cert", $rsp_cert, |
73 | "-cmd", "cr", | |
74 | "-subject", "/CN=any", | |
c87bcdbd | 75 | "-newkey", srctop_file('test', 'certs', 'ee-key-1024.pem'), |
168c595b DDO |
76 | "-secret", $secret, |
77 | "-ref", "client under test", | |
c5fc6754 | 78 | "-certout", $outfile])) |
168c595b | 79 | && compare_text($outfile, $rsp_cert) == 0, |
c87bcdbd | 80 | $title); |
57371e16 | 81 | # not unlinking $outfile |
168c595b | 82 | } |