This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 322
/
Makefile
324 lines (296 loc) · 14.3 KB
/
Makefile
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
NAME = hardware/mailserver:testing
all: build-no-cache init fixtures run clean
all-fast: build init fixtures run clean
no-build: init fixtures run clean
build-no-cache:
docker build --no-cache -t $(NAME) .
build:
docker build -t $(NAME) .
init:
-docker rm -f \
mariadb postgres redis openldap \
mailserver_default mailserver_reverse mailserver_ecdsa mailserver_ldap mailserver_ldap2 \
mailserver_traefik_acmev1 mailserver_traefik_acmev2
sleep 2
docker run \
-d \
--name mariadb \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=postfix \
-e MYSQL_USER=postfix \
-e MYSQL_PASSWORD=testpasswd \
-v "`pwd`/test/config/mariadb/struct.sql":/docker-entrypoint-initdb.d/struct.sql \
-v "`pwd`/test/config/mariadb/bind.cnf":/etc/mysql/conf.d/bind.cnf \
-t mysql:5.7
docker run \
-d \
--name postgres \
-e POSTGRES_DB=postfix \
-e POSTGRES_USER=postfix \
-e POSTGRES_PASSWORD=testpasswd \
-v "`pwd`/test/config/postgres":/docker-entrypoint-initdb.d \
-t postgres:10.5-alpine
docker run \
-d \
--name redis \
-t redis:4.0-alpine
docker run \
-d \
--name openldap \
-e LDAP_ORGANISATION="Test LDAP" \
-e LDAP_DOMAIN="domain.tld" \
-e LDAP_ADMIN_PASSWORD="testpasswd" \
-e LDAP_TLS=false \
-v "`pwd`/test/config/ldap/struct.ldif":/container/service/slapd/assets/config/bootstrap/ldif/custom/struct.ldif \
-t osixia/openldap:1.2.2 --copy-service
sleep 10
docker run \
-d \
--name mailserver_default \
--link mariadb:mariadb \
--link redis:redis \
-e DBPASS=testpasswd \
-e RSPAMD_PASSWORD=testpasswd \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e ADD_DOMAINS=domain2.tld,domain3.tld \
-e RECIPIENT_DELIMITER=: \
-e TESTING=true \
-v "`pwd`/test/share/tests":/tmp/tests \
-v "`pwd`/test/share/ssl/rsa":/var/mail/ssl \
-v "`pwd`/test/share/postfix/custom.conf":/var/mail/postfix/custom.conf \
-v "`pwd`/test/share/postfix/sender_access":/var/mail/postfix/sender_access \
-v "`pwd`/test/share/dovecot/conf.d":/var/mail/dovecot/conf.d \
-v "`pwd`/test/share/clamav/unofficial-sigs/user.conf":/var/mail/clamav-unofficial-sigs/user.conf \
-h mail.domain.tld \
-t $(NAME)
docker run \
-d \
--name mailserver_reverse \
--link postgres:postgres \
--link redis:redis \
-e FQDN=mail.domain.tld \
-e DOMAIN=domain.tld \
-e DBDRIVER=pgsql \
-e DBHOST=postgres \
-e DBPORT=5432 \
-e DBPASS=/tmp/passwd/postgres \
-e REDIS_HOST=redis \
-e REDIS_PORT=6379 \
-e REDIS_PASS=/tmp/passwd/redis \
-e RSPAMD_PASSWORD=/tmp/passwd/rspamd \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e VMAIL_SUBDIR=subdir \
-e RELAY_NETWORKS="192.168.0.0/16 172.16.0.0/12 10.0.0.0/8" \
-e DISABLE_CLAMAV=true \
-e DISABLE_SIEVE=true \
-e DISABLE_SIGNING=true \
-e DISABLE_GREYLISTING=true \
-e DISABLE_RATELIMITING=true \
-e DISABLE_DNS_RESOLVER=true \
-e ENABLE_POP3=true \
-e ENABLE_ENCRYPTION=true \
-e ENABLE_FETCHMAIL=true \
-e OPENDKIM_KEY_LENGTH=4096 \
-e TESTING=true \
-v "`pwd`/test/share/tests":/tmp/tests \
-v "`pwd`/test/share/passwd":/tmp/passwd \
-v "`pwd`/test/share/ssl/rsa":/var/mail/ssl \
-v "`pwd`/test/share/sieve/custom.sieve":/var/mail/sieve/custom.sieve \
-v "`pwd`/test/share/letsencrypt":/etc/letsencrypt \
-t $(NAME)
docker run \
-d \
--name mailserver_ldap \
--link openldap \
--link redis:redis \
-e DBDRIVER=ldap \
-e DBHOST=openldap \
-e DBPORT=389 \
-e LDAP_BIND_DN="cn=admin,dc=domain,dc=tld" \
-e LDAP_BIND_PW="testpasswd" \
-e LDAP_DEFAULT_SEARCH_BASE="o=mx,dc=domain,dc=tld" \
-e LDAP_DOMAIN_FILTER="(&(mail=*@%s)(objectClass=mailAccount))" \
-e LDAP_DOMAIN_ATTRIBUTE="mail" \
-e LDAP_DOMAIN_FORMAT="%d" \
-e LDAP_MAILBOX_FILTER="(&(mail=%s)(objectClass=mailAccount))" \
-e LDAP_MAILBOX_ATTRIBUTE="mail" \
-e LDAP_MAILBOX_FORMAT="/var/mail/vhosts/%d/%s/mail/" \
-e LDAP_ALIAS_FILTER="(&(mailalias=%s)(objectClass=mailAccount))" \
-e LDAP_ALIAS_ATTRIBUTE="mail" \
-e LDAP_FORWARD_FILTER="(&(mailalias=%s)(objectClass=mailAlias))" \
-e LDAP_FORWARD_ATTRIBUTE="mail" \
-e LDAP_GROUP_FILTER="(&(mail=%s)(objectClass=mailGroup))" \
-e LDAP_GROUP_ATTRIBUTE="uid" \
-e LDAP_SENDER_FILTER="(&(|(mail=%s)(mailalias=%s))(objectClass=mailAccount))" \
-e LDAP_SENDER_ATTRIBUTE="mail" \
-e LDAP_DOVECOT_USER_ATTRS="=home=/var/mail/vhosts/%d/%n/,=mail=maildir:/var/mail/vhosts/%d/%n/mail/,mailuserquota=quota_rule=*:bytes=%\$$" \
-e LDAP_DOVECOT_USER_FILTER="(&(mail=%u)(objectClass=mailAccount))" \
-e LDAP_DOVECOT_PASS_ATTRS="mail=user,userPassword=password" \
-e LDAP_DOVECOT_PASS_FILTER="(&(mail=%u)(objectClass=mailAccount))" \
-e LDAP_DOVECOT_ITERATE_ATTRS="mail=user" \
-e LDAP_DOVECOT_ITERATE_FILTER="(objectClass=mailAccount)" \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e RSPAMD_PASSWORD=testpasswd \
-e ADD_DOMAINS=domain2.tld,domain3.tld \
-e RECIPIENT_DELIMITER=: \
-e TESTING=true \
-v "`pwd`/test/share/tests":/tmp/tests \
-v "`pwd`/test/share/ssl/rsa":/var/mail/ssl \
-v "`pwd`/test/share/postfix/custom.conf":/var/mail/postfix/custom.conf \
-v "`pwd`/test/share/postfix/sender_access":/var/mail/postfix/sender_access \
-v "`pwd`/test/share/dovecot/conf.d":/var/mail/dovecot/conf.d \
-v "`pwd`/test/share/clamav/unofficial-sigs/user.conf":/var/mail/clamav-unofficial-sigs/user.conf \
-h mail.domain.tld \
-t $(NAME)
docker run \
-d \
--name mailserver_ldap2 \
--link openldap \
--link redis:redis \
-e DBDRIVER=ldap \
-e DBHOST=openldap \
-e DBPORT=389 \
-e LDAP_BIND_DN="cn=admin,dc=domain,dc=tld" \
-e LDAP_BIND_PW="testpasswd" \
-e LDAP_DEFAULT_SEARCH_BASE="o=mx,dc=domain,dc=tld" \
-e LDAP_DOMAIN_FILTER="(&(mail=*@%s)(objectClass=mailAccount))" \
-e LDAP_DOMAIN_ATTRIBUTE="mail" \
-e LDAP_DOMAIN_FORMAT="%d" \
-e LDAP_MAILBOX_FILTER="(&(mail=%s)(objectClass=mailAccount))" \
-e LDAP_MAILBOX_ATTRIBUTE="mail" \
-e LDAP_MAILBOX_FORMAT="/var/mail/vhosts/%d/%s/mail/" \
-e LDAP_ALIAS_FILTER="(&(mailalias=%s)(objectClass=mailAccount))" \
-e LDAP_ALIAS_ATTRIBUTE="mail" \
-e LDAP_SENDER_FILTER="(&(|(mail=%s)(mailalias=%s))(objectClass=mailAccount))" \
-e LDAP_SENDER_ATTRIBUTE="mail" \
-e LDAP_DOVECOT_USER_ATTRS="=home=/var/mail/vhosts/%d/%n/,=mail=maildir:/var/mail/vhosts/%d/%n/mail/,mailuserquota=quota_rule=*:bytes=%\$$" \
-e LDAP_DOVECOT_USER_FILTER="(&(mail=%u)(objectClass=mailAccount))" \
-e LDAP_DOVECOT_PASS_ATTRS="mail=user,userPassword=password" \
-e LDAP_DOVECOT_PASS_FILTER="(&(mail=%u)(objectClass=mailAccount))" \
-e LDAP_DOVECOT_ITERATE_ATTRS="mail=user" \
-e LDAP_DOVECOT_ITERATE_FILTER="(objectClass=mailAccount)" \
-e LDAP_MASTER_USER_ENABLED=true \
-e LDAP_DOVECOT_MASTER_PASS_ATTRS="mail=user,userPassword=password" \
-e LDAP_DOVECOT_MASTER_PASS_FILTER="(&(mail=%u)(st=%{login_user})(objectClass=mailAccount))" \
-e DISABLE_CLAMAV=true \
-e DISABLE_SIEVE=true \
-e DISABLE_SIGNING=true \
-e DISABLE_GREYLISTING=true \
-e DISABLE_RATELIMITING=true \
-e DISABLE_DNS_RESOLVER=true \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e RSPAMD_PASSWORD=testpasswd \
-e ADD_DOMAINS=domain2.tld,domain3.tld \
-e RECIPIENT_DELIMITER=: \
-e TESTING=true \
-v "`pwd`/test/share/tests":/tmp/tests \
-v "`pwd`/test/share/ssl/rsa":/var/mail/ssl \
-v "`pwd`/test/share/postfix/custom.conf":/var/mail/postfix/custom.conf \
-v "`pwd`/test/share/postfix/sender_access":/var/mail/postfix/sender_access \
-v "`pwd`/test/share/dovecot/conf.d":/var/mail/dovecot/conf.d \
-v "`pwd`/test/share/clamav/unofficial-sigs/user.conf":/var/mail/clamav-unofficial-sigs/user.conf \
-h mail.domain.tld \
-t $(NAME)
docker run \
-d \
--name mailserver_ecdsa \
--link mariadb:mariadb \
--link redis:redis \
-e DBPASS=testpasswd \
-e RSPAMD_PASSWORD=testpasswd \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e DISABLE_CLAMAV=true \
-e DISABLE_RSPAMD_MODULE=rbl,mx_check,url_redirector \
-e TESTING=true \
-v "`pwd`/test/share/ssl/ecdsa":/var/mail/ssl \
-v "`pwd`/test/share/postfix/custom.ecdsa.conf":/var/mail/postfix/custom.conf \
-h mail.domain.tld \
-t $(NAME)
docker run \
-d \
--name mailserver_traefik_acmev1 \
--link mariadb:mariadb \
--link redis:redis \
-e DEBUG_MODE=dovecot,postfix \
-e DBPASS=testpasswd \
-e RSPAMD_PASSWORD=testpasswd \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e DISABLE_CLAMAV=true \
-e TESTING=true \
-v "`pwd`/test/share/traefik/acme.v1.json":/etc/letsencrypt/acme/acme.json \
-h mail.domain.tld \
-t $(NAME)
docker run \
-d \
--name mailserver_traefik_acmev2 \
--link mariadb:mariadb \
--link redis:redis \
-e DEBUG_MODE=true \
-e DBPASS=testpasswd \
-e RSPAMD_PASSWORD=testpasswd \
-e VMAILUID=`id -u` \
-e VMAILGID=`id -g` \
-e DISABLE_CLAMAV=true \
-e TESTING=true \
-v "`pwd`/test/share/traefik/acme.v2.json":/etc/letsencrypt/acme/acme.json \
-h mail.domain.tld \
-t $(NAME)
fixtures:
# Wait for clamav unofficial sigs database update (default)
docker exec mailserver_default /bin/sh -c "while [ -f /var/lib/clamav-unofficial-sigs/pid/clamav-unofficial-sigs.pid ] ; do sleep 1 ; done"
# Wait for clamav load databases (default)
docker exec mailserver_default /bin/sh -c "while ! echo PING | nc -z 0.0.0.0 3310 ; do sleep 1 ; done"
# Wait for clamav unofficial sigs database update (ldap)
docker exec mailserver_ldap /bin/sh -c "while [ -f /var/lib/clamav-unofficial-sigs/pid/clamav-unofficial-sigs.pid ] ; do sleep 1 ; done"
# Wait for clamav load databases (ldap)
docker exec mailserver_ldap /bin/sh -c "while ! echo PING | nc -z 0.0.0.0 3310 ; do sleep 1 ; done"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user.txt"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user-spam-learning.txt"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-valid-user-subaddress.txt"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-non-existing-user.txt"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias.txt"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-spam-to-existing-user.txt"
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-virus-to-existing-user.txt"
docker exec mailserver_default /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-user-to-existing-user.txt"
docker exec mailserver_default /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-rejected-user-to-existing-user.txt"
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user.txt"
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-valid-user-subaddress-with-default-separator.txt"
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-non-existing-user.txt"
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias.txt"
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-spam-to-existing-user.txt"
docker exec mailserver_reverse /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-user-to-existing-user.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user-spam-learning.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-valid-user-subaddress.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-non-existing-user.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias-forward.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias-group.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-spam-to-existing-user.txt"
docker exec mailserver_ldap /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-virus-to-existing-user.txt"
docker exec mailserver_ldap /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-user-to-existing-user.txt"
docker exec mailserver_ldap /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-rejected-user-to-existing-user.txt"
docker exec mailserver_ldap2 /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user.txt"
docker exec mailserver_ldap2 /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-valid-user-subaddress.txt"
docker exec mailserver_ldap2 /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-non-existing-user.txt"
docker exec mailserver_ldap2 /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias.txt"
docker exec mailserver_ldap2 /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias-forward.txt"
docker exec mailserver_ldap2 /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias-group.txt"
docker exec mailserver_ldap2 /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-user-to-existing-user.txt"
sleep 2
docker exec mailserver_default /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:993 < /tmp/tests/sieve/trigger-spam-ham-learning.txt"
docker exec mailserver_ldap /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:993 < /tmp/tests/sieve/trigger-spam-ham-learning.txt"
# Wait until all mails have been processed
sleep 10
run:
./test/bats/bin/bats test/tests.bats
clean:
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
docker volume ls -qf dangling=true | xargs -r docker volume rm