-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·135 lines (118 loc) · 4.56 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
# -*- coding: utf-8; mode: sh; tab-width: 3; indent-tabs-mode: nil -*-
#
# Copyright 2017, 2021, 2024
# Raffaello D. Di Napoli
if [ -z "${ZONES_DIR:-}" ]; then
# No externally-set test directory; create one of our own.
ZONES_DIR="$(mktemp -p "${TMPDIR:-/tmp}" -d temp_zones.XXXXXX)"
export ZONES_DIR
zones_dir_rm=true
elif [ $(ls -1A "${ZONES_DIR}" | wc -l) -gt 0 ]; then
echo "${0}: temporary zones directory \`${ZONES_DIR}' must be empty" >&2
exit 1
else
zones_dir_rm=false
fi
cp -a test-data/*.zone "${ZONES_DIR}"
assert_file_contains() {
local assert_name="${1}" file="${2}" match="${3}"
if grep -q "${match}" <"${file}"; then
echo "${assert_name}: pass"
else
echo "${assert_name}: fail:"
echo " missing: ${match}"
fi
}
assert_file_not_contains() {
local assert_name="${1}" file="${2}" match="${3}"
if grep -q "${match}" <"${file}"; then
echo "${assert_name}: fail:"
echo " offending: ${match}"
else
echo "${assert_name}: pass"
fi
}
assert_line_equals() {
local assert_name="${1}" file="${2}" line="${3}" expected="${4}" actual
actual=$(sed -ne "${line} p" <"${file}")
assert_equal "${assert_name}" "${expected}" "${actual}"
}
assert_read() {
local assert_name="${1}" expected="${2}" actual=
read -r actual
assert_equal "${assert_name}" "${expected}" "${actual}"
}
assert_read_eof() {
local assert_name="${1}"
if grep -qF ''; then
echo "${assert_name}: fail:"
echo " unexpected excess output"
else
echo "${assert_name}: pass"
fi
}
assert_equal() {
local assert_name="${1}" expected="${2}" actual="${3}"
if [ "${actual}" = "${expected}" ]; then
echo "${assert_name}: pass"
else
echo "${assert_name}: fail:"
echo " expected: ${expected}"
echo " actual : ${actual}"
exit 1
fi
}
cleanup() {
if ${zones_dir_rm}; then
echo "Deleting temporary zones directory \`${ZONES_DIR}'" >&2
rm -rf -- "${ZONES_DIR}"
else
echo "Deleting temporary zones in \`${ZONES_DIR}'" >&2
find "${ZONES_DIR}" -mindepth 1 -delete
fi
}
trap cleanup EXIT
today=$(date -u +%Y%m%d)
echo "Testing print_domains_txt"
./dehydrated-zonefiles-hook print_domains_txt |
{
assert_read 'print_domains_txt example.com' \
'example.com mail.example.com mail2.example.com mail3.example.com ns.example.com www.example.com wwwtest.example.com'
assert_read 'print_domains_txt example.net' \
'example.net mail.example.net ns.example.net www.example.net wwwtest.example.net'
assert_read_eof 'print_domains_txt'
}
export alias=example.com
./dehydrated-zonefiles-hook deploy_challenge example.com challenge1 key1
unset alias
assert_line_equals 'deploy_challenge example.com' "${ZONES_DIR}/example.com.zone" 3 \
"@ IN SOA ns.example.com. username.example.com. ( ${today}01 1d 2h 4w 1h )"
assert_file_contains 'deploy_challenge example.com' "${ZONES_DIR}/example.com.zone" \
'^_acme-challenge TXT "key1"$'
export alias=example.net
./dehydrated-zonefiles-hook deploy_challenge example.net challenge2 key2 www.example.net challenge3 key3
unset alias
assert_line_equals 'deploy_challenge example.net' "${ZONES_DIR}/example.net.zone" 4 \
' 36;version'
assert_file_contains 'deploy_challenge example.net' "${ZONES_DIR}/example.net.zone" \
'^_acme-challenge TXT "key2"$'
assert_file_contains 'deploy_challenge example.net' "${ZONES_DIR}/example.net.zone" \
'^_acme-challenge.www TXT "key3"$'
./dehydrated-zonefiles-hook clean_challenge example.com challenge1 key1
assert_line_equals 'clean_challenge example.com' "${ZONES_DIR}/example.com.zone" 3 \
"@ IN SOA ns.example.com. username.example.com. ( ${today}02 1d 2h 4w 1h )"
assert_file_not_contains 'clean_challenge example.com' "${ZONES_DIR}/example.com.zone" \
'^_acme-challenge'
./dehydrated-zonefiles-hook clean_challenge example.net challenge2 key2 www.example.net challenge3 key3
assert_line_equals 'clean_challenge example.net' "${ZONES_DIR}/example.net.zone" 4 \
' 37;version'
assert_file_not_contains 'clean_challenge example.net' "${ZONES_DIR}/example.net.zone" \
'^_acme-challenge'
./dehydrated-zonefiles-hook test_domain_includes_mx_servers example.com
assert_equal 'domain_includes_mx_servers example.com' 0 ${?}
./dehydrated-zonefiles-hook test_domain_includes_mx_servers example.net
assert_equal 'domain_includes_mx_servers example.net' 0 ${?}
./dehydrated-zonefiles-hook test_domain_includes_mx_servers example.org
assert_equal 'domain_includes_mx_servers example.org' 1 ${?}
exit 0