From: Dmitry Belyavskiy Date: Tue, 8 Apr 2025 13:33:23 +0000 (+0200) Subject: Configutl tests X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b43913be7ea11306b74fab000902a53345bc2b49;p=thirdparty%2Fopenssl.git Configutl tests Reviewed-by: Matt Caswell Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/27290) --- diff --git a/test/recipes/25-test_configutl.t b/test/recipes/25-test_configutl.t new file mode 100644 index 00000000000..b158ab5bc7e --- /dev/null +++ b/test/recipes/25-test_configutl.t @@ -0,0 +1,49 @@ +#! /usr/bin/env perl +# Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + + +use strict; +use warnings; + +use File::Spec; +use OpenSSL::Test::Utils; +use OpenSSL::Test qw/:DEFAULT srctop_file/; + +setup("test_configutl"); + +my @tests = qw(escapes.cnf +leading-and-trailing-whitespace.cnf +order.cnf +variables.cnf); + +#includes.cnf is temporary excluded as it depends on #27300 + +plan tests => 2 * (scalar(@tests)) + 1; + +require_ok(srctop_file('test', 'recipes', 'tconversion.pl')); + +foreach my $file (@tests) { + my $path = ($file eq "includes.cnf") ? srctop_file("test", $file) : + srctop_file("test", "recipes", "25-test_configutl_data", $file); + ok(run(app(["openssl", "configutl", + "-config", $path, + "-noheader", "-out", "$file.got"]))); + + if ($file eq "includes.cnf") { + my $cmp1 = cmp_text("$file.got", srctop_file("test", "recipes", "25-test_configutl_data", "$file.expected1")); + my $cmp2 = cmp_text("$file.got", srctop_file("test", "recipes", "25-test_configutl_data", "$file.expected2")); + + is((($cmp1 == 0) || ($cmp2 == 0)), 1, "$file got/expected 1/2"); + } else { + is(cmp_text("$file.got", + srctop_file("test", "recipes", "25-test_configutl_data", "$file.expected")), + 0, "$file got/expected"); + } + + unlink "$file.got"; +} diff --git a/test/recipes/25-test_configutl_data/escapes.cnf b/test/recipes/25-test_configutl_data/escapes.cnf new file mode 100644 index 00000000000..9fe2fbc8c53 --- /dev/null +++ b/test/recipes/25-test_configutl_data/escapes.cnf @@ -0,0 +1,11 @@ +openssl_conf = openssl_init + +[test] +0.recipient = "/C=FI/O=Insta # Demo/CN=Insta Demo CA" +1.recipient = /C=FI/O=Insta \n Demo/CN=Insta Demo CA +2.recipient = /C=FI/O=Insta \b Demo/CN=Insta Demo CA +3.recipient = /C=FI/O=Insta \r Demo/CN=Insta Demo CA +4.recipient = /C=FI/O=Insta \t Demo/CN=Insta Demo CA +5.recipient = "/C=FI/O=Insta ' Demo/CN=Insta Demo CA" +6.recipient = '/C=FI/O=Insta " Demo/CN=Insta Demo CA' +7.recipient = /C=FI/O=Insta \\ Demo/CN=Insta Demo CA diff --git a/test/recipes/25-test_configutl_data/escapes.cnf.expected b/test/recipes/25-test_configutl_data/escapes.cnf.expected new file mode 100644 index 00000000000..3a423b03ee2 --- /dev/null +++ b/test/recipes/25-test_configutl_data/escapes.cnf.expected @@ -0,0 +1,11 @@ +openssl_conf = openssl_init + +[test] +0.recipient = /C=FI/O=Insta \# Demo/CN=Insta Demo CA +1.recipient = /C=FI/O=Insta \n Demo/CN=Insta Demo CA +2.recipient = /C=FI/O=Insta \b Demo/CN=Insta Demo CA +3.recipient = /C=FI/O=Insta \r Demo/CN=Insta Demo CA +4.recipient = /C=FI/O=Insta \t Demo/CN=Insta Demo CA +5.recipient = /C=FI/O=Insta \' Demo/CN=Insta Demo CA +6.recipient = /C=FI/O=Insta \" Demo/CN=Insta Demo CA +7.recipient = /C=FI/O=Insta \\ Demo/CN=Insta Demo CA diff --git a/test/recipes/25-test_configutl_data/included-file.noncnf b/test/recipes/25-test_configutl_data/included-file.noncnf new file mode 100644 index 00000000000..51089f51c36 --- /dev/null +++ b/test/recipes/25-test_configutl_data/included-file.noncnf @@ -0,0 +1,2 @@ +[included-file] +present = true diff --git a/test/recipes/25-test_configutl_data/includes.1.d/includes1.cnf b/test/recipes/25-test_configutl_data/includes.1.d/includes1.cnf new file mode 100644 index 00000000000..44c17ecd6a8 --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.1.d/includes1.cnf @@ -0,0 +1,2 @@ +[includes1] +cnf-file = present diff --git a/test/recipes/25-test_configutl_data/includes.1.d/includes1.conf b/test/recipes/25-test_configutl_data/includes.1.d/includes1.conf new file mode 100644 index 00000000000..c6e3c0c6f69 --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.1.d/includes1.conf @@ -0,0 +1,2 @@ +[includes1] +conf-file = present diff --git a/test/recipes/25-test_configutl_data/includes.1.d/nonconf.bak b/test/recipes/25-test_configutl_data/includes.1.d/nonconf.bak new file mode 100644 index 00000000000..f5835c6347e --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.1.d/nonconf.bak @@ -0,0 +1,2 @@ +[includes1] +nonconf = not present diff --git a/test/recipes/25-test_configutl_data/includes.2.d/main.cnf b/test/recipes/25-test_configutl_data/includes.2.d/main.cnf new file mode 100644 index 00000000000..a91410106ca --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.2.d/main.cnf @@ -0,0 +1,4 @@ +[includes2] +main = present + +.include tests/config/include.2.d/subincludes.d diff --git a/test/recipes/25-test_configutl_data/includes.2.d/subincludes.d/subconf.cnf b/test/recipes/25-test_configutl_data/includes.2.d/subincludes.d/subconf.cnf new file mode 100644 index 00000000000..9cbf6c7e417 --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.2.d/subincludes.d/subconf.cnf @@ -0,0 +1,2 @@ +[includes2] +subconf = absent diff --git a/test/recipes/25-test_configutl_data/includes.cnf b/test/recipes/25-test_configutl_data/includes.cnf new file mode 100644 index 00000000000..4e08e80cf04 --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.cnf @@ -0,0 +1,6 @@ +openssl_conf = openssl_init + +.include = ./includes.1.d +.include ./includes.2.d +.include ./nonexistant.d +.include ./included-file.noncnf diff --git a/test/recipes/25-test_configutl_data/includes.cnf.expected1 b/test/recipes/25-test_configutl_data/includes.cnf.expected1 new file mode 100644 index 00000000000..d9f27ac34dd --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.cnf.expected1 @@ -0,0 +1,11 @@ +openssl_conf = openssl_init + +[included-file] +present = true + +[includes1] +cnf-file = present +conf-file = present + +[includes2] +main = present diff --git a/test/recipes/25-test_configutl_data/includes.cnf.expected2 b/test/recipes/25-test_configutl_data/includes.cnf.expected2 new file mode 100644 index 00000000000..11b421cf903 --- /dev/null +++ b/test/recipes/25-test_configutl_data/includes.cnf.expected2 @@ -0,0 +1,11 @@ +openssl_conf = openssl_init + +[included-file] +present = true + +[includes1] +conf-file = present +cnf-file = present + +[includes2] +main = present diff --git a/test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf b/test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf new file mode 100644 index 00000000000..2801bd725ae --- /dev/null +++ b/test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf @@ -0,0 +1,6 @@ +openssl_conf = openssl_init + +[test] +0.recipient = " /C=FI/O=Insta Demo/CN=Insta Demo CA" +1.recipient = "/C=FI/O=Insta Demo/CN=Insta Demo CA " +2.recipient = " /C=FI/O=Insta Demo/CN=Insta Demo CA " diff --git a/test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf.expected b/test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf.expected new file mode 100644 index 00000000000..832ad6623f2 --- /dev/null +++ b/test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf.expected @@ -0,0 +1,6 @@ +openssl_conf = openssl_init + +[test] +0.recipient = " "/C=FI/O=Insta Demo/CN=Insta Demo CA +1.recipient = /C=FI/O=Insta Demo/CN=Insta Demo CA" " +2.recipient = " "/C=FI/O=Insta Demo/CN=Insta Demo CA" " diff --git a/test/recipes/25-test_configutl_data/order.cnf b/test/recipes/25-test_configutl_data/order.cnf new file mode 100644 index 00000000000..89662a1ab4b --- /dev/null +++ b/test/recipes/25-test_configutl_data/order.cnf @@ -0,0 +1,21 @@ +# vim:ft=conf +openssl_conf = openssl_init + +[def] +# Sections are alphabetically ordered +0.recipient = 0 + +[abc] +# Order within sections is preserved, even if it isn't sorted +7.recipient = 7 +6.recipient = 6 +4.recipient = 4 +3.recipient = 3 +5.recipient = 5 +2.recipient = 2 +1.recipient = 1 +0.recipient = 0 + +[default] +# The default section is consolidated and always printed first +aaatest = value diff --git a/test/recipes/25-test_configutl_data/order.cnf.expected b/test/recipes/25-test_configutl_data/order.cnf.expected new file mode 100644 index 00000000000..f7a7a9113ef --- /dev/null +++ b/test/recipes/25-test_configutl_data/order.cnf.expected @@ -0,0 +1,15 @@ +openssl_conf = openssl_init +aaatest = value + +[abc] +7.recipient = 7 +6.recipient = 6 +4.recipient = 4 +3.recipient = 3 +5.recipient = 5 +2.recipient = 2 +1.recipient = 1 +0.recipient = 0 + +[def] +0.recipient = 0 diff --git a/test/recipes/25-test_configutl_data/variables.cnf b/test/recipes/25-test_configutl_data/variables.cnf new file mode 100644 index 00000000000..04916116b14 --- /dev/null +++ b/test/recipes/25-test_configutl_data/variables.cnf @@ -0,0 +1,33 @@ +# vim:ft=conf +openssl_conf = openssl_init + +default_var = ABC +nested = "\${default_var}" + +[othersection] + +[test] +# These should expand to ABC read from the default section +0.recipient = ${default_var} +1.recipient = $default_var +2.recipient = $(default_var) +# These should expand to DEF as the other section was explicitly referenced +3.recipient = ${othersection::default_var} +4.recipient = $othersection::default_var +5.recipient = $(othersection::default_var) + +[test2] +default_var = GHI +# These should expand to GHI since the local section is always searched first +0.recipient = ${default_var} +1.recipient = $default_var + +[test3] +.pragma dollarid:on +# Out of these, the first should contain the literal "$default_var", the others should expand +0.recipient = literal$default_var +1.recipient = expanded${default_var} +2.recipient = expanded$(default_var) + +[test4] +recipient = literal$nested diff --git a/test/recipes/25-test_configutl_data/variables.cnf.expected b/test/recipes/25-test_configutl_data/variables.cnf.expected new file mode 100644 index 00000000000..b20bf7b2ed3 --- /dev/null +++ b/test/recipes/25-test_configutl_data/variables.cnf.expected @@ -0,0 +1,26 @@ +openssl_conf = openssl_init +default_var = ABC +nested = \${default_var} + +[othersection] + +[test] +0.recipient = ABC +1.recipient = ABC +2.recipient = ABC +3.recipient = ABC +4.recipient = ABC +5.recipient = ABC + +[test2] +default_var = GHI +0.recipient = GHI +1.recipient = GHI + +[test3] +0.recipient = literal\$default_var +1.recipient = expandedABC +2.recipient = expandedABC + +[test4] +recipient = literal\$nested