81-test_cmp_cli.t 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # Prevent MSys2 filename munging for arguments that look like file paths but
  26. # aren't
  27. $ENV{MSYS2_ARG_CONV_EXCL} = "/CN=";
  28. my @app = qw(openssl cmp);
  29. my @cmp_basic_tests = (
  30. [ "show help", [ "-help" ], 1 ],
  31. [ "CLI option not starting with '-'", [ "days", "1" ], 0 ],
  32. [ "unknown CLI option", [ "-dayss" ], 0 ],
  33. [ "bad int syntax: non-digit", [ "-days", "a/" ], 0 ],
  34. [ "bad int syntax: float", [ "-days", "3.14" ], 0 ],
  35. [ "bad int syntax: trailing garbage", [ "-days", "314_+" ], 0 ],
  36. [ "bad int: out of range", [ "-days", "2147483648" ], 0 ],
  37. );
  38. my @cmp_server_tests = (
  39. [ "with polling", [ "-poll_count", "1" ], 1 ]
  40. );
  41. # loader_attic doesn't build on VMS, so we don't test it
  42. push @cmp_server_tests, (
  43. [ "with loader_attic engine", [ "-engine", "loader_attic"], 1 ]
  44. )
  45. unless disabled('loadereng');
  46. plan tests => @cmp_basic_tests + @cmp_server_tests;
  47. foreach (@cmp_basic_tests) {
  48. my $title = $$_[0];
  49. my $params = $$_[1];
  50. my $expected = $$_[2];
  51. ok($expected == run(app([@app, "-config", '', @$params])),
  52. $title);
  53. }
  54. # these use the mock server directly in the cmp app, without TCP
  55. foreach (@cmp_server_tests) {
  56. my $title = $$_[0];
  57. my $extra_args = $$_[1];
  58. my $expected = $$_[2];
  59. my $secret = "pass:test";
  60. my $rsp_cert = srctop_file('test', 'certs', 'ee-cert-1024.pem');
  61. my $outfile = result_file("test.certout.pem");
  62. ok($expected ==
  63. run(app([@app, "-config", '', @$extra_args,
  64. "-use_mock_srv", "-srv_ref", "mock server",
  65. "-srv_secret", $secret,
  66. "-rsp_cert", $rsp_cert,
  67. "-cmd", "cr",
  68. "-subject", "/CN=any",
  69. "-newkey", srctop_file('test', 'certs', 'ee-key-1024.pem'),
  70. "-secret", $secret,
  71. "-ref", "client under test",
  72. "-certout", $outfile]))
  73. && compare_text($outfile, $rsp_cert) == 0,
  74. $title);
  75. # not unlinking $outfile
  76. }