]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Configutl tests
authorDmitry Belyavskiy <beldmit@gmail.com>
Tue, 8 Apr 2025 13:33:23 +0000 (15:33 +0200)
committerPauli <ppzgs1@gmail.com>
Thu, 8 May 2025 01:05:42 +0000 (11:05 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27290)

18 files changed:
test/recipes/25-test_configutl.t [new file with mode: 0644]
test/recipes/25-test_configutl_data/escapes.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/escapes.cnf.expected [new file with mode: 0644]
test/recipes/25-test_configutl_data/included-file.noncnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.1.d/includes1.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.1.d/includes1.conf [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.1.d/nonconf.bak [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.2.d/main.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.2.d/subincludes.d/subconf.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.cnf.expected1 [new file with mode: 0644]
test/recipes/25-test_configutl_data/includes.cnf.expected2 [new file with mode: 0644]
test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/leading-and-trailing-whitespace.cnf.expected [new file with mode: 0644]
test/recipes/25-test_configutl_data/order.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/order.cnf.expected [new file with mode: 0644]
test/recipes/25-test_configutl_data/variables.cnf [new file with mode: 0644]
test/recipes/25-test_configutl_data/variables.cnf.expected [new file with mode: 0644]

diff --git a/test/recipes/25-test_configutl.t b/test/recipes/25-test_configutl.t
new file mode 100644 (file)
index 0000000..b158ab5
--- /dev/null
@@ -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 (file)
index 0000000..9fe2fbc
--- /dev/null
@@ -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 (file)
index 0000000..3a423b0
--- /dev/null
@@ -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 (file)
index 0000000..51089f5
--- /dev/null
@@ -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 (file)
index 0000000..44c17ec
--- /dev/null
@@ -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 (file)
index 0000000..c6e3c0c
--- /dev/null
@@ -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 (file)
index 0000000..f5835c6
--- /dev/null
@@ -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 (file)
index 0000000..a914101
--- /dev/null
@@ -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 (file)
index 0000000..9cbf6c7
--- /dev/null
@@ -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 (file)
index 0000000..4e08e80
--- /dev/null
@@ -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 (file)
index 0000000..d9f27ac
--- /dev/null
@@ -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 (file)
index 0000000..11b421c
--- /dev/null
@@ -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 (file)
index 0000000..2801bd7
--- /dev/null
@@ -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 (file)
index 0000000..832ad66
--- /dev/null
@@ -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 (file)
index 0000000..89662a1
--- /dev/null
@@ -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 (file)
index 0000000..f7a7a91
--- /dev/null
@@ -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 (file)
index 0000000..0491611
--- /dev/null
@@ -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 (file)
index 0000000..b20bf7b
--- /dev/null
@@ -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