From 53bab87110beb727a9ea9de920c9a6684ae0c1fc Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 29 Nov 2015 12:16:25 +0100
Subject: [PATCH] lib-sieve: mime/foreverypart: Implemented basic execution
 tests.

---
 Makefile.am                                   |  1 +
 tests/extensions/mime/execute.svtest          | 67 ++++++++++++++++--
 .../mime/execute/foreverypart.sieve           | 15 ++--
 tests/extensions/mime/execute/mime.sieve      | 69 +++++++++++++++++++
 4 files changed, 144 insertions(+), 8 deletions(-)
 create mode 100644 tests/extensions/mime/execute/mime.sieve

diff --git a/Makefile.am b/Makefile.am
index 6fe58623a..3e67d5e7f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -167,6 +167,7 @@ test_cases = \
 	tests/extensions/metadata/execute.svtest \
 	tests/extensions/metadata/errors.svtest \
 	tests/extensions/mime/errors.svtest \
+	tests/extensions/mime/execute.svtest \
 	tests/extensions/mime/content-header.svtest \
 	tests/extensions/vnd.dovecot/debug/execute.svtest \
 	tests/extensions/vnd.dovecot/environment/basic.svtest \
diff --git a/tests/extensions/mime/execute.svtest b/tests/extensions/mime/execute.svtest
index 701d817a4..2ced83b48 100644
--- a/tests/extensions/mime/execute.svtest
+++ b/tests/extensions/mime/execute.svtest
@@ -4,8 +4,51 @@ require "vnd.dovecot.testsuite";
  * Execution testing (currently just meant to trigger any segfaults)
  */
 
-test "Basic" {
-	if not test_script_compile "execute/ihave.sieve" {
+test_set "message" text:
+From: Whomever <whoever@example.com>
+To: Someone <someone@example.com>
+Date: Sat, 10 Oct 2009 00:30:04 +0200
+Subject: whatever
+Content-Type: multipart/mixed; boundary=outer
+
+This is a multi-part message in MIME format.
+
+--outer
+Content-Type: multipart/alternative; boundary=inner
+
+This is a nested multi-part message in MIME format.
+
+--inner
+Content-Type: text/plain; charset="us-ascii"
+
+Hello
+
+--inner
+Content-Type: text/html; charset="us-ascii"
+
+<html><body>Hello</body></html>
+
+--inner--
+
+This is the end of the inner MIME multipart.
+
+--outer
+Content-Type: message/rfc822
+
+From: Someone Else
+Subject: Hello, this is an elaborate request for you to finally say hello
+ already!
+
+Please say Hello
+
+--outer--
+
+This is the end of the outer MIME multipart.
+.
+;
+
+test "Basic - foreverypart" {
+	if not test_script_compile "execute/foreverypart.sieve" {
 		test_fail "script compile failed";
 	}
 
@@ -17,7 +60,23 @@ test "Basic" {
 		test_fail "result execute failed";
 	}
 
-        test_binary_save "ihave-basic";
-        test_binary_load "ihave-basic";
+	test_binary_save "ihave-basic";
+	test_binary_load "ihave-basic";
 }
 
+test "Basic - mime" {
+	if not test_script_compile "execute/mime.sieve" {
+		test_fail "script compile failed";
+	}
+
+	if not test_script_run {
+		test_fail "script run failed";
+	}
+
+	if not test_result_execute {
+		test_fail "result execute failed";
+	}
+
+	test_binary_save "ihave-basic";
+	test_binary_load "ihave-basic";
+}
diff --git a/tests/extensions/mime/execute/foreverypart.sieve b/tests/extensions/mime/execute/foreverypart.sieve
index 0fe84c827..9ae1fba18 100644
--- a/tests/extensions/mime/execute/foreverypart.sieve
+++ b/tests/extensions/mime/execute/foreverypart.sieve
@@ -1,7 +1,14 @@
-require "ihave";
+require "foreverypart";
+require "variables";
 
-if ihave "nonsense-extension" {
-	nonsense_command "Frop!";
+foreverypart {
+	foreverypart {
+		foreverypart {
+			foreverypart {
+				set "a" "a${a}";
+			}
+		}
+	}
 }
 
-redirect "frop@example.com";
+
diff --git a/tests/extensions/mime/execute/mime.sieve b/tests/extensions/mime/execute/mime.sieve
new file mode 100644
index 000000000..dd7fedc02
--- /dev/null
+++ b/tests/extensions/mime/execute/mime.sieve
@@ -0,0 +1,69 @@
+require "mime";
+require "foreverypart";
+require "variables";
+
+if header :contains :mime "Content-Type" "text/plain" {
+	discard;
+}
+if header :mime :type "Content-Type" "text" {
+	discard;
+}
+if header :mime :subtype "Content-Type" "plain" {
+	discard;
+}
+if header :mime :contenttype "Content-Type" "text/plain" {
+	discard;
+}
+if header :mime :param ["frop", "friep"] "Content-Type" "frml" {
+	discard;
+}
+if header :anychild :contains :mime "Content-Type" "text/plain" {
+	discard;
+}
+if header :mime :anychild :type "Content-Type" "text" {
+	discard;
+}
+if header :mime :subtype :anychild "Content-Type" "plain" {
+	discard;
+}
+if header :anychild :mime :contenttype "Content-Type" "text/plain" {
+	discard;
+}
+if header :mime :param ["frop", "friep"] :anychild "Content-Type" "frml" {
+	discard;
+}
+
+foreverypart {
+	foreverypart {
+		if header :contains :mime "Content-Type" "text/plain" {
+			discard;
+		}
+		if header :mime :type "Content-Type" "text" {
+			discard;
+		}
+		if header :mime :subtype "Content-Type" "plain" {
+			discard;
+		}
+		if header :mime :contenttype "Content-Type" "text/plain" {
+			discard;
+		}
+		if header :mime :param ["frop", "friep"] "Content-Type" "frml" {
+			discard;
+		}
+		if header :anychild :contains :mime "Content-Type" "text/plain" {
+			discard;
+		}
+		if header :mime :anychild :type "Content-Type" "text" {
+			discard;
+		}
+		if header :mime :subtype :anychild "Content-Type" "plain" {
+			discard;
+		}
+		if header :anychild :mime :contenttype "Content-Type" "text/plain" {
+			discard;
+		}
+		if header :mime :param ["frop", "friep"] :anychild "Content-Type" "frml" {
+			discard;
+		}
+	}
+}
-- 
GitLab