blob: eb8ca56f1182f467ad500dbf2052415021163991 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2
3PRINT_PASSED=2
4
5NGINX_UTIL="/usr/bin/nginx-util"
6
7ORIG=".original-test-nginx-util-root"
8
9mkdir -p /tmp/.uci/
10
11uci commit nginx || { printf "Error invoking: uci commit\n Exit."; exit 2; }
12
13
14pst_exit() {
15 printf "\nExit: Recovering original settings ... "
16
17 uci revert nginx
18
19 cd "/etc/config/" && rm "nginx" && mv "nginx.${ORIG}" "nginx" ||
20 printf "\n%s: not moved %s to %s\n" "/etc/config/" "nginx${ORIG}" "nginx"
21
22 cd "/etc/crontabs/" && rm "root" && mv "root${ORIG}" "root" ||
23 printf "\n%s: not moved %s to %s\n" "/etc/crontabs/" "root${ORIG}" "root"
24
25 cd "$(dirname "${CONF_DIR}")" && rm -r "${CONF_DIR}" &&
26 mv "$(basename "${CONF_DIR}")${ORIG}" "$(basename "${CONF_DIR}")" ||
27 printf "\n%s: not moved %s to %s\n" "$(dirname "${CONF_DIR}")" \
28 "$(basename "${CONF_DIR}")${ORIG}" "$(basename "${CONF_DIR}")"
29
30 printf "done.\n"
31
32 exit "$1"
33}
34
35
36mkdir -p "/etc/config/" && touch "/etc/config/nginx"
37
38cd "/etc/config/" && [ ! -e "nginx${ORIG}" ] && cp "nginx" "nginx.${ORIG}" || {
39 printf "\n%s: not copied %s to %s\n" "/etc/config/" "nginx" "nginx${ORIG}"
40 pst_exit 3
41}
42
43uci set nginx.global.uci_enable=1
44
45
46mkdir -p "/etc/crontabs/" && touch "/etc/crontabs/root"
47
48cd "/etc/crontabs/" && [ ! -e "root${ORIG}" ] && mv "root" "root${ORIG}" || {
49 printf "\n%s: not moved %s to %s\n" "/etc/crontabs/" "root${ORIG}" "root"
50 pst_exit 4
51}
52
53touch "/etc/crontabs/root"
54
55
56# ----------------------------------------------------------------------------
57
58__esc_newlines() {
59 echo "${1}" | sed -E 's/$/\\n/' | tr -d '\n' | sed -E 's/\\n$/\n/'
60}
61
62__esc_sed_rhs() {
63 __esc_newlines "${1}" | sed -E 's/[&/\]/\\&/g'
64}
65
66_sed_rhs() {
67 __esc_sed_rhs "$(echo "${1}" | sed -E "s/[$]/$(__esc_sed_rhs "${2}")/g")"
68}
69
70__esc_regex() {
71 __esc_newlines "${1}" | sed -E 's/[^^_a-zA-Z0-9-]/[&]/g; s/\^/\\^/g'
72}
73
74_regex() {
75 __esc_regex "${1}" | sed -E -e 's/^(\[\s])*/^\\s*/' \
76 -e 's/(\[\s])+\[[*]]/(\\s.*)?/g' \
77 -e 's/(\[\s])+/\\s+/g' \
78 -e 's/(\[\s])*\[[;]]/\\s*;/g' \
79 -e "s/\[['\"]]/['\"]?/g" \
80 -e "s/\[[$]]/$(__esc_sed_rhs "$(__esc_regex "${2}")")/g"
81}
82
83_echo_sed() {
84 echo "" | sed -E "c${1}"
85}
86
87
88fileauto="# This file is re-created when Nginx starts."
89
90setpoint_init_lan() {
91 echo "${fileauto}"
92
93 sed -n -E '/^\s*#UCI_HTTP_CONFIG\s*$/q;p' "${UCI_CONF}.template"
94
95 local rhs="\t}\n\n\tserver { #see uci show 'nginx.\1'"
96 uci -n export nginx \
97 | sed -E -e "s/'//g" \
98 -e '/^\s*package\s+nginx\s*$/d' \
99 -e '/^\s*config\s+main\s/d' \
100 -e "s/^\s*config\s+server\s+(.*)$/$rhs/g" \
101 -e 's/^\s*list\s/\t\t/g' \
102 -e 's/^\s*option\s/\t\t/g' \
103 -e 's/^\s*uci_listen_locally\s+/\t\tlisten 127.0.0.1:/g' \
104 -e '/^\s*uci_/d' \
105 -e '/^$/d' -e "s/[^'\n]$/&;/g" \
106 | sed "1,2d"
107 printf "\t}\n\n"
108
109 sed -E '1,/^\s*#UCI_HTTP_CONFIG\s*$/ d' "${UCI_CONF}.template"
110}
111
112
113setpoint_add_ssl() {
114 local indent="\n$1"
115 local name="$2"
116 local default=""
117 [ "${name}" = "${LAN_NAME}" ] && default=".default"
118 local prefix="${CONF_DIR}${name}"
119
120 local ADDS=""
121 local CONF
122 CONF="$(sed -E \
123 -e "s/$(_regex "${NGX_INCLUDE}" "${LAN_LISTEN}${default}")/$1$(\
124 _sed_rhs "${NGX_INCLUDE}" "${LAN_SSL_LISTEN}${default}")/g" \
125 -e "s/^(\s*listen\s+)([^:]*:|\[[^]]*\]:)?80(\s|$|;)/\1\2443 ssl\3/g" \
126 "${prefix}.sans" 2>/dev/null)"
127 echo "${CONF}" | grep -qE "$(_regex "${NGX_SSL_CRT}" "${prefix}")" \
128 || ADDS="${ADDS}${indent}$(_sed_rhs "${NGX_SSL_CRT}" "${prefix}")"
129 echo "${CONF}" | grep -qE "$(_regex "${NGX_SSL_KEY}" "${prefix}")" \
130 || ADDS="${ADDS}${indent}$(_sed_rhs "${NGX_SSL_KEY}" "${prefix}")"
131 echo "${CONF}" | grep -qE "^\s*ssl_session_cache\s" \
132 || ADDS="${ADDS}${indent}$(_sed_rhs "${NGX_SSL_SESSION_CACHE}" "${name}")"
133 echo "${CONF}" | grep -qE "^\s*ssl_session_timeout\s" \
134 || ADDS="${ADDS}${indent}$(_sed_rhs "${NGX_SSL_SESSION_TIMEOUT}" "")"
135
136 if [ -n "${ADDS}" ]
137 then
138 ADDS="$(echo "${ADDS}" | sed -E 's/^\\n//')"
139 echo "${CONF}" | grep -qE "$(_regex "${NGX_SERVER_NAME}" "${name}")" \
140 && echo "${CONF}" \
141 | sed -E "/$(_regex "${NGX_SERVER_NAME}" "${name}")/a\\${ADDS}" \
142 > "${prefix}.with" \
143 && _echo_sed "Added directives to ${prefix}.with:\n${ADDS}" \
144 && return 0 \
145 || _echo_sed "Cannot add directives to ${prefix}.sans, missing:\
146 \n$(_sed_rhs "${NGX_SERVER_NAME}" "${name}")\n${ADDS}"
147 return 1
148 fi
149 return 0
150}
151
152# ----------------------------------------------------------------------------
153
154test_setpoint() {
155 [ "$(cat "$1")" = "$2" ] && return
156 echo "$1:"; cat "$1"
157 echo "differs from setpoint:"; echo "$2"
158 [ "${PRINT_PASSED}" -gt 1 ] && pst_exit 1
159}
160
161
162test_existence() {
163 if [ "$2" -eq "0" ]
164 then
165 [ ! -f "$1" ] && echo "$1 missing!" &&
166 [ "${PRINT_PASSED}" -gt 1 ] && pst_exit 1
167 else
168 [ -f "$1" ] && echo "$1 existing!" &&
169 [ "${PRINT_PASSED}" -gt 1 ] && pst_exit 1
170 fi
171}
172
173
174test() {
175 eval "$1 2>/dev/null >/dev/null"
176 if [ "$?" -eq "$2" ]
177 then
178 [ "${PRINT_PASSED}" -gt 0 ] \
179 && printf "%-72s%-1s\n" "$1" "2>/dev/null >/dev/null (-> $2?) passed."
180 else
181 printf "%-72s%-1s\n" "$1" "2>/dev/null >/dev/null (-> $2?) failed!!!"
182 [ "${PRINT_PASSED}" -gt 0 ] && printf "\n### Snip:\n" && eval "$1"
183 [ "${PRINT_PASSED}" -gt 0 ] && printf "### Snap.\n"
184 [ "${PRINT_PASSED}" -gt 1 ] && pst_exit 1
185 fi
186}
187
188
189
190[ "$PRINT_PASSED" -gt 0 ] && printf "\nTesting %s get_env ...\n" "${NGINX_UTIL}"
191
192
193eval $("${NGINX_UTIL}" get_env)
194test '[ -n "${UCI_CONF}" ]' 0
195test '[ -n "${NGINX_CONF}" ]' 0
196test '[ -n "${CONF_DIR}" ]' 0
197test '[ -n "${LAN_NAME}" ]' 0
198test '[ -n "${LAN_LISTEN}" ]' 0
199test '[ -n "${LAN_SSL_LISTEN}" ]' 0
200test '[ -n "${SSL_SESSION_CACHE_ARG}" ]' 0
201test '[ -n "${SSL_SESSION_TIMEOUT_ARG}" ]' 0
202test '[ -n "${ADD_SSL_FCT}" ]' 0
203test '[ -n "${MANAGE_SSL}" ]' 0
204
205mkdir -p "$(dirname "${LAN_LISTEN}")"
206
207mkdir -p "${CONF_DIR}"
208
209cd "$(dirname "${CONF_DIR}")" && [ ! -e "$(basename "${CONF_DIR}")${ORIG}" ] &&
210mv "$(basename "${CONF_DIR}")" "$(basename "${CONF_DIR}")${ORIG}" ||
211{
212 printf "\n%s: not moved %s to %s\n" "$(dirname "${CONF_DIR}")" \
213 "$(basename "${CONF_DIR}")" "$(basename "${CONF_DIR}")${ORIG}"
214 pst_exit 3
215}
216
217
218[ "$PRINT_PASSED" -gt 0 ] && printf "\nPrepare files in %s ...\n" "${CONF_DIR}"
219
220mkdir -p "${CONF_DIR}"
221
222cd "${CONF_DIR}" || pst_exit 2
223
224NGX_INCLUDE="include '\$';"
225NGX_SERVER_NAME="server_name * '\$' *;"
226NGX_SSL_CRT="ssl_certificate '\$.crt';"
227NGX_SSL_KEY="ssl_certificate_key '\$.key';"
228NGX_SSL_SESSION_CACHE="ssl_session_cache '$(echo "${SSL_SESSION_CACHE_ARG}" \
229 | sed -E "s/$(__esc_regex "${LAN_NAME}")/\$/")';"
230NGX_SSL_SESSION_TIMEOUT="ssl_session_timeout '${SSL_SESSION_TIMEOUT_ARG}';"
231
232cat > "${LAN_NAME}.sans" <<EOF
233# default_server for the LAN addresses getting the IPs by:
234# ifstatus lan | jsonfilter -e '@["ipv4-address","ipv6-address"].*.address'
235server {
236 include '${LAN_LISTEN}.default';
237 server_name ${LAN_NAME};
238 include conf.d/*.locations;
239}
240EOF
241CONFS="${CONFS} ${LAN_NAME}:0"
242
243cat > minimal.sans <<EOF
244server {
245 server_name minimal;
246}
247EOF
248CONFS="${CONFS} minimal:0"
249
250cat > listens.sans <<EOF
251server {
252 listen 80;
253 listen 81;
254 listen hostname:80;
255 listen hostname:81;
256 listen [::]:80;
257 listen [::]:81;
258 listen 1.3:80;
259# listen 1.3:80;
260 listen 1.3:81;
261 listen [1::3]:80;
262 listen [1::3]:81;
263 server_name listens;
264}
265EOF
266CONFS="${CONFS} listens:0"
267
268cat > normal.sans <<EOF
269server {
270 include '${LAN_LISTEN}';
271 server_name normal;
272}
273EOF
274CONFS="${CONFS} normal:0"
275
276cat > acme.sans <<EOF
277server {
278 listen 80;
279 include '${LAN_LISTEN}';
280 server_name acme;
281}
282EOF
283CONFS="${CONFS} acme:0"
284
285cat > more_server.sans <<EOF
286server {
287 # include '${LAN_LISTEN}';
288 server_name normal;
289}
290server {
291 include '${LAN_LISTEN}';
292 server_name more_server;
293}
294EOF
295CONFS="${CONFS} more_server:0"
296
297cat > more_names.sans <<EOF
298server {
299 include '${LAN_LISTEN}';
300 include '${LAN_LISTEN}';
301 include '${LAN_LISTEN}';
302 not include '${LAN_LISTEN}';
303 server_name example.com more_names example.org;
304}
305EOF
306CONFS="${CONFS} more_names:0"
307
308cat > different_name.sans <<EOF
309server {
310 include '${LAN_LISTEN}';
311 server_name minimal;
312}
313EOF
314CONFS="${CONFS} different_name:1"
315
316cat > comments.sans <<EOF
317server { # comment1
318 # comment2
319 include '${LAN_LISTEN}';
320 server_name comments;
321 # comment3
322} # comment4
323EOF
324CONFS="${CONFS} comments:0"
325
326cat > name_comment.sans <<EOF
327server {
328 include '${LAN_LISTEN}';
329 server_name name_comment; # comment
330}
331EOF
332CONFS="${CONFS} name_comment:0"
333
334cat > tab.sans <<EOF
335server {
336 include '${LAN_LISTEN}';
337 server_name tab;
338}
339EOF
340CONFS="${CONFS} tab:0"
341
342
343
344[ "$PRINT_PASSED" -gt 0 ] && printf "\nSetup files in %s ...\n" "${CONF_DIR}"
345
346
347for conf in ${CONFS}
348do test 'setpoint_add_ssl " " '"${conf%:*}" "${conf#*:}"
349done
350
351test 'setpoint_add_ssl "\t" tab' 0 # fixes wrong indentation.
352
353
354
355[ "$PRINT_PASSED" -gt 0 ] && printf "\nTesting Cron ... \n"
356
357
358echo -n "prefix" >"/etc/crontabs/root"
359test '"${NGINX_UTIL}" add_ssl _lan' 0
360echo "postfix" >>"/etc/crontabs/root"
361test_setpoint "/etc/crontabs/root" "prefix
3623 3 12 12 * ${NGINX_UTIL} 'check_ssl'
363postfix"
364
365test '"${NGINX_UTIL}" del_ssl _lan' 0
366test_setpoint "/etc/crontabs/root" "prefix
3673 3 12 12 * ${NGINX_UTIL} 'check_ssl'
368postfix"
369
370test '"${NGINX_UTIL}" check_ssl' 0
371test_setpoint "/etc/crontabs/root" "prefix
372postfix"
373
374test '"${NGINX_UTIL}" add_ssl _lan' 0
375test_setpoint "/etc/crontabs/root" "prefix
376postfix
3773 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
378
379rm -f "/etc/crontabs/root"
380
381
382[ "$PRINT_PASSED" -gt 0 ] && printf '\n\t-"-\t(legacy) ... \n'
383
384echo -n "prefix" >"/etc/crontabs/root"
385cp "minimal.sans" "minimal.conf"
386
387test '"${NGINX_UTIL}" add_ssl minimal' 0
388echo "postfix" >>"/etc/crontabs/root"
389test_setpoint "/etc/crontabs/root" "prefix
3903 3 12 12 * ${NGINX_UTIL} 'add_ssl' 'minimal'
391postfix"
392
393test '"${NGINX_UTIL}" del_ssl minimal' 0
394test_setpoint "/etc/crontabs/root" "prefix
395postfix"
396
397rm -f "/etc/crontabs/root"
398
399
400
401[ "$PRINT_PASSED" -gt 0 ] && printf "\nTesting %s init_lan ...\n" "${NGINX_UTIL}"
402
403
404rm -f "${LAN_NAME}.conf" "_redirect2ssl.conf" "${UCI_ADDED}.conf"
405rm -f "$(readlink "${UCI_CONF}")"
406
407test '"${NGINX_UTIL}" init_lan' 0
408test_setpoint "${UCI_CONF}" "$(setpoint_init_lan)"
409test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
410
411
412[ "$PRINT_PASSED" -gt 0 ] && printf '\n\t-"-\twith temporary UCI config ... \n'
413
414UCI_ADDED="$(uci add nginx server)" &&
415uci set nginx.@server[-1].server_name='temp' &&
416uci add_list nginx.@server[-1].listen='81 default_server' &&
417uci add_list nginx.@server[-1].listen='80' &&
418echo "UCI: nginx.${UCI_ADDED} added."
419
420rm -f "${LAN_NAME}.conf" "_redirect2ssl.conf" "${UCI_ADDED}.conf"
421rm -f "$(readlink "${UCI_CONF}")"
422
423test '"${NGINX_UTIL}" init_lan' 0
424test_setpoint "${UCI_CONF}" "$(setpoint_init_lan)"
425test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
426
427
428[ "$PRINT_PASSED" -gt 0 ] && printf '\n\t-"-\t(legacy) ... \n'
429
430cp "${LAN_NAME}.sans" "${LAN_NAME}.conf"
431touch "_redirect2ssl.conf" "${UCI_ADDED}.conf"
432rm -f "$(readlink "${UCI_CONF}")"
433test '"${NGINX_UTIL}" init_lan' 0
434
435skipped() {
436 printf "\t# skipped UCI server 'nginx.%s'" "$1"
437 printf " as it could conflict with: %s%s.conf\n\n" "${CONF_DIR}" "$1"
438}
439rhs="$(skipped "$LAN_NAME" && skipped _redirect2ssl && skipped "${UCI_ADDED}")"
440sed -E -e "s/^\t#UCI_HTTP_CONFIG$/$(__esc_sed_rhs "$rhs")\n/" \
441 -e 's/\\n/\n/g' -e "1i${fileauto}" "${UCI_CONF}.template" >"uci.setpoint"
442
443test_setpoint "${UCI_CONF}" "$(cat "uci.setpoint")"
444test_setpoint "/etc/crontabs/root" ""
445
446
447
448[ "$PRINT_PASSED" -gt 0 ] && printf "\nTesting %s add_ssl ...\n" "${NGINX_UTIL}"
449
450
451test '[ "${ADD_SSL_FCT}" = "add_ssl" ] ' 0
452
453rm -f "${LAN_NAME}.conf" "_redirect2ssl.conf" "${UCI_ADDED}.conf"
454rm -f "$(readlink "${UCI_CONF}")"
455test 'uci set nginx._lan.uci_manage_ssl="self-signed"' 0
456"${NGINX_UTIL}" del_ssl "${LAN_NAME}" 2>/dev/null
457test_setpoint "/etc/crontabs/root" ""
458test_existence "${LAN_NAME}.crt" 1
459test_existence "${LAN_NAME}.key" 1
460test '"${NGINX_UTIL}" add_ssl '"${UCI_ADDED}"' acme \
461 '"${CONF_DIR}${UCI_ADDED}.crt"' '"${CONF_DIR}${UCI_ADDED}.key"' ' 0
462test_setpoint "/etc/crontabs/root" ""
463test_existence "${UCI_ADDED}.crt" 1
464test_existence "${UCI_ADDED}.key" 1
465test '"${NGINX_UTIL}" add_ssl '"${LAN_NAME}" 0
466test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
467test_existence "${LAN_NAME}.crt" 0
468test_existence "${LAN_NAME}.key" 0
469test '"${NGINX_UTIL}" add_ssl '"${LAN_NAME}" 0
470test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
471test '"${NGINX_UTIL}" add_ssl inexistent' 1
472test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
473test '"${NGINX_UTIL}" init_lan' 0
474test_setpoint "${UCI_CONF}" "$(setpoint_init_lan)"
475test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'check_ssl'"
476test_existence "${UCI_ADDED}.crt" 1
477test_existence "${UCI_ADDED}.key" 1
478test_existence "${LAN_NAME}.crt" 0
479test_existence "${LAN_NAME}.key" 0
480
481
482[ "$PRINT_PASSED" -gt 0 ] && printf '\n\t-"-\t(legacy) ... \n'
483
484cp different_name.sans different_name.with
485
486cp "/etc/crontabs/root" "cron.setpoint"
487for conf in ${CONFS}; do
488 name="${conf%:*}"
489 [ "${name}" = "acme" ] && continue
490 [ "${name}" = "different_name" ] ||
491 echo "3 3 12 12 * ${NGINX_UTIL} 'add_ssl' '${name}'" >>"cron.setpoint"
492 cp "${name}.sans" "${name}.conf"
493 test '"${NGINX_UTIL}" add_ssl '"${name}" "${conf#*:}"
494 test_setpoint "${name}.conf" "$(cat "${name}.with")"
495 test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
496 [ "${name}" = "different_name" ] || test_existence "${name}.crt" 0
497 [ "${name}" = "different_name" ] || test_existence "${name}.key" 0
498done
499
500cp acme.sans acme.conf
501test '"${NGINX_UTIL}" add_ssl acme acme /path/to/crt /path/to/key' 0
502test_setpoint "acme.conf" "$(cat "acme.with")"
503test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
504test_existence "acme.crt" 1
505test_existence "acme.key" 1
506
507
508
509[ "$PRINT_PASSED" -gt 0 ] && printf "\nTesting %s del_ssl ...\n" "${NGINX_UTIL}"
510
511
512sed -E -e 's/443 ssl/80/' -e '/[^2]ssl/d' "/etc/config/nginx" >"config.setpoint"
513
514cp "/etc/crontabs/root" "cron.setpoint"
515rm -f "${LAN_NAME}.conf" "_redirect2ssl.conf" "${UCI_ADDED}.conf"
516test '"${NGINX_UTIL}" del_ssl '"${LAN_NAME}" 0
517test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
518test_existence "${LAN_NAME}.crt" 1
519test_existence "${LAN_NAME}.key" 1
520test '"${NGINX_UTIL}" del_ssl '"${LAN_NAME}" 1
521test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
522
523rm -f "$(readlink "${UCI_CONF}")"
524sed -E "/$(__esc_regex "'check_ssl'")/d" "/etc/crontabs/root" >"cron.setpoint"
525test '"${NGINX_UTIL}" init_lan' 0
526test_setpoint "${UCI_CONF}" "$(setpoint_init_lan)"
527test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
528
529touch "${UCI_ADDED}.crt" "${UCI_ADDED}.key"
530test '"${NGINX_UTIL}" del_ssl "'${UCI_ADDED}'" acme' 0
531test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
532test_existence "${UCI_ADDED}.crt" 0
533test_existence "${UCI_ADDED}.key" 0
534
535test '"${NGINX_UTIL}" del_ssl inexistent' 1
536test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
537
538test_setpoint "/etc/config/nginx" "$(cat "config.setpoint")"
539test '"${NGINX_UTIL}" add_ssl "'${UCI_ADDED}'" acme \
540 '"${CONF_DIR}${UCI_ADDED}.crt"' '"${CONF_DIR}${UCI_ADDED}.key"' ' 0
541test '"${NGINX_UTIL}" add_ssl "'$(uci get "nginx.${UCI_ADDED}.server_name")'"' 0
542test '"${NGINX_UTIL}" del_ssl "'$(uci get "nginx.${UCI_ADDED}.server_name")'"' 0
543rm -f "$(readlink "${UCI_CONF}")"
544sed -E "/$(__esc_regex "'check_ssl'")/d" "/etc/crontabs/root" >"cron.setpoint"
545test '"${NGINX_UTIL}" init_lan' 0
546test_setpoint "${UCI_CONF}" "$(setpoint_init_lan)"
547test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
548test_existence "${UCI_ADDED}.crt" 1
549test_existence "${UCI_ADDED}.key" 1
550
551
552[ "$PRINT_PASSED" -gt 0 ] && printf '\n\t-"-\t(legacy) ... \n'
553
554for conf in ${CONFS}; do
555 name="${conf%:*}"
556 [ "${name}" = "acme" ] && continue
557 sed -E "/$(__esc_regex "'${name}'")/d" "/etc/crontabs/root" >"cron.setpoint"
558 touch "${name}.crt" "${name}.key"
559 cp "${name}.with" "${name}.conf"
560 test '"${NGINX_UTIL}" del_ssl '"${name}" "${conf#*:}"
561 test_setpoint "${name}.conf" "$(cat "${name}.sans")"
562 test_setpoint "/etc/crontabs/root" "$(cat "cron.setpoint")"
563 [ "${name}" = "different_name" ] && rm "${name}.crt" "${name}.key"
564 test_existence "${name}.crt" 1
565 test_existence "${name}.key" 1
566done
567test_setpoint "/etc/crontabs/root" ""
568
569test '"${NGINX_UTIL}" del_ssl acme acme' 0
570test_existence "acme.crt" 1
571test_existence "acme.key" 1
572
573cp acme.with acme.conf
574touch acme.crt acme.key
575echo "3 3 12 12 * ${NGINX_UTIL} 'add_ssl' 'acme'" >>"/etc/crontabs/root"
576test '"${NGINX_UTIL}" del_ssl acme acme' 0
577test_setpoint "acme.conf" "$(cat "acme.sans")"
578test_setpoint "/etc/crontabs/root" "3 3 12 12 * ${NGINX_UTIL} 'add_ssl' 'acme'"
579test_existence "acme.crt" 0
580test_existence "acme.key" 0
581"${NGINX_UTIL}" del_ssl acme 2>/dev/null
582test_setpoint "/etc/crontabs/root" ""
583test_existence "acme.crt" 1
584test_existence "acme.key" 1
585
586
587[ "$PRINT_PASSED" -gt 0 ] && printf "\nTesting without UCI ... \n"
588
589rm -f "$(readlink "${UCI_CONF}")"
590
591test 'uci set nginx.global.uci_enable=0' 0
592
593test '"${NGINX_UTIL}" init_lan' 0
594
595test '[ -e "$(readlink '"${UCI_CONF}"')" ]' 1
596
597cp "${LAN_NAME}.sans" "${LAN_NAME}.conf"
598test '"${NGINX_UTIL}" add_ssl '"${LAN_NAME}" 0
599test '"${NGINX_UTIL}" add_ssl '"${LAN_NAME}" 0
600test '"${NGINX_UTIL}" del_ssl '"${LAN_NAME}" 0
601test '"${NGINX_UTIL}" del_ssl '"${LAN_NAME}" 0
602
603test 'rm "${LAN_NAME}.conf"' 0
604test '"${NGINX_UTIL}" add_ssl '"${LAN_NAME}" 1
605test '"${NGINX_UTIL}" del_ssl '"${LAN_NAME}" 1
606
607
608
609pst_exit 0