--- /dev/null
+#! /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";
+}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+[included-file]
+present = true
--- /dev/null
+[includes1]
+cnf-file = present
--- /dev/null
+[includes1]
+conf-file = present
--- /dev/null
+[includes1]
+nonconf = not present
--- /dev/null
+[includes2]
+main = present
+
+.include tests/config/include.2.d/subincludes.d
--- /dev/null
+[includes2]
+subconf = absent
--- /dev/null
+openssl_conf = openssl_init
+
+.include = ./includes.1.d
+.include ./includes.2.d
+.include ./nonexistant.d
+.include ./included-file.noncnf
--- /dev/null
+openssl_conf = openssl_init
+
+[included-file]
+present = true
+
+[includes1]
+cnf-file = present
+conf-file = present
+
+[includes2]
+main = present
--- /dev/null
+openssl_conf = openssl_init
+
+[included-file]
+present = true
+
+[includes1]
+conf-file = present
+cnf-file = present
+
+[includes2]
+main = present
--- /dev/null
+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 "
--- /dev/null
+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" "
--- /dev/null
+# 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
--- /dev/null
+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
--- /dev/null
+# 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
--- /dev/null
+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