summaryrefslogtreecommitdiffstats
path: root/pigeonhole/tests/extensions/editheader/protected.svtest
blob: 148a9c8f33a9051223c534574c43bdec99cc335e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
require "vnd.dovecot.testsuite";

require "variables";
require "encoded-character";
require "editheader";

set "message" text:
Received: by example.com (Postfix, from userid 202)
	id 32A131WFW23QWE4; Mon, 21 Nov 2011 05:25:26 +0200 (EET)
Delivery-date: Mon, 21 Nov 2011 04:26:04 +0100
Auto-Submitted: yes
X-Friep: frop 3
Subject: Frop!
From: stephan@example.com
To: tss@example.com

Frop!
.
;

test_set "message" "${message}";
test "Default protected" {
	if not exists "received" {
		test_fail "received header did not exist in the first place";
	}

	if not exists "auto-submitted" {
		test_fail "auto-submitted header did not exist in the first place";
	}

	deleteheader "received";
	deleteheader "auto-submitted";
	deleteheader "subject";

	if not exists "received" {
		test_fail "protected received header was deleted";
	}

	if not exists "auto-submitted" {
		test_fail "protected auto-submitted header was deleted";
	}

	if exists "subject" {
		test_fail "subject header cannot be protected, but it was not deleted";
	}
}

test_config_set "sieve_editheader_protected" "subject delivery-date x-frop";
test_config_reload :extension "editheader";

test_set "message" "${message}";
test "Configured protected" {
	if not exists "delivery-date" {
		test_fail "received header did not exist in the first place";
	}

	if not exists "subject" {
		test_fail "received header did not exist in the first place";
	}

	if exists "x-frop" {
		test_fail "x-frop header already present";
	}

	deleteheader "delivery-date";
	deleteheader "subject";
	addheader "x-frop" "Frop!";

	if not exists "delivery-date" {
		test_fail "protected delivery-date header was deleted";
	}

	if exists "subject" {
		test_fail "subject header cannot be protected, but it was not deleted";
	}

	if exists "x-frop" {
		test_fail "protected x-frop header was added";
	}
}

test_config_set "sieve_editheader_protected" "";
test_config_set "sieve_editheader_forbid_add" "subject x-frop";
test_config_set "sieve_editheader_forbid_delete" "subject x-friep";
test_config_reload :extension "editheader";

test_set "message" "${message}";
test "Configured forbid_add/forbid_delete" {
	if not exists "delivery-date" {
		test_fail "received header did not exist in the first place";
	}

	if not exists "subject" {
		test_fail "received header did not exist in the first place";
	}

	if not exists "x-friep" {
		test_fail "x-friep header did not exist in the first place";
	}

	if exists "x-frop" {
		test_fail "x-frop header already present";
	}

	deleteheader "delivery-date";
	deleteheader "subject";
	deleteheader "x-friep";

	if exists "delivery-date" {
		test_fail "unprotected delivery-date header was not deleted";
	}

	if exists "subject" {
		test_fail "subject header cannot be protected, but it was not deleted";
	}

	if not exists "x-friep" {
		test_fail "protected x-friep header was deleted";
	}

	addheader "delivery-date" "Yesterday";
	addheader "subject" "Fropfrop!";
	addheader "x-frop" "Frop!";
	addheader "received" text:
by sieve.example.com (My little Sieve script)
id 3jhl22khhf23f; Mon, 24 Aug 2015 04:11:54 -0600;
.
;
	addheader "auto-submitted" "no way";

	if not header "delivery-date" "Yesterday" {
		test_fail "unprotected delivery-date header was not added";
	}

	if not header "subject" "Fropfrop!" {
		test_fail "subject header cannot be protected, but it was not added";
	}

	if exists "x-frop" {
		test_fail "protected x-frop header was added";
	}

	if not header :contains "received" "sieve.example.com" {
		test_fail "received header was not added";
	}

	if not header "auto-submitted" "no way" {
		test_fail "autosubmitted header was not added";
	}
}

/*
 * TEST - Bad header configuration
 */

test_config_set "sieve_editheader_protected" "${unicode:1F4A9} delivery-date";
test_config_reload :extension "editheader";

test_set "message" "${message}";
test "Bad header configuration" {
	if not exists "delivery-date" {
		test_fail "delivery-date header did not exist in the first place";
	}

	deleteheader "delivery-date";

	if not exists "delivery-date" {
		test_fail "protected delivery-date header was deleted";
	}
}

test_config_set "sieve_editheader_protected" "";
test_config_reload :extension "editheader";