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