dovecot-2.2-pigeonhole: lib-sieve: metadata extensions: Implemen...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Fri Nov 21 00:24:06 UTC 2014
details: http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/4f53a9230f44
changeset: 1972:4f53a9230f44
user: Stephan Bosch <stephan at rename-it.nl>
date: Fri Nov 21 01:23:15 2014 +0100
description:
lib-sieve: metadata extensions: Implemented proper checking of annotation names everywhere.
Also added testsuite items to test syntax.
diffstat:
Makefile.am | 1 +
src/lib-sieve/plugins/metadata/tst-metadataexists.c | 45 ++++++++++++++++++-
tests/extensions/metadata/errors.svtest | 18 +++++++
tests/extensions/metadata/errors/syntax.sieve | 48 +++++++++++++++++++++
tests/extensions/metadata/execute.svtest | 29 ++++++++++++-
5 files changed, 138 insertions(+), 3 deletions(-)
diffs (215 lines):
diff -r 57b48c0580cd -r 4f53a9230f44 Makefile.am
--- a/Makefile.am Thu Nov 20 01:04:00 2014 +0100
+++ b/Makefile.am Fri Nov 21 01:23:15 2014 +0100
@@ -159,6 +159,7 @@
tests/extensions/duplicate/execute.svtest \
tests/extensions/duplicate/execute-vnd.svtest \
tests/extensions/metadata/execute.svtest \
+ tests/extensions/metadata/errors.svtest \
tests/extensions/vnd.dovecot/debug/execute.svtest \
tests/deprecated/notify/basic.svtest \
tests/deprecated/notify/mailto.svtest \
diff -r 57b48c0580cd -r 4f53a9230f44 src/lib-sieve/plugins/metadata/tst-metadataexists.c
--- a/src/lib-sieve/plugins/metadata/tst-metadataexists.c Thu Nov 20 01:04:00 2014 +0100
+++ b/src/lib-sieve/plugins/metadata/tst-metadataexists.c Fri Nov 21 01:23:15 2014 +0100
@@ -104,10 +104,41 @@
* Test validation
*/
+struct _validate_context {
+ struct sieve_validator *valdtr;
+ struct sieve_command *tst;
+};
+
+static int tst_metadataexists_annotation_validate
+(void *context, struct sieve_ast_argument *arg)
+{
+ struct _validate_context *valctx =
+ (struct _validate_context *)context;
+
+ if ( sieve_argument_is_string_literal(arg) ) {
+ const char *aname = sieve_ast_strlist_strc(arg);
+ const char *error;
+
+ if ( !imap_metadata_verify_entry_name(aname, &error) ) {
+ char *lcerror = t_strdup_noconst(error);
+ lcerror[0] = i_tolower(lcerror[0]);
+ sieve_argument_validate_warning
+ (valctx->valdtr, arg, "%s test: "
+ "specified annotation name `%s' is invalid: %s",
+ sieve_command_identifier(valctx->tst),
+ str_sanitize(aname, 256), lcerror);
+ }
+ }
+
+ return TRUE; /* Can't check at compile time */
+}
+
static bool tst_metadataexists_validate
(struct sieve_validator *valdtr, struct sieve_command *tst)
{
struct sieve_ast_argument *arg = tst->first_positional;
+ struct sieve_ast_argument *aarg;
+ struct _validate_context valctx;
unsigned int arg_index = 1;
if ( sieve_command_is(tst, metadataexists_test) ) {
@@ -127,7 +158,16 @@
return FALSE;
}
- return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
+ if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
+ return FALSE;
+
+ aarg = arg;
+ memset(&valctx, 0, sizeof(valctx));
+ valctx.valdtr = valdtr;
+ valctx.tst = tst;
+
+ return sieve_ast_stringlist_map
+ (&aarg, (void*)&valctx, tst_metadataexists_annotation_validate);
}
/*
@@ -232,7 +272,8 @@
"specified annotation name `%s' is invalid: %s",
(mailbox != NULL ? "metadataexists" : "servermetadataexists"),
str_sanitize(str_c(aname), 256), _lc_error(error));
- continue;
+ all_exist = FALSE;
+ break;;
}
ret = imap_metadata_get(imtrans, str_c(aname), &avalue);
diff -r 57b48c0580cd -r 4f53a9230f44 tests/extensions/metadata/errors.svtest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/metadata/errors.svtest Fri Nov 21 01:23:15 2014 +0100
@@ -0,0 +1,18 @@
+require "vnd.dovecot.testsuite";
+
+require "relational";
+require "comparator-i;ascii-numeric";
+
+/*
+ * Invalid syntax
+ */
+
+test "Invalid Syntax" {
+ if test_script_compile "errors/syntax.sieve" {
+ test_fail "compile should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "27" {
+ test_fail "wrong number of errors reported";
+ }
+}
diff -r 57b48c0580cd -r 4f53a9230f44 tests/extensions/metadata/errors/syntax.sieve
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/metadata/errors/syntax.sieve Fri Nov 21 01:23:15 2014 +0100
@@ -0,0 +1,48 @@
+require "mboxmetadata";
+require "servermetadata";
+
+# 1-4: Used as a command
+metadata;
+metadataexists;
+servermetadata;
+servermetadataexists;
+
+# 5-8: Used with no argument
+if metadata {}
+if metadataexists {}
+if servermetadata {}
+if servermetadataexists {}
+
+# 9-10: Used with one string argument
+if metadata "frop" { }
+if servermetadata "frop" { }
+if metadataexists "frop" { }
+
+# Used with one number argument
+if metadata 13123123 { }
+if servermetadata 123123 { }
+if metadataexists 123123 { }
+if servermetadataexists 123123 {}
+
+# Used with one string list argument
+if metadata ["frop"] { }
+if servermetadata ["frop"] { }
+if metadataexists ["frop"] { }
+
+# Used with unknown tag
+if metadata :frop "frop" { }
+if servermetadata :frop "frop" { }
+if metadataexists :frop "frop" { }
+if servermetadataexists :frop "frop" {}
+
+# Invalid arguments
+if metadata "/private/frop" "friep" {}
+if servermetadata "INBOX" "/private/frop" "friep" {}
+if metadataexists 23 "/private/frop" {}
+if servermetadataexists "INBOX" "/private/frop" {}
+
+# Invalid annotations
+if metadata "INBOX" "frop" "friep" {}
+if servermetadata "frop" "friep" {}
+if metadataexists "INBOX" ["/private/frop", "/friep"] { }
+if servermetadataexists ["/private/frop", "/friep", "/private/friep"] { }
diff -r 57b48c0580cd -r 4f53a9230f44 tests/extensions/metadata/execute.svtest
--- a/tests/extensions/metadata/execute.svtest Thu Nov 20 01:04:00 2014 +0100
+++ b/tests/extensions/metadata/execute.svtest Fri Nov 21 01:23:15 2014 +0100
@@ -35,6 +35,13 @@
}
}
+test "MetadataExists - Invalid" {
+ if metadataexists "INBOX"
+ ["/shared/frop", "/friep", "/private/frml"] {
+ test_fail "metadataexists accepted invalid annotation name";
+ }
+}
+
test "Metadata" {
if not metadata :is "INBOX" "/private/frop" "FROP!" {
test_fail "invalid metadata value for /private/frop";
@@ -58,6 +65,12 @@
}
}
+test "Metadata - Invalid" {
+ if metadata :contains "INBOX" "/frop" "" {
+ test_fail "erroneously found a value for \"/frop\"";
+ }
+}
+
test "ServermetadataExists - None exist" {
if servermetadataexists "/private/frop" {
test_fail "servermetadataexists confirms existence of unknown annotation";
@@ -86,7 +99,14 @@
test "ServermetadataExists - All exist" {
if not servermetadataexists
["/private/frop", "/private/friep", "/private/frml"] {
- test_fail "metadataexists fails to recognize annotations";
+ test_fail "servermetadataexists fails to recognize annotations";
+ }
+}
+
+test "ServermetadataExists - Invalid" {
+ if servermetadataexists
+ ["frop", "/private/friep", "/private/frml"] {
+ test_fail "servermetadataexists accepted invalid annotation name";
}
}
@@ -112,3 +132,10 @@
test_fail "unexpected match for /private/frml";
}
}
+
+test "Servermetadata - Invalid" {
+ if servermetadata :contains "/frop" "" {
+ test_fail "erroneously found a value for \"/frop\"";
+ }
+}
+
More information about the dovecot-cvs
mailing list