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