File: execute.svtest

package info (click to toggle)
dovecot 1%3A2.2.27-3%2Bdeb9u2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 48,520 kB
  • sloc: ansic: 430,475; sh: 17,438; makefile: 6,587; cpp: 1,557; perl: 295; python: 67; xml: 44; pascal: 27
file content (158 lines) | stat: -rw-r--r-- 3,611 bytes parent folder | download | duplicates (4)
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
require "vnd.dovecot.testsuite";
require "vnd.dovecot.execute";
require "vnd.dovecot.debug";
require "variables";
require "relational";
require "environment";
require "encoded-character";

test_set "message" text:
From: stephan@example.com
To: pipe@example.net
Subject: Frop!

Frop!
.
;

test_config_set "sieve_execute_bin_dir" "${tst.path}/../bin";
test_config_reload :extension "vnd.dovecot.execute";
test_result_reset;

test "Execute - bare" {
	execute "program";
}

test_result_reset;
test "Execute - i/-" {
	execute :input "FROP" "frame";
}

test_result_reset;
test "Execute - -/o" {
	execute :output "out" "frame";

	if not string "${out}" "FRAMED {  }" {
		test_fail "wrong string returned: ${out}";
	}
}

test_result_reset;
test "Execute - i/o" {
	execute :input "FROP" :output "out" "frame";

	if not string "${out}" "FRAMED { FROP }" {
		test_fail "wrong string returned: ${out}";
	}
}

test_result_reset;
test "Execute - i/o and arguments" {
	execute :input "FROP" :output "out" "frame" ["FRIEP "];

	if not string "${out}" "FRAMED FRIEP { FROP }" {
		test_fail "wrong string returned: ${out}";
	}
}

test_result_reset;
test "Execute - pipe" {
	execute :pipe :output "msg" "cat";

	if not string :contains "${msg}" "Subject: Frop!" {
		test_fail "wrong string returned: ${out}";
	}
}

test_result_reset;
test "Execute - pipe /dev/stdin" {
	execute :pipe :output "msg" "cat-stdin";

	if not string :contains "${msg}" "Subject: Frop!" {
		test_fail "wrong string returned: ${out}";
	}
}

test_result_reset;
test "Execute - env" {
	test_set "envelope.from" "stephan@sub.example.com";
	test_set "envelope.to" "stephan@sub.example.net";
	test_set "envelope.orig_to" "all@sub.example.net";

	execute :output "out" "env" "SENDER";
	if not string :is "${out}" "stephan@sub.example.com" {
		test_fail "wrong SENDER env returned: '${out}'";
	}

	execute :output "out" "env" "RECIPIENT";
	if not string :is "${out}" "stephan@sub.example.net" {
		test_fail "wrong RECIPIENT env returned: '${out}'";
	}

	execute :output "out" "env" "ORIG_RECIPIENT";
	if not string :is "${out}" "all@sub.example.net" {
		test_fail "wrong ORIG_RECIPIENT env returned: '${out}'";
	}

	execute :output "out" "env" "HOST";
	if not environment :is "host" "${out}" {
		test_fail "wrong HOST env returned: '${out}'";
	}

	execute :output "out" "env" "HOME";
	if string :count "eq" "${out}" "0" {
		test_fail "empty HOME env returned";
	}

	execute :output "out" "env" "USER";
	if string :count "eq" "${out}" "0" {
		test_fail "empty USER env returned";
	}
}

test_result_reset;
test "Execute - used as test" {
	if execute :pipe :output "msg" "dog" {
		test_fail "execute action indicated success with invalid program";
	}

	if not execute :pipe :output "msg" "cat" {
		test_fail "execute action indicated failure with valid program";
	}

	if not string :contains "${msg}" "Subject: Frop!" {
		test_fail "wrong string returned: ${out}";
	}
}
	
test_config_set "sieve_execute_input_eol" "crlf";
test_config_reload :extension "vnd.dovecot.execute";
test_result_reset;
set "out" "";

test "Execute - CRLF" {
	execute
		:input "FROP${hex:0A}FRIEP${hex:0a}"
		:output "out"
		"crlf";

	if not string "${out}" "FROP#${hex:0A}FRIEP#${hex:0a}" {
		test_fail "wrong string returned: '${out}'";
	}
}

test_config_set "sieve_execute_input_eol" "lf";
test_config_reload :extension "vnd.dovecot.execute";
test_result_reset;
set "out" "";

test "Execute - LF" {
	execute
		:input "FROP${hex:0D 0A}FRIEP${hex:0d 0a}"
		:output "out"
		"crlf";

	if not string "${out}" "FROP${hex:0A}FRIEP${hex:0a}" {
		test_fail "wrong string returned: '${out}'";
	}
}