diff --git a/Makefile.am b/Makefile.am index d2c9cab7f43ea10c61c3a9fc24304bfbe1c015b8..3090495a4140644fb34560f211f603806e849faa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,6 +32,8 @@ test_cases = \ tests/extensions/envelope.svtest \ tests/extensions/variables/basic.svtest \ tests/extensions/variables/match.svtest \ + tests/extensions/variables/modifiers.svtest \ + tests/extensions/variables/quoting.svtest \ tests/extensions/include/variables.svtest \ tests/extensions/imapflags/basic.svtest \ tests/extensions/imapflags/rfc.svtest \ diff --git a/src/lib-sieve/ext-envelope.c b/src/lib-sieve/ext-envelope.c index 0587054740c4e63a7ac505f4a894294debf353cb..ccd1f72c8d03333f7470e81bae5477506a839b0f 100644 --- a/src/lib-sieve/ext-envelope.c +++ b/src/lib-sieve/ext-envelope.c @@ -412,7 +412,7 @@ static int ext_envelope_operation_execute const struct sieve_runtime_env *renv, sieve_size_t *address) { bool result = TRUE; - const struct sieve_comparator *cmp = &i_octet_comparator; + const struct sieve_comparator *cmp = &i_ascii_casemap_comparator; const struct sieve_match_type *mtch = &is_match_type; const struct sieve_address_part *addrp = &all_address_part; struct sieve_match_context *mctx; diff --git a/src/lib-sieve/tst-address.c b/src/lib-sieve/tst-address.c index 5b5bc4308db5ac4376c4aa222ead72776bcc0ba1..4761affcce37c4d8c38775a83129a223f298fd09 100644 --- a/src/lib-sieve/tst-address.c +++ b/src/lib-sieve/tst-address.c @@ -210,7 +210,7 @@ static int tst_address_operation_execute const struct sieve_runtime_env *renv, sieve_size_t *address) { bool result = TRUE; - const struct sieve_comparator *cmp = &i_octet_comparator; + const struct sieve_comparator *cmp = &i_ascii_casemap_comparator; const struct sieve_match_type *mtch = &is_match_type; const struct sieve_address_part *addrp = &all_address_part; struct sieve_match_context *mctx; diff --git a/src/lib-sieve/tst-header.c b/src/lib-sieve/tst-header.c index 3ca310678b6bd4a358877187f012d5befd42e4c3..4335aab70cc6d14449889ba81b5a25dcd2eb5648 100644 --- a/src/lib-sieve/tst-header.c +++ b/src/lib-sieve/tst-header.c @@ -164,7 +164,7 @@ static int tst_header_operation_execute { bool result = TRUE; int opt_code = 0; - const struct sieve_comparator *cmp = &i_octet_comparator; + const struct sieve_comparator *cmp = &i_ascii_casemap_comparator; const struct sieve_match_type *mtch = &is_match_type; struct sieve_match_context *mctx; struct sieve_coded_stringlist *hdr_list; diff --git a/tests/extensions/variables/basic.svtest b/tests/extensions/variables/basic.svtest index c14459feaf5a4d1c5ab121f7d7a519a208faea36..f628480cea6ff491b3f597419fbcf4ff650f2cf9 100644 --- a/tests/extensions/variables/basic.svtest +++ b/tests/extensions/variables/basic.svtest @@ -150,112 +150,6 @@ test "Variables case-insensitive" { } } -/* - * Modifiers - */ - -test "Modifier :lower" { - set :lower "test" "VaLuE"; - - if not string :is "${test}" "value" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifiers :lower :upperfirst" { - set :lower :upperfirst "test" "vAlUe"; - - if string :is "${test}" "value" { - test_fail "modifiers applied with wrong precedence"; - } - - if not string :is "${test}" "Value" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifiers :upperfirst :lower" { - set :upperfirst :lower "test" "vAlUe"; - - if string :is "${test}" "value" { - test_fail "modifiers applied with wrong precedence"; - } - - if not string :is "${test}" "Value" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifier :upper" { - set :upper "test" "vAlUe"; - - if not string :is "${test}" "VALUE" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifiers :upper :lowerfirst" { - set :upper :lowerfirst "test" "VaLuE"; - - if string :is "${test}" "VALUE" { - test_fail "modifiers applied with wrong precedence"; - } - - if not string :is "${test}" "vALUE" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifiers :lowerfirst :upper" { - set :lowerfirst :upper "test" "VaLuE"; - - if string :is "${test}" "VALUE" { - test_fail "modifiers applied with wrong precedence"; - } - - if not string :is "${test}" "vALUE" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifier :length" { - set :length "test" "VaLuE"; - - if not string :is "${test}" "5" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifier :length (elaborate)" { - set "a" "abcdefghijklmnopqrstuvwxyz"; - set "b" "1234567890"; - set :length "test" " ${a}:${b} "; - - if not string :is "${test}" "40" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifier :quotewildcard" { - set :quotewildcard "test" "^^***??**^^"; - - if not string :is "${test}" "^^\\*\\*\\*\\?\\?\\*\\*^^" { - test_fail "modified variable assignment failed"; - } -} - -test "Modifier :length :quotewildcard" { - set :length :quotewildcard "test" "^^***??**^^"; - - if string :is "${test}" "11" { - test_fail "modifiers applied with wrong precedence"; - } - - if not string :is "${test}" "18" { - test_fail "modified variable assignment failed"; - } -} - /* * Variable substitution */ diff --git a/tests/extensions/variables/match.svtest b/tests/extensions/variables/match.svtest index 67c734afc63d93710512ef62243449c6ff70e348..6871924a863201550b8bf20a79a68d9973a911b3 100644 --- a/tests/extensions/variables/match.svtest +++ b/tests/extensions/variables/match.svtest @@ -2,6 +2,143 @@ require "vnd.dovecot.testsuite"; require "variables"; + +/* + * RFC compliance + */ + +# Test acceptance of leading zeroes +test "RFC - leading zeroes" { + if not string :matches "frop:frup:frop" "*:*:*" { + test_fail "failed to match"; + } + + if not string :is "${0000002}" "frup" { + test_fail "incorrect match value (0000002): ${0000002}"; + } +} + +# Test non-greedyness +test "RFC - not greedy" { + if not string :matches "frop.......frop.........frop...." "?*frop*" { + test_fail "failed to match"; + } + + if not string :is "${1}${2}${3}" "frop................frop...." { + test_fail "incorrect match values: ${1}${2}${3}"; + } +} + +# Index out of range +test "RFC - index out of range" { + if not string :matches "test" "*" { + test_fail "failed to match (impossible)"; + } + + if not string :is "${2}" "" { + test_fail "incorrect match value: '${2}'"; + } +} + +# Index 0 +test "RFC - index 0" { + if not string :matches "a b c d e f g" "? ? ? ? ? ? ?" { + test_fail "failed to match"; + } + + if not string :is "${0}" "a b c d e f g" { + test_fail "incorrect match value: ${0}"; + } +} + +# Test short-circuit +test "RFC - test short-circuit" { + if not anyof ( + string :matches "a b c d e f g" "? ?", + string :matches "puk pok puk pok" "pu*ok", + string :matches "snot kip snot" "snot*snot" + ) { + test_fail "failed to match any"; + } + + if string :is "${1}" " kip " { + test_fail "did not short-circuit test execution or intented test failed."; + } + + if not string :is "${1}" "k pok puk p" { + test_fail "incorrect match value: ${1}"; + } +} + +test "RFC - example" { + test_set "message" text: +Subject: [acme-users] [fwd] version 1.0 is out +List-Id: Dovecot Mailing List <dovecot@dovecot.org> +To: coyote@ACME.Example.COM +Fom: stephan@rename-it.nl + +Test message. +. +; + if header :matches "List-ID" "*<*@*" { + if not string "INBOX.lists.${2}" "INBOX.lists.dovecot" { + test_fail "incorrect match value: INBOX.lists.${2}"; + } + } else { + test_fail "failed to match list header"; + } + + # Imagine the header + # Subject: [acme-users] [fwd] version 1.0 is out + if header :matches "Subject" "[*] *" { + # ${1} will hold "acme-users", + # ${2} will hold "[fwd] version 1.0 is out" + + if anyof ( + not string "${1}" "acme-users", + not string "${2}" "[fwd] version 1.0 is out" + ) { + test_fail "invalid match values: ${1} ${2}"; + } + } else { + test_fail "failed to match subject"; + } + + # Imagine the header + # To: coyote@ACME.Example.COM + if address :matches ["To", "Cc"] ["coyote@**.com", + "wile@**.com"] { + # ${0} is the matching address + # ${1} is always the empty string + # ${2} is part of the domain name ("ACME.Example") + + if anyof ( + not string "${0}" "coyote@ACME.Example.COM", + not string "${1}" "", + not string "${2}" "ACME.Example" + ) { + test_fail "invalid match values: ${0}, ${1}, ${2}"; + } + } else { + # Control wouldn't reach this block if any match was + # successful, so no match variables are set at this + # point. + + test_fail "failed to match to address"; + } + + if anyof (true, address :domain :matches "To" "*.com") { + # The second test is never evaluated, so there are + # still no match variables set. + + /* FIXME: not compliant */ + } +} + +/* + * Generic tests + */ + set "match1" "Test of general stupidity"; test "Begin" { @@ -165,3 +302,4 @@ test "Letters words *? first" { test_fail "incorrect match values: ${val}"; } } + diff --git a/tests/extensions/variables/modifiers.svtest b/tests/extensions/variables/modifiers.svtest new file mode 100644 index 0000000000000000000000000000000000000000..04fe9d67cfa0f5ea92fab01d7cb05795cba131a5 --- /dev/null +++ b/tests/extensions/variables/modifiers.svtest @@ -0,0 +1,109 @@ +require "vnd.dovecot.testsuite"; +require "variables"; + +/* + * Modifiers + */ + +test "Modifier :lower" { + set :lower "test" "VaLuE"; + + if not string :is "${test}" "value" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifiers :lower :upperfirst" { + set :lower :upperfirst "test" "vAlUe"; + + if string :is "${test}" "value" { + test_fail "modifiers applied with wrong precedence"; + } + + if not string :is "${test}" "Value" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifiers :upperfirst :lower" { + set :upperfirst :lower "test" "vAlUe"; + + if string :is "${test}" "value" { + test_fail "modifiers applied with wrong precedence"; + } + + if not string :is "${test}" "Value" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifier :upper" { + set :upper "test" "vAlUe"; + + if not string :is "${test}" "VALUE" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifiers :upper :lowerfirst" { + set :upper :lowerfirst "test" "VaLuE"; + + if string :is "${test}" "VALUE" { + test_fail "modifiers applied with wrong precedence"; + } + + if not string :is "${test}" "vALUE" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifiers :lowerfirst :upper" { + set :lowerfirst :upper "test" "VaLuE"; + + if string :is "${test}" "VALUE" { + test_fail "modifiers applied with wrong precedence"; + } + + if not string :is "${test}" "vALUE" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifier :length" { + set :length "test" "VaLuE"; + + if not string :is "${test}" "5" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifier :length (elaborate)" { + set "a" "abcdefghijklmnopqrstuvwxyz"; + set "b" "1234567890"; + set :length "test" " ${a}:${b} "; + + if not string :is "${test}" "40" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifier :quotewildcard" { + set :quotewildcard "test" "^^***??**^^"; + + if not string :is "${test}" "^^\\*\\*\\*\\?\\?\\*\\*^^" { + test_fail "modified variable assignment failed"; + } +} + +test "Modifier :length :quotewildcard" { + set :length :quotewildcard "test" "^^***??**^^"; + + if string :is "${test}" "11" { + test_fail "modifiers applied with wrong precedence"; + } + + if not string :is "${test}" "18" { + test_fail "modified variable assignment failed"; + } +} + diff --git a/tests/match-types/contains.svtest b/tests/match-types/contains.svtest index d8f5122858a696637427148ef99a642c329085ef..719f20581ea9d400185e2d4ca119bcc52cd3a71f 100644 --- a/tests/match-types/contains.svtest +++ b/tests/match-types/contains.svtest @@ -54,7 +54,7 @@ test "Match case-insensitive" { test_fail "match fails to apply correct comparator"; } - if address :contains "from" "RENAME-IT" { + if not address :contains "from" "RENAME-IT" { test_fail "default comparator is wrong"; } }