dovecot-2.1-pigeonhole: testsuite: editheader extension: added e...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Nov 26 12:49:11 EET 2011


details:   http://hg.rename-it.nl/dovecot-2.1-pigeonhole/rev/df95edf614c4
changeset: 1555:df95edf614c4
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Nov 26 11:49:07 2011 +0100
description:
testsuite: editheader extension: added error tests for header value verification.

diffstat:

 src/lib-sieve/plugins/editheader/cmd-addheader.c     |  25 +++++++++++-
 src/lib-sieve/plugins/editheader/cmd-deleteheader.c  |  13 +++---
 src/lib-sieve/rfc2822.c                              |  13 ++++--
 tests/extensions/editheader/errors.svtest            |  37 ++++++++++++++----
 tests/extensions/editheader/errors/field-value.sieve |  15 +++++++
 5 files changed, 80 insertions(+), 23 deletions(-)

diffs (199 lines):

diff -r 1143c225b528 -r df95edf614c4 src/lib-sieve/plugins/editheader/cmd-addheader.c
--- a/src/lib-sieve/plugins/editheader/cmd-addheader.c	Sat Nov 26 11:29:07 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/cmd-addheader.c	Sat Nov 26 11:49:07 2011 +0100
@@ -107,7 +107,7 @@
 
 		if ( !rfc2822_header_field_name_verify(str_c(fname), str_len(fname)) ) {
 			sieve_argument_validate_error
-				(valdtr, arg, "specified field name `%s' is invalid",
+				(valdtr, arg, "addheader command: specified field name `%s' is invalid",
 					str_sanitize(str_c(fname), 80));
 			return FALSE;
 		}
@@ -125,7 +125,17 @@
 	if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 		return FALSE;
 
-	/* FIXME: validate value if constant */
+	if ( sieve_argument_is_string_literal(arg) ) {
+		string_t *fvalue = sieve_ast_argument_str(arg);
+
+		if ( !rfc2822_header_field_body_verify
+			(str_c(fvalue), str_len(fvalue), TRUE, TRUE) ) {
+			sieve_argument_validate_error
+				(valdtr, arg, "addheader command: specified value `%s' is invalid",
+					str_sanitize(str_c(fvalue), 80));
+			return FALSE;
+		}
+	}
 
 	return TRUE;
 }
@@ -244,11 +254,20 @@
 
 	if ( !rfc2822_header_field_name_verify
 		(str_c(field_name), str_len(field_name)) ) {
-		sieve_runtime_error(renv, NULL, "specified field name `%s' is invalid",
+		sieve_runtime_error(renv, NULL, "addheader action: "
+			"specified field name `%s' is invalid",
 			str_sanitize(str_c(field_name), 80));
 		return SIEVE_EXEC_FAILURE;
 	}
 
+	if ( !rfc2822_header_field_body_verify
+		(str_c(value), str_len(value), TRUE, TRUE) ) {
+		sieve_runtime_error(renv, NULL, "addheader action: "
+			"specified value `%s' is invalid",
+			str_sanitize(str_c(value), 80));
+		return SIEVE_EXEC_FAILURE;
+	}
+
 	/*
 	 * Perform operation
 	 */
diff -r 1143c225b528 -r df95edf614c4 src/lib-sieve/plugins/editheader/cmd-deleteheader.c
--- a/src/lib-sieve/plugins/editheader/cmd-deleteheader.c	Sat Nov 26 11:29:07 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/cmd-deleteheader.c	Sat Nov 26 11:49:07 2011 +0100
@@ -236,7 +236,7 @@
 
 	if ( arg == NULL ) {
 		sieve_command_validate_error(valdtr, cmd, 
-			"the %s %s expects at least one positioal argument, but none was found", 
+			"the %s %s expects at least one positional argument, but none was found", 
 			sieve_command_identifier(cmd), sieve_command_type_name(cmd));
 		return FALSE;
 	}
@@ -253,9 +253,9 @@
 		string_t *fname = sieve_ast_argument_str(arg);
 
 		if ( !rfc2822_header_field_name_verify(str_c(fname), str_len(fname)) ) {
-			sieve_argument_validate_error
-				(valdtr, arg, "specified field name `%s' is invalid",
-					str_sanitize(str_c(fname), 80));
+			sieve_argument_validate_error(valdtr, arg, "deleteheader command:"
+				"specified field name `%s' is invalid",
+				str_sanitize(str_c(fname), 80));
 			return FALSE;
 		}
 	}
