Debian Codegraph @

t/Makefile.cgi

raw
1 #! /usr/bin/make -rRf
2 #?
3 #? DESCRIPTION
4 #? For more details please see
5 #? ../Makefile Makefile Makefile.help Makefile.pod
6 #? make help.test.cgi
7 #?
8 #? VERSION
9 #? @(#) Makefile.cgi 1.60 22/11/12 09:50:04
10 #?
11 #? AUTHOR
12 #? 18-apr-18 Achim Hoffmann
13 #?
14 # -----------------------------------------------------------------------------
15
16 HELP-help.test.cgi = targets for testing '$(SRC.cgi)' (mainly invalid arguments)
17
18 _SID.cgi := 1.60
19
20 _MYSELF.cgi := t/Makefile.cgi
21 ALL.includes += $(_MYSELF.cgi)
22 ALL.inc.type += cgi
23 ALL.help.tests += help.test.cgi
24
25 first-cgi-target-is-default: help.test.cgi
26
27 ifeq (,$(_SID.test))
28 -include t/Makefile
29 endif
30
31 TEST.cgi.hosts =
32 ifdef TEST.hosts
33 TEST.cgi.hosts = $(TEST.hosts)
34 endif
35
36 MAKEFLAGS += --no-print-directory
37 # needed here, even if set in Makefile.inc; reason yet unknown (01/2019)
38
39 help.test.cgi: HELP_TYPE = cgi
40 help.test.cgi-v: HELP_TYPE = cgi
41 help.test.cgi-vv: HELP_TYPE = cgi
42
43 HELP-_cgi0 = _____________________________________________ testing .cgi _
44 HELP-test.cgi = test all bad IPs, hostnames and options for '$(SRC.cgi)'
45 HELP-test.cgi.log = same as test.cgi but store output in '$(TEST.logdir)/'
46 HELP-test.cgi.badhosts = test that some hostnames are ignored in '$(SRC.cgi)'
47 HELP-test.cgi.badIPs = test that some IPs are ignored in '$(SRC.cgi)'
48 HELP-test.cgi.badall = test all bad and good IPs and hostnames
49 HELP-test.cgi.badopt = test bad options and characters
50 HELP-test.cgi.goodIPs = test IPs to be passed
51 HELP-test.cgi-NAME = same as testcmd-cgi-bad_NAME
52 HELP-testcmd-cgi-bad_NAME = check if a single NAME (IP or hostname) allowed in '$(SRC.cgi)'
53
54 HELP.cgi = $(_NL)\
55 \# Examples: $(_NL)\
56 \# $(MAKE_COMMAND) test.cgiall$(_NL)\
57 \# $(MAKE_COMMAND) testcmd-cgi-bad_42.42.42.42$(_NL)\
58 \# $(MAKE_COMMAND) testcmd-cgi-bad_127.0.0.127$(_NL)\
59 \# $(MAKE_COMMAND) testcmd-cgi-bad_localhost$(_NL)\
60 \# $(MAKE_COMMAND) e-LIST.cgi.badhosts$(_NL)\
61 \# $(MAKE_COMMAND) s-LIST.cgi.badIPs$(_NL)\
62 \# $(MAKE_COMMAND) s-LIST.cgi.badopt$(_NL)\
63 \#$(_NL)\
64 \# There are no test.cgi.*.log targets, please use test.cgi.log instead.$(_NL)\
65 \#$(_NL)\
66 \# Hint: use test.pattern-cgi- instead of test.pattern-cgi , as the$(_NL)\
67 \# patttern cgi may match other targets too.
68
69 LIST.cgi.badhosts := \
70 localhost any.local
71 # hostname.ok.to.show.failed-status
72
73 # range from - - - - - - - - - - - - - - - - - - to
74 LIST.cgi.badIPv4 := \
75 0.0.0.1 0.0.0.255 \
76 10.0.0.1 10.0.0.255 10.12.34.56 10.255.255.255 \
77 100.64.0.0 100.64.0.255 \
78 127.0.0.1 127.1.0.1 127.1.0.255 \
79 127.251.251.1 127.255.255.255 \
80 169.254.0.1 169.254.1.1 169.254.255.255 \
81 172.16.0.1 172.19.255.255 \
82 192.0.0.1 192.0.0.255 \
83 192.0.2.1 192.0.2.255 \
84 192.88.99.1 192.88.99.25 \
85 192.168.0.1 192.168.255.255 \
86 198.18.0.1 198.18.0.255 198.18.1.1 198.18.0.1.255 \
87 198.51.100.1 198.51.100.255 \
88 203.0.13.1 203.0.13.255 \
89 224.0.0.1 224.0.0.255 239.1.1.255 239.255.255.255 \
90 240.0.0.1 251.251.251.251 255.255.255.255 \
91 127.0.1 127.1 10.0.1 10.1 224.0.1 224.1 \
92 127001 111111 2133465000 127.666 42 \
93 0127.0.1 127.071 127.0.07 127.0.0.000042 \
94 0x7f.0.1 0x0b.026.8492 127.0x71 127.0.0.000x42 \
95 0x07f000001 \
96
97 # last line contain IPs with ocatl notations; should be ignored in general
98
99 # the IP or hostname becomes part of the target name, hence IPv6 are not
100 # possible verbatim because they contain : in the name; the : must be escaped
101 LIST.cgi.badIPv6 := \
102 \:\:1 ffff\:\:1 7f00\:1 ffff\:7f00\:1 \
103 ff01\:\:1 ff02\:\:1 ff02\:\:fb 64\:abcd\:\: \
104 \:251.1.1.1 \:\:251.1.1.1 \:abcd\:251.1.1.1 \:abcd\:\:251.1.1.1 \
105 abcd\:\:251.1.1.1 abcd\:\:\:251.1.1.1 abcd\:a\:\:251.1.1.1 \
106 fe80\:21ab\:22cd\:2323\:\:1 fec0\:21ab\:22cd\:2323\:\:1 feff\:21ab\:22cd\:2323\:\:1 \
107 fc00\:21ab\:22cd\:2323\:\:1 fdff\:21ab\:22cd\:2323\:\:1 \
108
109 HELP.cgi.internal = "\
110 \# test.cgi.badhosts: $(LIST.cgi.badhosts)$(_NL)\
111 \# test.cgi.badIPs: $(LIST.cgi.badIPs)$(_NL)\
112 \# test.cgi.goodIPs: $(LIST.cgi.goodIPs)$(_NL)\
113 "
114
115 # TODO: *goodIP* not yet ready
116 LIST.cgi.goodhosts := localhost.ok
117 LIST.cgi.goodIPv4 :=
118
119 # 128.0.1 128.1 192.1 \
120
121 LIST.cgi.goodIPv6 := \
122 ffff \
123 2002\:0\:0\:0\:0\:0\:b0b\:b0b \
124 fe00\:21ab\:22cd\:2323\:\:1
125
126 LIST.cgi.badIPs := $(LIST.cgi.badIPv4) $(LIST.cgi.badIPv6)
127 LIST.cgi.goodIPs := $(LIST.cgi.goodIPv4) $(LIST.cgi.goodIPv6)
128
129 ALL.cgi.goodhosts := $(LIST.cgi.goodhosts:%=testcmd-cgi-good_%)
130 ALL.cgi.goodIPs := $(LIST.cgi.goodIPs:%=testcmd-cgi-good_%)
131 ALL.cgi.badhosts := $(LIST.cgi.badhosts:%=testcmd-cgi-bad_%)
132 ALL.cgi.badIPs := $(LIST.cgi.badIPs:%=testcmd-cgi-bad_%)
133
134 HELP.test.cgi.all = $(_NL)\
135 \# targets for testing bad hosts:$(_NL)\
136 $(ALL.cgi.badhosts)$(_NL)\
137 $(_NL)\
138 \# targets for testing bad IPs:$(_NL)\
139 $(ALL.cgi.badIPs)$(_NL)\
140 $(_NL)\
141 \# targets for testing good IPs:$(_NL)\
142 $(ALL.cgi.goodIPs)$(_NL)\
143
144
145 # SEE Make:target name
146 # SEE Make:target name prefix
147
148 # Testing for invalid arguments, hostnames and IPs uses following command:
149 # o-saft.cgi --cgi +quit --exit=BEGIN0 --host=10.0.0.1
150 # or
151 # env QUERY_STRING="--cgi&--cmd=quit&--exit=BEGIN0&--host=10.0.0.1" o-saft.cgi
152 # they should return:
153 # X-Cite: Perl is a mess. ...
154 # X-O-Saft: OWASP – SSL advanced forensic tool
155 # Content-type: text/plain; charset=utf-8
156 #
157 # #o-saft.pl _yeast_EXIT exit=BEGIN0 - BEGIN start
158 #
159 # The option --exit=BEGIN0 ensures that nothing will be done in o-saft.pl .
160 # It ensures that the last line of the output contains exit=BEGIN0 . This last
161 # line is missing if o-saft.cgi exits because an invalid argument, hostname
162 # or IP was detected. The purpose here is to check if o-saft.cgi exits, hence
163 # the test succeeds, if the last line is missing.
164 # The target no.message is used for each individual test. It is a pattern rule
165 # in t/Makefile and uses the variables EXE.pl, TEST.args and TEST.INIT, which
166 # are passed as arguments to the recursive MAKE call.
167 # "make -i" is used to ensure that all tests are performed.
168
169 # testing usage of --cgi option; means that TEST.init must be set explicitly
170 # test fails, if it reports something containing exit=BEGIN0
171
172 # All tests for good or bad arguments need the same initial options
173 testcmd-cgi-%: EXE.pl = ../$(SRC.cgi)
174 testcmd-cgi-bad%: EXE.pl = ../$(SRC.cgi)
175 testcmd-cgi-good%: EXE.pl = ../$(SRC.cgi)
176 test.cgi: TEST.init = --cgi --exit=BEGIN0 +quit
177 testcmd-cgi-%: TEST.init = --cgi --exit=BEGIN0 +quit
178 testcmd-cgi-chr%: TEST.init = --cgi
179
180 testarg-cgi-%: EXE.pl = ../$(SRC.cgi)
181 testarg-cgi-%: TEST.init = --cgi --exit=BEGIN0 +quit
182 # check host argument without --host=
183 testarg-cgi-host-localhost: TEST.init += localhost
184 testarg-cgi-host-127_42: TEST.init += 127.42
185 testarg-cgi-host-12742: TEST.init += 12742
186 testarg-cgi-host-2133465000: TEST.init += 2133465000
187 testarg-cgi-host-7f00_1: TEST.init += 7f00:1
188 testarg-cgi-host-ffff__1: TEST.init += ffff::1
189
190 ALL.cgi.badarg = $(shell awk -F: '/^testarg-cgi-host-/ {arr[$$1]=1}$(_EXE.print_arr_END.awk)' $(_MYSELF.cgi))
191
192 # special targets to test bad --cgi
193 #testarg-cgi---cgi_ok: TEST.init = --cgi --ok.to.show.failed-status --exit=BEGIN0 +quit
194 testarg-cgi---cgi-miss: TEST.init = --missing--cgi --exit=BEGIN0 +quit
195 testarg-cgi---cgi-bad1: TEST.init = --cgiwrong --exit=BEGIN0 +quit
196 testarg-cgi---cgi-bad2: TEST.init = --cgi=wrong --exit=BEGIN0 +quit
197 testarg-cgi---cgi-bad3: TEST.init = --wrongcgi --exit=BEGIN0 +quit
198
199 ALL.cgi.badcgi = testarg-cgi---cgi-miss testarg-cgi---cgi-bad1 testarg-cgi---cgi-bad2 testarg-cgi---cgi-bad3
200
201 # arguments silently ignored by $(SRC.cgi), hence it will not die;
202 # target succeeds if $(SRC.cgi) returns exit=BEGIN0 0; hence testcmd-cgi-good-
203 LIST.cgi-opt-ignore := \
204 --cmd=list --cmd=+list --cmd=+dump --url=+dump \
205 --traceARG --trace --cmd=--trace --url=--trace \
206 --v --cmd=--v --url=--v \
207 --cmd=+version --ca-file=not-allowed --ca-path=not-allowed \
208 --cmd=libversion --ca-files=not-allowed --ca-paths=not-allowed \
209 --rc=not-allowed
210
211 # arguments checked by $(SRC.cgi), hence it will die;
212 # target succeeds if $(SRC.cgi) does not returns exit=BEGIN0
213 LIST.cgi-opt-die := \
214 --env=not-allowed --exe=not-allowed --lib=not-allowed \
215 --call=not-allowed --openssl=not-allowed
216
217 ifndef cgi-targets-generated
218 # SEE Make:macros
219 $(foreach arg, $(LIST.cgi-opt-ignore), \
220 $(eval _target=testcmd-cgi-good-$(subst =,-,$(arg))_any.FQDN) \
221 $(eval $(_target): TEST.init += $(arg)) \
222 $(eval ALL.cgi.badopt += $(_target)) \
223 )
224 $(foreach arg, $(LIST.cgi-opt-die), $(eval \
225 testcmd-cgi-$(subst =,-,$(arg))_any.FQDN: TEST.init += $(arg) \
226 ))
227 $(foreach arg, $(LIST.cgi-opt-die), $(eval \
228 ALL.cgi.badopt += testcmd-cgi-$(subst =,-,$(arg))_any.FQDN \
229 ))
230 undefine arg
231 undefine _target
232 endif
233
234 # targets for bad characters are written literally because it is difficult
235 # to replace the character in the generated target name
236 # the bad characters are enclosed in _ and _ for better readability
237 testcmd-cgi-chr-langle_any.FQDN: TEST.init += '--bad-char=_<_'
238 testcmd-cgi-chr-rangle_any.FQDN: TEST.init += '--bad-char=_>_'
239 testcmd-cgi-chr-semikolon_any.FQDN:TEST.init += '--bad-char=_;_'
240 testcmd-cgi-chr-tilde_any.FQDN: TEST.init += '--bad-char=_~_'
241 testcmd-cgi-chr-question_any.FQDN: TEST.init += '--bad-char=_?_'
242 #testcmd-cgi-chr-dollar_any.FQDN: TEST.init += '--bad-char=_\$$_'
243 testcmd-cgi-chr-percent_any.FQDN: TEST.init += '--bad-char=_%_'
244 testcmd-cgi-chr-dqoute_any.FQDN: TEST.init += '--bad-char=_\"_'
245 testcmd-cgi-chr-back_any.FQDN: TEST.init += '--bad-char=_\`_'
246 testcmd-cgi-chr-star_any.FQDN: TEST.init += '--bad-char=_*_'
247 testcmd-cgi-chr-lbrac_any.FQDN: TEST.init += '--bad-char=_(_'
248 testcmd-cgi-chr-rbrac_any.FQDN: TEST.init += '--bad-char=_)_'
249 testcmd-cgi-chr-lsquare_any.FQDN: TEST.init += '--bad-char=_[_'
250 testcmd-cgi-chr-rsquare_any.FQDN: TEST.init += '--bad-char=_]_'
251 testcmd-cgi-chr-lcurl_any.FQDN: TEST.init += '--bad-char=_{_'
252 testcmd-cgi-chr-rcurl_any.FQDN: TEST.init += '--bad-char=_}_'
253 testcmd-cgi-chr-caret_any.FQDN: TEST.init += '--bad-char=_^_'
254 testcmd-cgi-chr-bar_any.FQDN: TEST.init += '--bad-char=_|_'
255 testcmd-cgi-chr-hash_any.FQDN: TEST.init += '--bad-char=_\#_'
256
257 ALL.cgi.badchr = $(shell awk -F: '/^testcmd-cgi-chr-/ {arr[$$1]=1}$(_EXE.print_arr_END.awk)' $(_MYSELF.cgi))
258
259 # check HTTP header options
260 # NOTE: target name is testarg-cgi_ instead of testarg-cgi- because it should
261 # not match pattern rule testarg-cgi-%
262 testarg-cgi_with%: EXE.pl = ../$(SRC.cgi)
263 testarg-cgi_with%: TEST.init =
264 testarg-cgi_with-header: TEST.init += --cgi --exit=ARGS --with_HTTP_header --cgi-header
265 testarg-cgi_without-header: TEST.init += --cgi --exit=ARGS --with_HTTP_header --cgi-no-header
266
267 ALL.cgi.header = testarg-cgi_with-header testarg-cgi_without-header
268
269 test.cgi.log-compare: TEST.target_prefix = testcmd-cgi
270 test.cgi.log-move: TEST.target_prefix = testcmd-cgi
271 # TEST.target_prefix not yet used
272 # FIXME: general rule can only handle on perfix, but we have testcmd- and testarg. here
273
274 # NOTE: --exit=BEGIN0 must not be the last argument, because it triggers buggy
275 # check in o-saft.cgi (at least up to version 1.44), hence --dummy added
276 testarg-cgi-%:
277 @$(TRACE.target)
278 @$(MAKE) $(MFLAGS) no.message-exit.BEGIN0 EXE.pl=$(EXE.pl) TEST.init="$(TEST.init)" TEST.args=--dummy
279
280 testcmd-cgi-%:
281 @$(TRACE.target)
282 @$(eval _host := $(shell echo "$*" | awk -F_ '{print $$NF}'))
283 @$(MAKE) $(MFLAGS) no.message-exit.BEGIN0 EXE.pl=$(EXE.pl) TEST.init="$(TEST.init) --host=$(_host)" TEST.args=--dummy
284
285 # TODO: following target prints "#o-saft.pl..."
286 testcmd-cgi-good%:
287 @$(TRACE.target)
288 @$(eval _host := $(shell echo "$*" | awk -F_ '{print $$NF}'))
289 @$(MAKE) $(MFLAGS) message-exit.BEGIN0 EXE.pl=$(EXE.pl) TEST.init="$(TEST.init) --host=$(_host)" TEST.args=--dummy
290
291 # alias for simple usage
292 test.cgi-%: testcmd-cgi-bad_%
293 @echo ""
294
295 ALL.test.cgi = \
296 $(ALL.cgi.goodhosts) \
297 $(ALL.cgi.goodIPs) \
298 $(ALL.cgi.badopt) \
299 $(ALL.cgi.badchr) \
300 $(ALL.cgi.badhosts) \
301 $(ALL.cgi.badIPs) \
302 $(ALL.cgi.badarg) \
303 $(ALL.cgi.badcgi) \
304 $(ALL.cgi.header)
305
306 test.cgi.badhosts: $(ALL.cgi.badhosts)
307 test.cgi.badIPs: $(ALL.cgi.badIPs)
308 test.cgi.badall: test.cgi.badhosts test.cgi.badIPs
309 test.cgi.badopt: $(ALL.cgi.badopt)
310 test.cgi.badchr: $(ALL.cgi.badchr)
311 test.cgi.goodIPs: $(ALL.cgi.goodIPs)
312 test.cgi.goodhosts:$(ALL.cgi.goodhosts)
313
314 _TEST.cgi.log = $(TEST.logdir)/test.cgi.log-$(TEST.today)
315 # use 'make -i ...' because we have targets which fail, which is intended
316 $(_TEST.cgi.log):
317 @echo "# Makefile.cgi 1.60: $(MAKE) test.cgi.log" > $@
318 @$(MAKE) -i test.cgi >> $@ 2>&1
319
320 # not yet needed: test.log-compare-hint
321 test.cgi.log: $(_TEST.cgi.log) $(ALL.cgi.header:%=%.log)
322 @$(TRACE.target)
323 @$(TRACE.target.log)
324 @diff $(TEST.logdir)/$@ $(_TEST.cgi.log) \
325 && rm $(_TEST.cgi.log) \
326 || mv $(_TEST.cgi.log) $(TEST.logdir)/$@
327 @-test -f $(TEST.logdir)/$@ || mv $(_TEST.cgi.log) $(TEST.logdir)/$@
328 @ls -l $(TEST.logdir)/$@*
329 # TODO: same target as test.warnings.log
330 ALL.test.cgi.log += test.cgi.log
331
332 ifndef ALL.Makefiles
333 # NOTE: needed if called with -f Makefile.cgi
334 %-v: TRACE.target = echo "\# $@: $?"
335 %-v: %
336 echo CGI $(TEST.init)
337 @$(EXE.dummy)
338
339 %-vv: TRACE.target = echo "\# $@: $^"
340 %-vv: %
341 echo CGI
342 @$(EXE.dummy)
343 endif
344
345 test.cgi: $(ALL.test.cgi)