From d6a78f68740c9051e40fd05b64377c1530a247a9 Mon Sep 17 00:00:00 2001
From: Aki Tuomi <aki.tuomi@open-xchange.com>
Date: Thu, 5 Dec 2024 11:23:47 +0200
Subject: [PATCH] tests: Selectively disable UTF-8 failure test with mail UTF-8
 support

---
 Makefile.am                                   | 22 ++++++++++++++++---
 configure.ac                                  |  2 ++
 tests/failures/mailbox-bad-utf8.svtest        |  6 -----
 tests/failures/mailbox-bad-utf8.svtest.in     |  6 +++++
 ...-address.svtest => test-address.svtest.in} | 18 +++++++--------
 5 files changed, 36 insertions(+), 18 deletions(-)
 delete mode 100644 tests/failures/mailbox-bad-utf8.svtest
 create mode 100644 tests/failures/mailbox-bad-utf8.svtest.in
 rename tests/{test-address.svtest => test-address.svtest.in} (97%)

diff --git a/Makefile.am b/Makefile.am
index 8ca026764..53a4d1028 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,9 @@ EXTRA_DIST = \
 	examples \
 	COPYING.LGPL \
 	ChangeLog \
-	update-version.sh
+	update-version.sh \
+	tests/test-address.svtest.in \
+	tests/failures/mailbox-bad-utf8.svtest.in
 
 dist-hook:
 	rm -rf `find $(distdir)/tests -type f -name '*.svbin'`
@@ -56,6 +58,10 @@ else
 test_unfinished =
 endif
 
+test_utf8_cases = \
+		  tests/test-address.svtest \
+		  tests/failures/mailbox-bad-utf8.svtest
+
 test_cases = \
 	tests/testsuite.svtest \
 	tests/control-if.svtest \
@@ -184,7 +190,17 @@ test_cases = \
 	tests/extensions/vnd.dovecot/report/execute.svtest \
 	$(test_unfinished)
 
-$(test_cases):
+
+prepare_test_cases:
+	$(AM_V_at)for case in $(test_utf8_cases); do \
+		if test @HAVE_MAIL_UTF8@ = 1; then \
+		  $(SED) -s -e 's/#UTF8#.*//' $${case}.in > $$case ; \
+		else \
+		  $(SED) -s -e 's/#UTF8#//' $${case}.in > $$case ; \
+		fi; \
+	done
+
+$(test_cases): prepare_test_cases
 	@$(TEST_BIN) $(top_srcdir)/$@
 
 failure_test_cases = \
@@ -214,7 +230,7 @@ extprograms_test_cases = \
 $(extprograms_test_cases):
 	@$(TEST_EXTPROGRAMS_BIN) 	$(top_srcdir)/$@
 
-.PHONY: test test-plugins $(test_cases) $(failure_test_cases) $(extprograms_test_cases)
+.PHONY: test test-plugins $(test_cases) $(failure_test_cases) $(extprograms_test_cases) prepare_test_case
 test: all-am $(test_cases) $(failure_test_cases)
 test-plugins: all-am $(extprograms_test_cases)
 
diff --git a/configure.ac b/configure.ac
index ba24a322e..d406e635c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,6 +49,8 @@ AC_SUBST(BINARY_CFLAGS)
 AC_SUBST(BINARY_LDFLAGS)
 AC_SUBST(LIBDOVECOT_INCLUDE)
 
+DC_HAVE_MAIL_UTF8
+
 AC_SUBST(PIGEONHOLE_ASSET_VERSION, regexp(AC_PACKAGE_VERSION, [^\([0-9]+\)\.\([0-9]+\).\([0-9]+\)], [\1.\2.\3]))
 AS_IF([test $PIGEONHOLE_ASSET_VERSION = "0.0.0"], [
    AC_SUBST([PIGEONHOLE_ASSET_VERSION], "main")
diff --git a/tests/failures/mailbox-bad-utf8.svtest b/tests/failures/mailbox-bad-utf8.svtest
deleted file mode 100644
index ad104e5ab..000000000
--- a/tests/failures/mailbox-bad-utf8.svtest
+++ /dev/null
@@ -1,6 +0,0 @@
-require "vnd.dovecot.testsuite";
-require "encoded-character";
-
-test "Mailbox parameter with bad UTF-8" {
-	test_message :folder "I${hex:9b}BOX" 0;
-}
diff --git a/tests/failures/mailbox-bad-utf8.svtest.in b/tests/failures/mailbox-bad-utf8.svtest.in
new file mode 100644
index 000000000..2b441ed5c
--- /dev/null
+++ b/tests/failures/mailbox-bad-utf8.svtest.in
@@ -0,0 +1,6 @@
+require "vnd.dovecot.testsuite";
+require "encoded-character";
+
+#UTF8# test "Mailbox parameter with bad UTF-8" {
+#UTF8#	test_message :folder "I${hex:9b}BOX" 0;
+#UTF8# }
diff --git a/tests/test-address.svtest b/tests/test-address.svtest.in
similarity index 97%
rename from tests/test-address.svtest
rename to tests/test-address.svtest.in
index 3f7012fe4..1598826c1 100644
--- a/tests/test-address.svtest
+++ b/tests/test-address.svtest.in
@@ -454,17 +454,17 @@ test "Invalid addresses" {
 		test_fail ":localpart matched invalid address";
 	}
 
-	if address :localpart "resent-cc" "jürgen" {
-		test_fail ":localpart matched invalid UTF-8 address";
-	}
+#UTF8#	if address :localpart "resent-cc" "jürgen" {
+#UTF8#		test_fail ":localpart matched invalid UTF-8 address";
+#UTF8#	}
 
 	if address :domain "to" "example.org" {
 		test_fail ":domain matched invalid address";
 	}
 
-	if address :domain "resent-cc" "example.com" {
-		test_fail ":domain matched invalid UTF-8 address";
-	}
+#UTF8#	if address :domain "resent-cc" "example.com" {
+#UTF8#		test_fail ":domain matched invalid UTF-8 address";
+#UTF8#	}
 
 	if not address :is :all "resent-to" "" {
 		test_fail ":all failed to match empty address";
@@ -474,9 +474,9 @@ test "Invalid addresses" {
 		test_fail ":all failed to match invalid address";
 	}
 
-	if not address :is :all "resent-cc" "<jürgen@example.com>" {
-		test_fail ":all failed to match invalid UTF-8 address";
-	}
+#UTF8#	if not address :is :all "resent-cc" "<jürgen@example.com>" {
+#UTF8#		test_fail ":all failed to match invalid UTF-8 address";
+#UTF8#	}
 
 	if address :is :localpart "bcc" "" {
 		test_fail ":localpart matched invalid address";
-- 
GitLab