@@ -431,7 +431,8 @@
 
 	if ( !rfc2822_header_field_name_verify
 		(str_c(field_name), str_len(field_name)) ) {
-		sieve_runtime_error(renv, NULL, "specified field name `%s' is invalid",
+		sieve_runtime_error(renv, NULL, "deleteheader action: ",
+			"specified field name `%s' is invalid",
 			str_sanitize(str_c(field_name), 80));
 		return SIEVE_EXEC_FAILURE;
 	}
@@ -513,7 +514,7 @@
 		if ( ret == 0 ) {
 			sieve_runtime_trace(renv, 0, "header `%s' not found", str_c(field_name));
 		} else if ( ret < 0 ) {
-			sieve_runtime_warning(renv, NULL, "editheader action: "
+			sieve_runtime_warning(renv, NULL, "deleteheader action: "
 				"failed to delete occurences of header `%s' (this should not happen!)",
 				str_c(field_name));
 		}
diff -r 1143c225b528 -r df95edf614c4 src/lib-sieve/rfc2822.c
--- a/src/lib-sieve/rfc2822.c	Sat Nov 26 11:29:07 2011 +0100
+++ b/src/lib-sieve/rfc2822.c	Sat Nov 26 11:49:07 2011 +0100
@@ -54,11 +54,14 @@
 	 */
 
 	while ( p < pend ) {
-		if ( *p != '\t' && *p < 0x20 )
-			return FALSE;
-
-		if ( (*p == '\r' || *p == '\n') && !allow_crlf )
-			return FALSE;
+		if ( *p < 0x20 ) {
+			if ( (*p == '\r' || *p == '\n') ) {
+				if ( !allow_crlf )
+					return FALSE;
+			} else if ( *p != '\t' ) {
+				return FALSE;
+			}
+		}
 
 		if ( !is8bit && *p > 127 ) {
 			if ( !allow_utf8 )
diff -r 1143c225b528 -r df95edf614c4 tests/extensions/editheader/errors.svtest
--- a/tests/extensions/editheader/errors.svtest	Sat Nov 26 11:29:07 2011 +0100
+++ b/tests/extensions/editheader/errors.svtest	Sat Nov 26 11:49:07 2011 +0100
@@ -13,20 +13,20 @@
 		test_fail "wrong number of errors reported";
 	}
 
-	if not test_error :index 1 :matches "*field name*X-field:*invalid" {
-		test_fail "wrong error reported";
+	if not test_error :index 1 :matches "*field name*X-field:*invalid*" {
+		test_fail "wrong error reported (1)";
 	}
 
-	if not test_error :index 2 :matches "*field name*X field*invalid" {
-		test_fail "wrong error reported";
+	if not test_error :index 2 :matches "*field name*X field*invalid*" {
+		test_fail "wrong error reported (2)";
 	}
 
-	if not test_error :index 3 :matches "*field name*X-field:*invalid" {
-		test_fail "wrong error reported";
+	if not test_error :index 3 :matches "*field name*X-field:*invalid*" {
+		test_fail "wrong error reported (3)";
 	}
 
-	if not test_error :index 4 :matches "*field name*X field*invalid" {
-		test_fail "wrong error reported";
+	if not test_error :index 4 :matches "*field name*X field*invalid*" {
+		test_fail "wrong error reported (4)";
 	}
 }
 
@@ -43,7 +43,26 @@
 		test_fail "wrong number of errors reported";
 	}
 
-	if not test_error :matches "*field name*X-field:*invalid" {
+	if not test_error :matches "*field name*X-field:*invalid*" {
 		test_fail "wrong error reported";
 	}
 }
+
+test "Invalid field value" {
+	if test_script_compile "errors/field-value.sieve" {
+		test_fail "compile should have failed";
+	}
+
+	if not test_error :count "eq" :comparator "i;ascii-numeric" "3" {
+		test_fail "wrong number of errors reported";
+	}
+
+	if not test_error :index 1 :matches "*value*Yeah!?*invalid*" {
+		test_fail "wrong error reported (1)";
+	}
+
+	if not test_error :index 2 :matches "*value*Woah!*invalid*" {
+		test_fail "wrong error reported (2)";
+	}
+}
+
diff -r 1143c225b528 -r df95edf614c4 tests/extensions/editheader/errors/field-value.sieve
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/editheader/errors/field-value.sieve	Sat Nov 26 11:49:07 2011 +0100
@@ -0,0 +1,15 @@
+require "editheader";
+require "encoded-character";
+
+# Ok
+addheader "X-field" "Frop";
+
+# Ok
+addheader "X-field" "Frop
+Frml";
+
+# Invalid 'BELL'
+addheader "X-field" "Yeah!${hex:07}";
+
+# Invalid 'NUL'
+addheader "X-field" "Woah!${hex:00}";


More information about the dovecot-cvs mailing list