From 9f020ec313bf3faaf332bfe1844007dbaf5475af Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 14 Mar 2010 12:19:51 +0100
Subject: [PATCH] Spamtest and virustest extensions: discarded whitespace at
 beginning of regexp and added syntax testsuite tests.

---
 Makefile.am                                   |  1 +
 .../spamvirustest/ext-spamvirustest-common.c  |  1 +
 tests/extensions/spamvirustest/errors.svtest  | 15 +++++++++++++++
 .../spamvirustest/errors/syntax-errors.sieve  | 19 +++++++++++++++++++
 .../extensions/spamvirustest/spamtest.svtest  |  2 +-
 5 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 tests/extensions/spamvirustest/errors.svtest
 create mode 100644 tests/extensions/spamvirustest/errors/syntax-errors.sieve

diff --git a/Makefile.am b/Makefile.am
index 41e6907be..59d1fb8d3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -118,6 +118,7 @@ test_cases = \
 	tests/extensions/spamvirustest/spamtest.svtest \
 	tests/extensions/spamvirustest/virustest.svtest \
 	tests/extensions/spamvirustest/spamtestplus.svtest \
+	tests/extensions/spamvirustest/errors.svtest \
 	$(test_unfinished)
 
 $(test_cases):
diff --git a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c
index 2b61a2007..35bc33aa4 100644
--- a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c
+++ b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c
@@ -133,6 +133,7 @@ static bool ext_spamvirustest_header_spec_parse
 		return FALSE;
 	}
 	p++;
+	while ( *p == ' ' || *p == '\t' ) p++;
 
 	spec->regexp_match = TRUE;
 	if ( !_regexp_compile(&spec->regexp, p, &regexp_error) ) {
diff --git a/tests/extensions/spamvirustest/errors.svtest b/tests/extensions/spamvirustest/errors.svtest
new file mode 100644
index 000000000..7e6b794b3
--- /dev/null
+++ b/tests/extensions/spamvirustest/errors.svtest
@@ -0,0 +1,15 @@
+require "vnd.dovecot.testsuite";
+
+require "comparator-i;ascii-numeric";
+require "relational";
+
+test "Syntax errors" {
+	if test_script_compile "errors/syntax-errors.sieve" {
+		test_fail "compile should have failed";
+	}
+
+	if not test_error :count "eq" :comparator "i;ascii-numeric" "5" {
+		test_fail "wrong number of errors reported";
+	}
+}
+
diff --git a/tests/extensions/spamvirustest/errors/syntax-errors.sieve b/tests/extensions/spamvirustest/errors/syntax-errors.sieve
new file mode 100644
index 000000000..82e49ed58
--- /dev/null
+++ b/tests/extensions/spamvirustest/errors/syntax-errors.sieve
@@ -0,0 +1,19 @@
+require "spamtest";
+require "virustest";
+
+# Value not a string
+if spamtest 3 {
+}
+
+# Value not a string
+if virustest 3 {
+}
+
+# Missing value argument
+if spamtest :matches :comparator "i;ascii-casemap" {
+}
+
+# Inappropriate :percent argument
+if spamtest :percent "3" {
+}
+
diff --git a/tests/extensions/spamvirustest/spamtest.svtest b/tests/extensions/spamvirustest/spamtest.svtest
index 917a5cce7..b032d6a69 100644
--- a/tests/extensions/spamvirustest/spamtest.svtest
+++ b/tests/extensions/spamvirustest/spamtest.svtest
@@ -84,7 +84,7 @@ test "Value: low" {
 }
 
 test_config :set "sieve_spamtest_status_header"
-	"X-SpamCheck3:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+	"X-SpamCheck3: [ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
 test_config :reload "spamtest";
 
 test "Value: high" {
-- 
GitLab