Skip to content
Snippets Groups Projects
Commit 16553960 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Testsuite: restructured and extended tests for the relational extension.

parent 969153d7
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,6 @@ test_cases = \ ...@@ -26,7 +26,6 @@ test_cases = \
tests/match-types/is.svtest \ tests/match-types/is.svtest \
tests/match-types/contains.svtest \ tests/match-types/contains.svtest \
tests/match-types/matches.svtest \ tests/match-types/matches.svtest \
tests/match-types/relational.svtest \
tests/address-parts/subaddress.svtest \ tests/address-parts/subaddress.svtest \
tests/extensions/encoded-character.svtest \ tests/extensions/encoded-character.svtest \
tests/extensions/envelope.svtest \ tests/extensions/envelope.svtest \
...@@ -45,8 +44,11 @@ test_cases = \ ...@@ -45,8 +44,11 @@ test_cases = \
tests/extensions/body/match-values.svtest \ tests/extensions/body/match-values.svtest \
tests/extensions/regex/basic.svtest \ tests/extensions/regex/basic.svtest \
tests/extensions/regex/errors.svtest \ tests/extensions/regex/errors.svtest \
tests/extensions/relational/basic.svtest \
tests/extensions/relational/rfc.svtest \
tests/extensions/relational/errors.svtest \
tests/compile/compile.svtest \ tests/compile/compile.svtest \
tests/compile/compile-examples.svtest \ tests/compile/examples.svtest \
tests/compile/errors.svtest tests/compile/errors.svtest
$(test_cases): $(test_cases):
......
require ["relational", "comparator-i;ascii-numeric", "fileinto"];
if header :value "lt" :comparator "i;ascii-numeric"
["x-priority"] ["3"]
{
fileinto "Priority";
}
elsif address :count "gt" :comparator "i;ascii-numeric"
["to"] ["5"]
{
# everything with more than 5 recipients in the "to" field
# is considered SPAM
fileinto "SPAM";
}
elsif address :value "gt" :all :comparator "i;ascii-casemap"
["from"] ["M"]
{
fileinto "From N-Z";
} else {
fileinto "From A-M";
}
if allof (
address :count "eq" :comparator "i;ascii-numeric"
["to", "cc"] ["1"] ,
address :all :comparator "i;ascii-casemap"
["to", "cc"] ["me@foo.example.com"] )
{
fileinto "Only me";
}
...@@ -49,3 +49,9 @@ test "Sanjay example" { ...@@ -49,3 +49,9 @@ test "Sanjay example" {
test_fail "could not compile"; test_fail "could not compile";
} }
} }
test "Relational extension (RFC5231) example" {
if not test_compile "../../sieve/examples/relational.rfc5231.sieve" {
test_fail "could not compile";
}
}
require "vnd.dovecot.testsuite";
# A bit awkward to test the extension with itself
require "relational";
require "comparator-i;ascii-numeric";
test "Validation errors" {
if test_compile "errors/validation.sieve" {
test_fail "compile should have failed";
}
if test_error :count "ne" "3" {
test_fail "wrong number of errors reported";
}
}
require "relational";
# Not a valid relation (1)
if header :value "gr" "from" "ah" {
keep;
}
# Not a valid relation (1)
if header :count "lf" "from" "eek" {
keep;
}
require "vnd.dovecot.testsuite";
require "relational";
require "comparator-i;ascii-numeric";
test_set "message" text:
Received: ...
Received: ...
Subject: example
To: foo@example.com, baz@example.com
CC: qux@example.com
RFC Example
.
;
test "Example 1" {
# The test:
if not address :count "ge" :comparator "i;ascii-numeric"
["to", "cc"] ["3"] {
test_fail "should have counted three addresses";
}
# would evaluate to true, and the test
if anyof (
address :count "ge" :comparator "i;ascii-numeric"
["to"] ["3"],
address :count "ge" :comparator "i;ascii-numeric"
["cc"] ["3"]
) {
test_fail "should not have counted three addresses";
}
# would evaluate to false.
# To check the number of received fields in the header, the following
# test may be used:
if header :count "ge" :comparator "i;ascii-numeric"
["received"] ["3"] {
test_fail "should not have counted three received headers";
}
# This would evaluate to false. But
if not header :count "ge" :comparator "i;ascii-numeric"
["received", "subject"] ["3"] {
test_fail "should have counted three headers";
}
# would evaluate to true.
# The test:
if header :count "ge" :comparator "i;ascii-numeric"
["to", "cc"] ["3"] {
test_fail "should not have counted three to or cc headers";
}
# will always evaluate to false on an RFC 2822 compliant message
# [RFC2822], since a message can have at most one "to" field and at
# most one "cc" field. This test counts the number of fields, not the
# number of addresses.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.