summaryrefslogtreecommitdiffstats
path: root/test/functional/tests.bats
blob: 4f2750dcdee3e401ac64681feac83f60ea08eae3 (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
load test_helper

RSPAMC="$BATS_TEST_DIRNAME/../../src/client/rspamc"

@test "Test rspamd using gtube" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf"
	run_rspamd
	run ${RSPAMC} -h localhost:56789 \
		"$BATS_TEST_DIRNAME/messages/gtube.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'Action: reject'
}

@test "Test rspamd encrypted using gtube" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf"
	run_rspamd
	run ${RSPAMC} -h localhost:56789 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		"$BATS_TEST_DIRNAME/messages/gtube.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'Action: reject'
}

@test "Test rspamd spamc gtube" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf"
	run_rspamd
	run perl $BATS_TEST_DIRNAME/cases/spamc.pl "$BATS_TEST_DIRNAME/messages/gtube.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'GTUBE'
}

@test "Test rspamd streamlined gtube" {
	skip
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf"
	run_rspamd
	run perl $BATS_TEST_DIRNAME/cases/http_streamline.pl "$BATS_TEST_DIRNAME/messages/gtube.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'Action: reject'
}

@test "Test rspamd learn" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \
		STATSDIR=${BATS_TMPDIR}
	clear_stats
	run_rspamd
	run ${RSPAMC} -h localhost:56790 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		learn_spam \
		"$BATS_TEST_DIRNAME/messages/spam_message.eml"
	[ "$status" -eq 0 ]
	
	echo $output | egrep 'success.*true'
	
	run ${RSPAMC} -h localhost:56789 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		symbols \
		"$BATS_TEST_DIRNAME/messages/spam_message.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'BAYES_SPAM'
	clear_stats
}

@test "Test rspamd re-learn" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \
		STATSDIR=${BATS_TMPDIR}
	clear_stats
	run_rspamd
	run ${RSPAMC} -h localhost:56790 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		learn_spam \
		"$BATS_TEST_DIRNAME/messages/spam_message.eml"
	[ "$status" -eq 0 ]
	
	echo $output | egrep 'success.*true'
	
	run ${RSPAMC} -h localhost:56790 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		learn_ham \
		"$BATS_TEST_DIRNAME/messages/spam_message.eml"
	[ "$status" -eq 0 ]
	
	echo $output | egrep 'success.*true'
	
	run ${RSPAMC} -h localhost:56789 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		symbols \
		"$BATS_TEST_DIRNAME/messages/spam_message.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'BAYES_HAM'
	clear_stats
}

@test "Test learn message with an empty part" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \
		STATSDIR=${BATS_TMPDIR}
	clear_stats
	run_rspamd
	run ${RSPAMC} -h localhost:56790 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		learn_spam \
		"$BATS_TEST_DIRNAME/messages/empty_part.eml"
	[ "$status" -eq 0 ]
	
	echo $output | egrep 'success.*true'
	
	run ${RSPAMC} -h localhost:56789 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		symbols \
		"$BATS_TEST_DIRNAME/messages/empty_part.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'BAYES_SPAM'
	clear_stats
}

@test "Test learn message with bad statfiles" {
	export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \
		STATSDIR=/non/existent
	run_rspamd
	run ${RSPAMC} -h localhost:56790 \
		--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \
		learn_spam \
		"$BATS_TEST_DIRNAME/messages/empty_part.eml"
	[ "$status" -eq 0 ]
	
	echo $output >&2
	echo $output | egrep 'cannot open backend'
}

@test "Test rspamd dependencies" {
	clear_stats
	sed -e 's|@@LUA_SCRIPT@@|${CURDIR}/functional/cases/deps.lua|' < \
		"$BATS_TEST_DIRNAME/configs/lua_test.conf" > \
		"$BATS_TMPDIR/rspamd.conf"
	export RSPAMD_CONFIG="$BATS_TMPDIR/rspamd.conf" \
		STATSDIR=${BATS_TMPDIR}
	run_rspamd
	run ${RSPAMC} -h localhost:56789 \
		symbols \
		"$BATS_TEST_DIRNAME/messages/spam_message.eml"
	[ "$status" -eq 0 ]
	
	echo $output | grep 'DEP10'
	clear_stats
}