From 7b36cdbada7618feea61b81be65d5872753043d9 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 3 Jan 2010 21:41:45 +0100
Subject: [PATCH] Spamtest extension: added various value tests to the
 testsuite.

---
 .../extensions/spamvirustest/spamtest.svtest  | 105 ++++++++++++++++--
 1 file changed, 97 insertions(+), 8 deletions(-)

diff --git a/tests/extensions/spamvirustest/spamtest.svtest b/tests/extensions/spamvirustest/spamtest.svtest
index 6ffa2a2c6..0a6369444 100644
--- a/tests/extensions/spamvirustest/spamtest.svtest
+++ b/tests/extensions/spamvirustest/spamtest.svtest
@@ -1,5 +1,8 @@
 require "vnd.dovecot.testsuite";
 require "spamtest";
+require "relational";
+require "comparator-i;ascii-numeric";
+require "variables";
 
 /*
  * Value
@@ -9,29 +12,32 @@ test_set "message" text:
 From: legitimate@example.com
 To: victim@dovecot.org
 Subject: Not spammish
-X-Company-MailScanner-SpamScore: -1.6 (-)
-X-Company-MailScanner-SpamCheck: 
-	No, score=-1.6 required=5.0 tests=AWL,BAYES_00,HTML_IMAGE_RATIO_02,HTML_MESSAGE,MIME_HTML_MOSTLY
-	autolearn=no version=3.2.5
+X-SpamCheck: No, score=-1.6 required=5.0 autolearn=no version=3.2.5
+X-SpamCheck1: No, score=0.0 required=5.0 autolearn=no version=3.2.5
+X-SpamCheck2: No, score=1.0 required=5.0 autolearn=no version=3.2.5
+X-SpamCheck3: No, score=4.0 required=5.0 autolearn=no version=3.2.5
+X-SpamCheck4: Yes, score=5.0 required=5.0 autolearn=no version=3.2.5
+X-SpamCheck5: Yes, score=7.6 required=5.0 autolearn=no version=3.2.5
 
 Test!
 .
 ;
 
 test_config :set "sieve_spamtest_status_header"
-	"X-Company-MailScanner-SpamCheck: [ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+	"X-SpamCheck:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
 test_config :set "sieve_spamtest_max_header"
-	"X-Company-MailScanner-SpamCheck: [ \\ta-zA-Z]+, score=-?[0-9]+.[0-9]+ required=(-?[0-9]+.[0-9]+)";
+	"X-SpamCheck:[ \\ta-zA-Z]+, score=-?[0-9]+.[0-9]+ required=(-?[0-9]+.[0-9]+)";
 test_config :set "sieve_spamtest_status_type" "value";
 test_config :reload "spamtest";
 
 test "Value: subzero" {
 	if spamtest :is "0" {
-		test_fail "spamtest not configured";
+		test_fail "spamtest not configured or test failed";
 	}
 
 	if not spamtest :is "1" {
-		test_fail "wrong spam value produced";
+		if spamtest :matches "*" { }
+		test_fail "wrong spam value produced: ${1}";
 	}
 
 	if spamtest :is "2" {
@@ -39,3 +45,86 @@ test "Value: subzero" {
 	}
 }
 
+test_config :set "sieve_spamtest_status_header"
+	"X-SpamCheck1:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+test_config :reload "spamtest";
+
+test "Value: zero" {
+	if spamtest :is "0" {
+		test_fail "spamtest not configured or test failed";
+	}
+
+	if not spamtest :is "1" {
+		if spamtest :matches "*" { }
+		test_fail "wrong spam value produced: ${1}";
+	}
+
+	if spamtest :is "2" {
+		test_fail "spam test matches anything";
+	}
+}
+
+test_config :set "sieve_spamtest_status_header"
+	"X-SpamCheck2:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+test_config :reload "spamtest";
+
+test "Value: low" {
+	if spamtest :is "0" {
+		test_fail "spamtest not configured or test failed";
+	}
+
+	if not spamtest :value "gt" "1" {
+		test_fail "too small spam value produced";
+	}
+
+	if not spamtest :value "eq" "2" {
+		if spamtest :matches "*" { }
+		test_fail "wrong spam value produced: ${1}";
+	}
+}
+
+test_config :set "sieve_spamtest_status_header"
+	"X-SpamCheck3:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+test_config :reload "spamtest";
+
+test "Value: high" {
+	if spamtest :is "0" {
+		test_fail "spamtest not configured or test failed";
+	}
+
+	if not spamtest :value "eq" "8" {
+		if spamtest :matches "*" { }
+		test_fail "wrong spam value produced: ${1}";
+	}
+}
+
+test_config :set "sieve_spamtest_status_header"
+	"X-SpamCheck4:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+test_config :reload "spamtest";
+
+test "Value: max" {
+	if spamtest :is "0" {
+		test_fail "spamtest not configured or test failed";
+	}
+
+	if not spamtest :value "eq" "10" {
+		if spamtest :matches "*" { }
+		test_fail "wrong spam value produced: ${1}";
+	}
+}
+
+test_config :set "sieve_spamtest_status_header"
+	"X-SpamCheck5:[ \\ta-zA-Z]+, score=(-?[0-9]+.[0-9]+)";
+test_config :reload "spamtest";
+
+test "Value: past-max" {
+	if spamtest :is "0" {
+		test_fail "spamtest not configured or test failed";
+	}
+
+	if not spamtest :value "eq" "10" {
+		if spamtest :matches "*" { }
+		test_fail "wrong spam value produced: ${1}";
+	}
+}
+
-- 
GitLab