-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxlator-t.sh
128 lines (107 loc) · 2.97 KB
/
xlator-t.sh
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
#!/bin/sh
XLATOR="./quest-dnsupdate-xlator -test"
WRKTMP=${TMPDIR:-/tmp}/.xlator-t$$
mkdir -p $WRKTMP
#trap 'rm -rf $WRKTMP' 0
VERBOSE=false
PASSED_ALL=true
# XXX tests go here
verbose () { $VERBOSE && echo "$*"; :; }
start () { TESTNAME="$*"; }
result () { if test $? = 0; then pass; else fail; fi; }
invert () { test $? != 0; "$@"; }
pass () { echo " ok $TESTNAME"; }
fail () { echo "FAIL $TESTNAME"; PASSED_ALL=false; }
#-- runs the given command, and returns true if the here-document on
# file descriptor 3 matches the output from the given command
check () {
expected_ec=0
case $1 in -exit) shift; expected_ec=$1; shift;; esac
cat <&3 > $WRKTMP/expected
"$@" > $WRKTMP/out; ec=$?
if test $ec != $expected_ec; then
echo "unexpected exit code from '$*'" >&2
echo " was $ec, expected $expected_ec" >&2
return 1
fi
if cmp -s $WRKTMP/expected $WRKTMP/out; then
:
else
{ echo "unexpected output from '$*'"
echo "----- actual output:"
cat $WRKTMP/out
echo "----- expected output:"
cat $WRKTMP/expected
} >&2
return 1
fi
return 0
}
cat <<-. > $WRKTMP/input
Software\Policies\Microsoft\Windows NT\DNSClient;RegistrationEnabled;REG_DWORD;1
Software\Policies\Microsoft\Windows NT\DNSClient;RegisterReverseLookup;REG_DWORD;2
Software\Policies\Microsoft\Windows NT\DNSClient;RegistrationOverwritesInConflict;REG_DWORD;0
Software\Policies\Microsoft\Windows NT\DNSClient;RegistrationTtl;REG_DWORD;600
Software\Policies\Microsoft\Windows NT\DNSClient;UpdateSecurityLevel;REG_DWORD;0
Software\Policies\Microsoft\Windows NT\DNSClient;UpdateTopLevelDomainZones;REG_DWORD;0
.
start "info"
$XLATOR info >/dev/null </dev/null
result
start "badarg"
$XLATOR badarg >/dev/null </dev/null 2>&1
invert result
start "keys"
check $XLATOR keys </dev/null 3<<'.'
Software\Policies\Microsoft\Windows NT\DNSClient
.
result
CONF=/tmp/dnsupdate.conf
start "init from empty"
rm -f $CONF &&
check $XLATOR init </dev/null 3</dev/null &&
test ! -f $CONF
result
start "apply"
check $XLATOR <$WRKTMP/input 3</dev/null &&
check cat $CONF 3<<'.'
#--VGP BEGIN--#
RegisterReverseLookup = 2
RegistrationEnabled = 1
RegistrationOverwritesInConflict = 0
RegistrationTtl = 600
UpdateSecurityLevel = 0
UpdateTopLevelDomainZones = 0
#--VGP END--#
.
result
start "init to empty"
check $XLATOR init </dev/null 3</dev/null &&
test ! -f $CONF
result
cat <<. >$CONF
# Some random existing conf file
Foo = 1 2 3
UpdateSecurityLevel = 99999
.
start "apply existing"
cp $CONF $WRKTMP/orig.conf
cp $WRKTMP/orig.conf $WRKTMP/expect.conf
cat >>$WRKTMP/expect.conf <<-.
#--VGP BEGIN--#
RegisterReverseLookup = 2
RegistrationEnabled = 1
RegistrationOverwritesInConflict = 0
RegistrationTtl = 600
UpdateSecurityLevel = 0
UpdateTopLevelDomainZones = 0
#--VGP END--#
.
check $XLATOR <$WRKTMP/input 3</dev/null &&
check cat $CONF 3<$WRKTMP/expect.conf
result
start "init existing"
check $XLATOR init </dev/null 3</dev/null &&
check cat $CONF 3<$WRKTMP/orig.conf
result
$PASSED_ALL # must be last line