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