Blame


1 85b37c72 2022-12-30 thomas .include "../../got-version.mk"
2 85b37c72 2022-12-30 thomas
3 ead70407 2022-11-17 thomas REGRESS_TARGETS=test_repo_read test_repo_read_group \
4 5667a3a5 2022-11-17 thomas test_repo_read_denied_user test_repo_read_denied_group \
5 ead70407 2022-11-17 thomas test_repo_read_bad_user test_repo_read_bad_group \
6 6d7eb4f7 2023-04-04 thomas test_repo_write test_repo_write_empty test_request_bad \
7 6d7eb4f7 2023-04-04 thomas test_repo_write_protected
8 f2900386 2022-10-31 thomas NOOBJ=Yes
9 163d9376 2023-01-19 thomas CLEANFILES=gotd.conf
10 f2900386 2022-10-31 thomas
11 f2900386 2022-10-31 thomas .PHONY: ensure_root prepare_test_repo check_test_repo start_gotd
12 f2900386 2022-10-31 thomas
13 f2900386 2022-10-31 thomas GOTD_TEST_ROOT=/tmp
14 f2900386 2022-10-31 thomas GOTD_DEVUSER?=gotdev
15 a0934206 2022-10-31 thomas GOTD_DEVUSER_HOME!=userinfo $(GOTD_DEVUSER) | awk '/^dir/ {print $$2}'
16 d6e78555 2023-06-01 thomas GOTD_TEST_REPO!?=mktemp -d "$(GOTD_TEST_ROOT)/gotd-test-repo-XXXXXXXXXX"
17 f2900386 2022-10-31 thomas GOTD_TEST_REPO_URL=ssh://${GOTD_DEVUSER}@127.0.0.1/test-repo
18 f2900386 2022-10-31 thomas
19 2bf2e644 2022-12-11 thomas GOTD_TEST_USER?=${DOAS_USER}
20 2bf2e644 2022-12-11 thomas .if empty(GOTD_TEST_USER)
21 2bf2e644 2022-12-11 thomas GOTD_TEST_USER=${SUDO_USER}
22 2bf2e644 2022-12-11 thomas .endif
23 2bf2e644 2022-12-11 thomas .if empty(GOTD_TEST_USER)
24 2bf2e644 2022-12-11 thomas GOTD_TEST_USER=${USER}
25 2bf2e644 2022-12-11 thomas .endif
26 a0934206 2022-10-31 thomas GOTD_TEST_USER_HOME!=userinfo $(GOTD_TEST_USER) | awk '/^dir/ {print $$2}'
27 f2900386 2022-10-31 thomas
28 f2900386 2022-10-31 thomas # gotd.conf parameters
29 f2900386 2022-10-31 thomas GOTD_USER?=got
30 f2900386 2022-10-31 thomas GOTD_SOCK=${GOTD_DEVUSER_HOME}/gotd.sock
31 f2900386 2022-10-31 thomas
32 85b37c72 2022-12-30 thomas .if "${GOT_RELEASE}" == "Yes"
33 85b37c72 2022-12-30 thomas PREFIX ?= /usr/local
34 85b37c72 2022-12-30 thomas BINDIR ?= ${PREFIX}/bin
35 85b37c72 2022-12-30 thomas .else
36 85b37c72 2022-12-30 thomas PREFIX ?= ${GOTD_TEST_USER_HOME}
37 85b37c72 2022-12-30 thomas BINDIR ?= ${PREFIX}/bin
38 85b37c72 2022-12-30 thomas .endif
39 85b37c72 2022-12-30 thomas
40 85b37c72 2022-12-30 thomas GOTD_START_CMD?=$(BINDIR)/gotd -vv -f $(PWD)/gotd.conf
41 85b37c72 2022-12-30 thomas GOTD_STOP_CMD?=$(BINDIR)/gotctl -f $(GOTD_SOCK) stop
42 f2900386 2022-10-31 thomas GOTD_TRAP=trap "$(GOTD_STOP_CMD)" HUP INT QUIT PIPE TERM
43 f2900386 2022-10-31 thomas
44 f2900386 2022-10-31 thomas GOTD_TEST_ENV=GOTD_TEST_ROOT=$(GOTD_TEST_ROOT) \
45 f2900386 2022-10-31 thomas GOTD_TEST_REPO_URL=$(GOTD_TEST_REPO_URL) \
46 f2900386 2022-10-31 thomas GOTD_TEST_REPO=$(GOTD_TEST_REPO) \
47 f2900386 2022-10-31 thomas GOTD_SOCK=$(GOTD_SOCK) \
48 a07c01e0 2022-11-08 thomas GOTD_DEVUSER=$(GOTD_DEVUSER) \
49 f2900386 2022-10-31 thomas HOME=$(GOTD_TEST_USER_HOME) \
50 f2900386 2022-10-31 thomas PATH=$(GOTD_TEST_USER_HOME)/bin:$(PATH)
51 f2900386 2022-10-31 thomas
52 f2900386 2022-10-31 thomas ensure_root:
53 f2900386 2022-10-31 thomas @if [[ `id -u` -ne 0 ]]; then \
54 69e99a59 2022-12-08 thomas echo gotd test suite must be started by root >&2; \
55 f2900386 2022-10-31 thomas false; \
56 69e99a59 2022-12-08 thomas fi ; \
57 69e99a59 2022-12-08 thomas if [[ "$(GOTD_TEST_USER)" = "root" ]]; then \
58 69e99a59 2022-12-08 thomas echo GOTD_TEST_USER must be a non-root user >&2; \
59 69e99a59 2022-12-08 thomas false; \
60 f2900386 2022-10-31 thomas fi
61 f2900386 2022-10-31 thomas
62 729a7e24 2022-11-17 thomas start_gotd_ro: ensure_root
63 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
64 f2900386 2022-10-31 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
65 f2900386 2022-10-31 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
66 f2900386 2022-10-31 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
67 729a7e24 2022-11-17 thomas @echo ' permit ro $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
68 f2900386 2022-10-31 thomas @echo "}" >> $(PWD)/gotd.conf
69 f2900386 2022-10-31 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
70 f2900386 2022-10-31 thomas @$(GOTD_TRAP); sleep .5
71 f2900386 2022-10-31 thomas
72 ff260661 2022-11-17 thomas start_gotd_ro_group: ensure_root
73 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
74 ff260661 2022-11-17 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
75 ff260661 2022-11-17 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
76 ff260661 2022-11-17 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
77 ff260661 2022-11-17 thomas @echo ' permit ro :$(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
78 ff260661 2022-11-17 thomas @echo "}" >> $(PWD)/gotd.conf
79 ff260661 2022-11-17 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
80 ff260661 2022-11-17 thomas @$(GOTD_TRAP); sleep .5
81 ff260661 2022-11-17 thomas
82 b40156b3 2022-11-17 thomas # try a permit rule followed by a deny rule; last matched rule wins
83 b40156b3 2022-11-17 thomas start_gotd_ro_denied_user: ensure_root
84 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
85 b40156b3 2022-11-17 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
86 b40156b3 2022-11-17 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
87 b40156b3 2022-11-17 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
88 b40156b3 2022-11-17 thomas @echo ' permit ro $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
89 b40156b3 2022-11-17 thomas @echo ' deny $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
90 b40156b3 2022-11-17 thomas @echo "}" >> $(PWD)/gotd.conf
91 b40156b3 2022-11-17 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
92 b40156b3 2022-11-17 thomas @$(GOTD_TRAP); sleep .5
93 b40156b3 2022-11-17 thomas
94 5667a3a5 2022-11-17 thomas # try a permit rule followed by a deny rule; last matched rule wins
95 5667a3a5 2022-11-17 thomas start_gotd_ro_denied_group: ensure_root
96 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
97 5667a3a5 2022-11-17 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
98 5667a3a5 2022-11-17 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
99 5667a3a5 2022-11-17 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
100 5667a3a5 2022-11-17 thomas @echo ' permit ro $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
101 5667a3a5 2022-11-17 thomas @echo ' deny :$(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
102 5667a3a5 2022-11-17 thomas @echo "}" >> $(PWD)/gotd.conf
103 5667a3a5 2022-11-17 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
104 5667a3a5 2022-11-17 thomas @$(GOTD_TRAP); sleep .5
105 5667a3a5 2022-11-17 thomas
106 ead70407 2022-11-17 thomas # $GOTD_DEVUSER should not equal $GOTD_USER
107 ead70407 2022-11-17 thomas start_gotd_ro_bad_user: ensure_root
108 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
109 ead70407 2022-11-17 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
110 ead70407 2022-11-17 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
111 ead70407 2022-11-17 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
112 ead70407 2022-11-17 thomas @echo ' permit ro $(GOTD_USER)' >> $(PWD)/gotd.conf
113 ead70407 2022-11-17 thomas @echo "}" >> $(PWD)/gotd.conf
114 ead70407 2022-11-17 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
115 ead70407 2022-11-17 thomas @$(GOTD_TRAP); sleep .5
116 ead70407 2022-11-17 thomas
117 ff260661 2022-11-17 thomas # $GOTD_DEVUSER should not be in group wheel
118 ff260661 2022-11-17 thomas start_gotd_ro_bad_group: ensure_root
119 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
120 ff260661 2022-11-17 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
121 ff260661 2022-11-17 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
122 ff260661 2022-11-17 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
123 ff260661 2022-11-17 thomas @echo ' permit ro :wheel' >> $(PWD)/gotd.conf
124 ff260661 2022-11-17 thomas @echo "}" >> $(PWD)/gotd.conf
125 ff260661 2022-11-17 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
126 ff260661 2022-11-17 thomas @$(GOTD_TRAP); sleep .5
127 ff260661 2022-11-17 thomas
128 729a7e24 2022-11-17 thomas start_gotd_rw: ensure_root
129 f9a4feb6 2023-01-06 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
130 729a7e24 2022-11-17 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
131 729a7e24 2022-11-17 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
132 729a7e24 2022-11-17 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
133 729a7e24 2022-11-17 thomas @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
134 729a7e24 2022-11-17 thomas @echo "}" >> $(PWD)/gotd.conf
135 729a7e24 2022-11-17 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
136 729a7e24 2022-11-17 thomas @$(GOTD_TRAP); sleep .5
137 729a7e24 2022-11-17 thomas
138 6d7eb4f7 2023-04-04 thomas start_gotd_rw_protected: ensure_root
139 6d7eb4f7 2023-04-04 thomas @echo 'listen on "$(GOTD_SOCK)"' > $(PWD)/gotd.conf
140 6d7eb4f7 2023-04-04 thomas @echo "user $(GOTD_USER)" >> $(PWD)/gotd.conf
141 6d7eb4f7 2023-04-04 thomas @echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
142 6d7eb4f7 2023-04-04 thomas @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
143 6d7eb4f7 2023-04-04 thomas @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
144 6d7eb4f7 2023-04-04 thomas @echo ' protect branch "foo"' >> $(PWD)/gotd.conf
145 6d7eb4f7 2023-04-04 thomas @echo ' protect tag namespace "refs/tags/"' >> $(PWD)/gotd.conf
146 6d7eb4f7 2023-04-04 thomas @echo ' protect branch "refs/heads/main"' >> $(PWD)/gotd.conf
147 6d7eb4f7 2023-04-04 thomas @echo "}" >> $(PWD)/gotd.conf
148 6d7eb4f7 2023-04-04 thomas @$(GOTD_TRAP); $(GOTD_START_CMD)
149 6d7eb4f7 2023-04-04 thomas @$(GOTD_TRAP); sleep .5
150 6d7eb4f7 2023-04-04 thomas
151 f2900386 2022-10-31 thomas prepare_test_repo: ensure_root
152 f2900386 2022-10-31 thomas @chown ${GOTD_USER} "${GOTD_TEST_REPO}"
153 f2900386 2022-10-31 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./prepare_test_repo.sh'
154 f2900386 2022-10-31 thomas
155 a07c01e0 2022-11-08 thomas prepare_test_repo_empty: ensure_root
156 a07c01e0 2022-11-08 thomas @chown ${GOTD_USER} "${GOTD_TEST_REPO}"
157 a07c01e0 2022-11-08 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./prepare_test_repo.sh 1'
158 a07c01e0 2022-11-08 thomas
159 729a7e24 2022-11-17 thomas test_repo_read: prepare_test_repo start_gotd_ro
160 f2900386 2022-10-31 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
161 f2900386 2022-10-31 thomas 'env $(GOTD_TEST_ENV) sh ./repo_read.sh'
162 f2900386 2022-10-31 thomas @$(GOTD_STOP_CMD) 2>/dev/null
163 f2900386 2022-10-31 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
164 f2900386 2022-10-31 thomas
165 ff260661 2022-11-17 thomas test_repo_read_group: prepare_test_repo start_gotd_ro_group
166 ff260661 2022-11-17 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
167 ff260661 2022-11-17 thomas 'env $(GOTD_TEST_ENV) sh ./repo_read.sh'
168 ff260661 2022-11-17 thomas @$(GOTD_STOP_CMD) 2>/dev/null
169 ff260661 2022-11-17 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
170 ff260661 2022-11-17 thomas
171 b40156b3 2022-11-17 thomas test_repo_read_denied_user: prepare_test_repo start_gotd_ro_denied_user
172 b40156b3 2022-11-17 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
173 b40156b3 2022-11-17 thomas 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
174 b40156b3 2022-11-17 thomas @$(GOTD_STOP_CMD) 2>/dev/null
175 b40156b3 2022-11-17 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
176 b40156b3 2022-11-17 thomas
177 5667a3a5 2022-11-17 thomas test_repo_read_denied_group: prepare_test_repo start_gotd_ro_denied_group
178 5667a3a5 2022-11-17 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
179 5667a3a5 2022-11-17 thomas 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
180 5667a3a5 2022-11-17 thomas @$(GOTD_STOP_CMD) 2>/dev/null
181 5667a3a5 2022-11-17 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
182 5667a3a5 2022-11-17 thomas
183 ead70407 2022-11-17 thomas test_repo_read_bad_user: prepare_test_repo start_gotd_ro_bad_user
184 ead70407 2022-11-17 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
185 ead70407 2022-11-17 thomas 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
186 ead70407 2022-11-17 thomas @$(GOTD_STOP_CMD) 2>/dev/null
187 ead70407 2022-11-17 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
188 ead70407 2022-11-17 thomas
189 ff260661 2022-11-17 thomas test_repo_read_bad_group: prepare_test_repo start_gotd_ro_bad_group
190 ff260661 2022-11-17 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
191 ff260661 2022-11-17 thomas 'env $(GOTD_TEST_ENV) sh ./repo_read_access_denied.sh'
192 ff260661 2022-11-17 thomas @$(GOTD_STOP_CMD) 2>/dev/null
193 ff260661 2022-11-17 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
194 ff260661 2022-11-17 thomas
195 729a7e24 2022-11-17 thomas test_repo_write: prepare_test_repo start_gotd_rw
196 f2900386 2022-10-31 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
197 f2900386 2022-10-31 thomas 'env $(GOTD_TEST_ENV) sh ./repo_write.sh'
198 f2900386 2022-10-31 thomas @$(GOTD_STOP_CMD) 2>/dev/null
199 f2900386 2022-10-31 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
200 a07c01e0 2022-11-08 thomas
201 729a7e24 2022-11-17 thomas test_repo_write_empty: prepare_test_repo_empty start_gotd_rw
202 a07c01e0 2022-11-08 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
203 a07c01e0 2022-11-08 thomas 'env $(GOTD_TEST_ENV) sh ./repo_write_empty.sh'
204 a07c01e0 2022-11-08 thomas @$(GOTD_STOP_CMD) 2>/dev/null
205 a07c01e0 2022-11-08 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
206 6d7eb4f7 2023-04-04 thomas
207 6d7eb4f7 2023-04-04 thomas test_repo_write_protected: prepare_test_repo start_gotd_rw_protected
208 6d7eb4f7 2023-04-04 thomas @-$(GOTD_TRAP); su ${GOTD_TEST_USER} -c \
209 6d7eb4f7 2023-04-04 thomas 'env $(GOTD_TEST_ENV) sh ./repo_write_protected.sh'
210 6d7eb4f7 2023-04-04 thomas @$(GOTD_STOP_CMD) 2>/dev/null
211 6d7eb4f7 2023-04-04 thomas @su -m ${GOTD_USER} -c 'env $(GOTD_TEST_ENV) sh ./check_test_repo.sh'
212 f2900386 2022-10-31 thomas
213 581fa623 2022-12-30 thomas test_request_bad: prepare_test_repo_empty start_gotd_ro
214 79f1ca78 2022-12-30 thomas @-$(GOTD_TRAP); su -m ${GOTD_TEST_USER} -c \
215 581fa623 2022-12-30 thomas 'env $(GOTD_TEST_ENV) sh ./request_bad.sh'
216 79f1ca78 2022-12-30 thomas @$(GOTD_STOP_CMD) 2>/dev/null
217 79f1ca78 2022-12-30 thomas
218 f2900386 2022-10-31 thomas .include <bsd.regress.mk>