81-test_cmp_cli.t 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #! /usr/bin/env perl
  2. # Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
  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. use strict;
  11. use warnings;
  12. use POSIX;
  13. use File::Compare qw/compare_text/;
  14. use OpenSSL::Test qw/:DEFAULT with srctop_file srctop_dir bldtop_dir result_file/;
  15. use OpenSSL::Test::Utils;
  16. BEGIN {
  17. setup("test_cmp_cli");
  18. }
  19. use lib srctop_dir('Configurations');
  20. use lib bldtop_dir('.');
  21. plan skip_all => "These tests are not supported in a fuzz build"
  22. if config('options') =~ /-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION/;
  23. plan skip_all => "These tests are not supported in a no-cmp build"
  24. if disabled("cmp");
  25. my $app = bldtop_dir("apps/openssl cmp");
  26. my @cmp_basic_tests = (
  27. [ "show help", [ "-help" ], 1 ],
  28. [ "CLI option not starting with '-'", [ "days", "1" ], 0 ],
  29. [ "unknown CLI option", [ "-dayss" ], 0 ],
  30. [ "bad int syntax: non-digit", [ "-days", "a/" ], 0 ],
  31. [ "bad int syntax: float", [ "-days", "3.14" ], 0 ],
  32. [ "bad int syntax: trailing garbage", [ "-days", "314_+" ], 0 ],
  33. [ "bad int: out of range", [ "-days", "2147483648" ], 0 ],
  34. );
  35. my @cmp_server_tests = (
  36. [ "with polling", [ "-poll_count", "1" ], 1 ],
  37. [ "with loader_attic engine", [ "-engine", "loader_attic"],
  38. !disabled('dynamic-engine') &&
  39. !disabled("deprecated-3.0") ]
  40. );
  41. plan tests => @cmp_basic_tests + @cmp_server_tests;
  42. foreach (@cmp_basic_tests) {
  43. my $title = $$_[0];
  44. my $params = $$_[1];
  45. my $expected = $$_[2];
  46. ok($expected == run(cmd([$app, "-config", '""', @$params])),
  47. $title);
  48. }
  49. # these use the mock server directly in the cmp app, without TCP
  50. foreach (@cmp_server_tests) {
  51. my $title = $$_[0];
  52. my $extra_args = $$_[1];
  53. my $expected = $$_[2];
  54. my $secret = "pass:test";
  55. my $rsp_cert = srctop_file('test', 'certs', 'ee-cert-1024.pem');
  56. my $outfile = result_file("test.certout.pem");
  57. ok($expected ==
  58. run(cmd([$app, "-config", '""', @$extra_args,
  59. "-use_mock_srv", "-srv_ref", "mock server",
  60. "-srv_secret", $secret,
  61. "-rsp_cert", $rsp_cert,
  62. "-cmd", "cr",
  63. "-subject", "/CN=any",
  64. "-newkey", srctop_file('test', 'certs', 'ee-key-1024.pem'),
  65. "-secret", $secret,
  66. "-ref", "client under test",
  67. "-certout", $outfile]))
  68. && compare_text($outfile, $rsp_cert) == 0,
  69. $title);
  70. # not unlinking $outfile
  71. }