implement gotwebd test harness
[got-portable.git] / regress / gotd / Makefile
blobaeab4db6f7a50e4200cc5e66ffdc5a664581c22b
1 .include "../../got-version.mk"
3 REGRESS_TARGETS=test_repo_read test_repo_read_group \
4 test_repo_read_denied_user test_repo_read_denied_group \
5 test_repo_read_bad_user test_repo_read_bad_group \
6 test_repo_write test_repo_write_empty test_request_bad \
7 test_repo_write_protected test_repo_write_readonly \
8 test_email_notification test_http_notification \
9 test_git_interop test_email_and_http_notification \
10 test_http_notification_hmac
11 NOOBJ=Yes
12 CLEANFILES=gotd.conf gotd-secrets.conf
14 .PHONY: ensure_root ensure_secrets prepare_test_repo check_test_repo start_gotd
16 GOTD_TEST_ROOT=/tmp
17 GOTD_DEVUSER?=gotdev
18 GOTD_DEVUSER_HOME!=getent passwd $(GOTD_DEVUSER) | cut -d: -f6
19 GOTD_TEST_REPO!?=mktemp -d "$(GOTD_TEST_ROOT)/gotd-test-repo-XXXXXXXXXX"
20 GOTD_TEST_REPO_NAME=test-repo
21 GOTD_TEST_REPO_URL=ssh://${GOTD_DEVUSER}@127.0.0.1/$(GOTD_TEST_REPO_NAME)
22 GOTD_TEST_SMTP_PORT=2525
23 GOTD_TEST_HTTP_PORT=8000
24 GOTD_TEST_HMAC_SECRET!=openssl rand -base64 32
26 GOTD_TEST_USER?=${DOAS_USER}
27 .if empty(GOTD_TEST_USER)
28 GOTD_TEST_USER=${SUDO_USER}
29 .endif
30 .if empty(GOTD_TEST_USER)
31 GOTD_TEST_USER=${USER}
32 .endif
33 GOTD_TEST_USER_HOME!=getent passwd $(GOTD_TEST_USER) | cut -d: -f6
35 # gotd.conf parameters
36 GOTD_USER?=got
37 GOTD_SOCK=${GOTD_DEVUSER_HOME}/gotd.sock
39 .if "${GOT_RELEASE}" == "Yes"
40 PREFIX ?= /usr/local
41 BINDIR ?= ${PREFIX}/sbin
42 .else
43 PREFIX ?= ${GOTD_TEST_USER_HOME}
44 BINDIR ?= ${PREFIX}/bin
45 .endif
47 GOTD_START_CMD?=env ${GOTD_ENV} $(BINDIR)/gotd -vv -f $(PWD)/gotd.conf
48 GOTD_STOP_CMD?=$(BINDIR)/gotctl -f $(GOTD_SOCK) stop
49 GOTD_TRAP=trap "$(GOTD_STOP_CMD)" HUP INT QUIT PIPE TERM
51 GOTD_ENV=GOT_NOTIFY_TIMEOUT=10
53 GOTD_TEST_ENV=GOTD_TEST_ROOT=$(GOTD_TEST_ROOT) \
54 GOTD_TEST_REPO_URL=$(GOTD_TEST_REPO_URL) \
55 GOTD_TEST_REPO_NAME=$(GOTD_TEST_REPO_NAME) \
56 GOTD_TEST_REPO=$(GOTD_TEST_REPO) \
57 GOTD_SOCK=$(GOTD_SOCK) \
58 GOTD_DEVUSER=$(GOTD_DEVUSER) \
59 GOTD_USER=$(GOTD_USER) \
60 GOTD_CONF=$(PWD)/gotd.conf \
61 GOTD_TEST_SMTP_PORT=$(GOTD_TEST_SMTP_PORT) \
62 GOTD_TEST_HTTP_PORT=$(GOTD_TEST_HTTP_PORT) \
63 GOTD_TEST_HMAC_SECRET=$(GOTD_TEST_HMAC_SECRET) \
64 HOME=$(GOTD_TEST_USER_HOME) \
65 PATH=$(GOTD_TEST_USER_HOME)/bin:$(PATH)
67 ensure_root:
68 @if [[ `id -u` -ne 0 ]]; then \
69 echo gotd test suite must be started by root >&2; \
70 false; \
71 fi ; \
72 if [[ "$(GOTD_TEST_USER)" = "root" ]]; then \
73 echo GOTD_TEST_USER must be a non-root user >&2; \
74 false; \
77 ensure_secrets:
78 @echo 'auth flan user flan password password' > $(PWD)/gotd-secrets.conf
79 @echo 'hmac flan ${GOTD_TEST_HMAC_SECRET}' >> $(PWD)/gotd-secrets.conf
80 @chown root:0 $(PWD)/gotd-secrets.conf
81 @chmod 600 $(PWD)/gotd-secrets.conf
83 start_gotd_ro: ensure_root
84 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
85 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
86 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
87 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
88 @echo ' permit ro $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
89 @echo "}" >> $(PWD)/gotd.conf
90 @$(GOTD_TRAP); $(GOTD_START_CMD)
91 @$(GOTD_TRAP); sleep .5
93 start_gotd_implicit_ro: ensure_root
94 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
95 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
96 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
97 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
98 @echo "}" >> $(PWD)/gotd.conf
99 @$(GOTD_TRAP); $(GOTD_START_CMD)
100 @$(GOTD_TRAP); sleep .5
102 start_gotd_ro_group: ensure_root
103 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
104 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
105 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
106 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
107 @echo ' permit ro :$(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
108 @echo "}" >> $(PWD)/gotd.conf
109 @$(GOTD_TRAP); $(GOTD_START_CMD)
110 @$(GOTD_TRAP); sleep .5
112 # try a permit rule followed by a deny rule; last matched rule wins
113 start_gotd_ro_denied_user: ensure_root
114 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
115 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
116 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
117 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
118 @echo ' permit ro $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
119 @echo ' deny $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
120 @echo "}" >> $(PWD)/gotd.conf
121 @$(GOTD_TRAP); $(GOTD_START_CMD)
122 @$(GOTD_TRAP); sleep .5
124 # try a permit rule followed by a deny rule; last matched rule wins
125 start_gotd_ro_denied_group: ensure_root
126 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
127 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
128 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
129 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
130 @echo ' permit ro $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
131 @echo ' deny :$(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
132 @echo "}" >> $(PWD)/gotd.conf
133 @$(GOTD_TRAP); $(GOTD_START_CMD)
134 @$(GOTD_TRAP); sleep .5
136 # $GOTD_DEVUSER should not equal $GOTD_USER
137 start_gotd_ro_bad_user: ensure_root
138 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
139 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
140 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
141 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
142 @echo ' permit ro $(GOTD_USER)' >> $(PWD)/gotd.conf
143 @echo "}" >> $(PWD)/gotd.conf
144 @$(GOTD_TRAP); $(GOTD_START_CMD)
145 @$(GOTD_TRAP); sleep .5
147 # $GOTD_DEVUSER should not be in group wheel
148 start_gotd_ro_bad_group: ensure_root
149 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
150 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
151 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
152 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
153 @echo ' permit ro :wheel' >> $(PWD)/gotd.conf
154 @echo "}" >> $(PWD)/gotd.conf
155 @$(GOTD_TRAP); $(GOTD_START_CMD)
156 @$(GOTD_TRAP); sleep .5
158 start_gotd_rw: ensure_root
159 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
160 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
161 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
162 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
163 @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
164 @echo "}" >> $(PWD)/gotd.conf
165 @$(GOTD_TRAP); $(GOTD_START_CMD)
166 @$(GOTD_TRAP); sleep .5
168 start_gotd_rw_protected: ensure_root
169 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
170 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
171 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
172 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
173 @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
174 @echo ' protect branch "foo"' >> $(PWD)/gotd.conf
175 @echo ' protect tag namespace "refs/tags/"' >> $(PWD)/gotd.conf
176 @echo ' protect branch "refs/heads/main"' >> $(PWD)/gotd.conf
177 @echo "}" >> $(PWD)/gotd.conf
178 @$(GOTD_TRAP); $(GOTD_START_CMD)
179 @$(GOTD_TRAP); sleep .5
181 start_gotd_email_notification: ensure_root
182 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
183 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
184 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
185 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
186 @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
187 @echo ' notify {' >> $(PWD)/gotd.conf
188 @echo -n ' email to ${GOTD_DEVUSER}' >> $(PWD)/gotd.conf
189 @echo ' relay 127.0.0.1 port ${GOTD_TEST_SMTP_PORT}' >> $(PWD)/gotd.conf
190 @echo " }" >> $(PWD)/gotd.conf
191 @echo "}" >> $(PWD)/gotd.conf
192 @$(GOTD_TRAP); $(GOTD_START_CMD)
193 @$(GOTD_TRAP); sleep .5
195 start_gotd_http_notification: ensure_root ensure_secrets
196 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
197 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
198 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
199 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
200 @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
201 @echo ' notify {' >> $(PWD)/gotd.conf
202 @echo ' url "http://localhost:${GOTD_TEST_HTTP_PORT}/" auth flan insecure' >> $(PWD)/gotd.conf
203 @echo " }" >> $(PWD)/gotd.conf
204 @echo "}" >> $(PWD)/gotd.conf
205 @$(GOTD_TRAP); $(GOTD_START_CMD) -s $(PWD)/gotd-secrets.conf
206 @$(GOTD_TRAP); sleep .5
208 start_gotd_email_and_http_notification: ensure_root ensure_secrets
209 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
210 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
211 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
212 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
213 @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
214 @echo ' notify {' >> $(PWD)/gotd.conf
215 @echo ' url "http://localhost:${GOTD_TEST_HTTP_PORT}/" auth flan insecure' >> $(PWD)/gotd.conf
216 @echo -n ' email to ${GOTD_DEVUSER}' >> $(PWD)/gotd.conf
217 @echo ' relay 127.0.0.1 port ${GOTD_TEST_SMTP_PORT}' >> $(PWD)/gotd.conf
218 @echo " }" >> $(PWD)/gotd.conf
219 @echo "}" >> $(PWD)/gotd.conf
220 @$(GOTD_TRAP); $(GOTD_START_CMD) -s $(PWD)/gotd-secrets.conf
221 @$(GOTD_TRAP); sleep .5
223 start_gotd_http_notification_hmac: ensure_root ensure_secrets
224 @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
225 @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
226 @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
227 @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
228 @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
229 @echo ' notify {' >> $(PWD)/gotd.conf
230 @echo ' url "http://localhost:${GOTD_TEST_HTTP_PORT}/" auth flan insecure hmac flan' >> $(PWD)/gotd.conf
231 @echo " }" >> $(PWD)/gotd.conf
232 @echo "}" >> $(PWD)/gotd.conf
233 @$(GOTD_TRAP); $(GOTD_START_CMD) -s $(PWD)/gotd-secrets.conf
234 @$(GOTD_TRAP); sleep .5
236 prepare_test_repo: ensure_root
237 @chown ${GOTD_USER} "${GOTD_TEST_REPO}"
238 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./prepare_test_repo.sh'
240 prepare_test_repo_empty: ensure_root
241 @chown ${GOTD_USER} "${GOTD_TEST_REPO}"
242 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./prepare_test_repo.sh 1'
244 test_repo_read: prepare_test_repo start_gotd_ro
245 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
246 'env $(GOTD_TEST_ENV) sh ./repo_read.sh'
247 @$(GOTD_STOP_CMD) 2>/dev/null
248 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
250 test_repo_read_group: prepare_test_repo start_gotd_ro_group
251 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
252 'env $(GOTD_TEST_ENV) sh ./repo_read.sh'
253 @$(GOTD_STOP_CMD) 2>/dev/null
254 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
256 test_repo_read_denied_user: prepare_test_repo start_gotd_ro_denied_user
257 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
258 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
259 @$(GOTD_STOP_CMD) 2>/dev/null
260 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
262 test_repo_read_denied_group: prepare_test_repo start_gotd_ro_denied_group
263 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
264 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
265 @$(GOTD_STOP_CMD) 2>/dev/null
266 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
268 test_repo_read_bad_user: prepare_test_repo start_gotd_ro_bad_user
269 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
270 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
271 @$(GOTD_STOP_CMD) 2>/dev/null
272 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
274 test_repo_read_bad_group: prepare_test_repo start_gotd_ro_bad_group
275 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
276 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
277 @$(GOTD_STOP_CMD) 2>/dev/null
278 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
280 test_repo_write: prepare_test_repo start_gotd_rw
281 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
282 'env $(GOTD_TEST_ENV) sh ./repo_write.sh'
283 @$(GOTD_STOP_CMD) 2>/dev/null
284 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
286 test_repo_write_empty: prepare_test_repo_empty start_gotd_rw
287 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
288 'env $(GOTD_TEST_ENV) sh ./repo_write_empty.sh'
289 @$(GOTD_STOP_CMD) 2>/dev/null
290 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
292 test_repo_write_protected: prepare_test_repo start_gotd_rw_protected
293 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
294 'env $(GOTD_TEST_ENV) sh ./repo_write_protected.sh'
295 @$(GOTD_STOP_CMD) 2>/dev/null
296 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
298 test_repo_write_readonly: prepare_test_repo_empty start_gotd_implicit_ro
299 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
300 'env $(GOTD_TEST_ENV) sh ./repo_write_readonly.sh'
301 @$(GOTD_STOP_CMD) 2>/dev/null
302 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
304 test_request_bad: prepare_test_repo_empty start_gotd_ro
305 @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
306 'env $(GOTD_TEST_ENV) sh ./request_bad.sh'
307 @$(GOTD_STOP_CMD) 2>/dev/null
309 test_email_notification: prepare_test_repo start_gotd_email_notification
310 @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
311 'env $(GOTD_TEST_ENV) sh ./email_notification.sh'
312 @$(GOTD_STOP_CMD) 2>/dev/null
314 test_http_notification: prepare_test_repo start_gotd_http_notification
315 @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
316 'env $(GOTD_TEST_ENV) sh ./http_notification.sh'
317 @$(GOTD_STOP_CMD) 2>/dev/null
319 test_http_notification_hmac: prepare_test_repo start_gotd_http_notification_hmac
320 @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
321 'env $(GOTD_TEST_ENV) sh ./http_notification_hmac.sh'
322 @$(GOTD_STOP_CMD) 2>/dev/null
324 test_email_and_http_notification: prepare_test_repo start_gotd_email_and_http_notification
325 @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
326 'env $(GOTD_TEST_ENV) sh ./http_notification.sh test_file_changed'
327 @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
328 'env $(GOTD_TEST_ENV) sh ./email_notification.sh test_file_changed'
329 @$(GOTD_STOP_CMD) 2>/dev/null
331 test_git_interop: prepare_test_repo start_gotd_rw
332 @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
333 'env $(GOTD_TEST_ENV) sh ./test_git_interop.sh'
334 @$(GOTD_STOP_CMD) 2>/dev/null
335 @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
337 .include <bsd.regress.mk>