summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-01-31 23:25:08 +0000
committerDamien Miller <djm@mindrot.org>2020-02-01 10:28:33 +1100
commit677d0ece67634262b3b96c3cd6410b19f3a603b7 (patch)
treed7d84543dc02bdf9fb47f1657a96b2bbb685ee54 /regress
parentd4f4cdd681ab6408a98419f398b75a55497ed324 (diff)
upstream: regress test for sshd_config Include directive; from Jakub
Jelen OpenBSD-Regress-ID: 0d9224de3297c7a5f51ba68d6e3725a2a9345fa4
Diffstat (limited to 'regress')
-rw-r--r--regress/Makefile5
-rw-r--r--regress/servcfginclude.sh154
-rw-r--r--regress/test-exec.sh3
3 files changed, 159 insertions, 3 deletions
diff --git a/regress/Makefile b/regress/Makefile
index 34c47e8cb..774c10d41 100644
--- a/regress/Makefile
+++ b/regress/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.104 2019/09/03 08:37:45 djm Exp $ 1# $OpenBSD: Makefile,v 1.106 2020/01/31 23:25:08 djm Exp $
2 2
3tests: prep file-tests t-exec unit 3tests: prep file-tests t-exec unit
4 4
@@ -87,6 +87,7 @@ LTESTS= connect \
87 principals-command \ 87 principals-command \
88 cert-file \ 88 cert-file \
89 cfginclude \ 89 cfginclude \
90 servcfginclude \
90 allow-deny-users \ 91 allow-deny-users \
91 authinfo \ 92 authinfo \
92 sshsig 93 sshsig
@@ -122,7 +123,7 @@ CLEANFILES= *.core actual agent-key.* authorized_keys_${USERNAME} \
122 ssh-rsa_oldfmt \ 123 ssh-rsa_oldfmt \
123 ssh_config ssh_config.* ssh_proxy ssh_proxy_bak \ 124 ssh_config ssh_config.* ssh_proxy ssh_proxy_bak \
124 ssh_proxy_envpass sshd.log sshd_config sshd_config_minimal \ 125 ssh_proxy_envpass sshd.log sshd_config sshd_config_minimal \
125 sshd_config.orig sshd_proxy sshd_proxy.* sshd_proxy_bak \ 126 sshd_config.* sshd_proxy sshd_proxy.* sshd_proxy_bak \
126 sshd_proxy_orig t10.out t10.out.pub t12.out t12.out.pub \ 127 sshd_proxy_orig t10.out t10.out.pub t12.out t12.out.pub \
127 t2.out t3.out t6.out1 t6.out2 t7.out t7.out.pub \ 128 t2.out t3.out t6.out1 t6.out2 t7.out t7.out.pub \
128 t8.out t8.out.pub t9.out t9.out.pub testdata \ 129 t8.out t8.out.pub t9.out t9.out.pub testdata \
diff --git a/regress/servcfginclude.sh b/regress/servcfginclude.sh
new file mode 100644
index 000000000..b25c8faa8
--- /dev/null
+++ b/regress/servcfginclude.sh
@@ -0,0 +1,154 @@
1# Placed in the Public Domain.
2
3tid="server config include"
4
5cat > $OBJ/sshd_config.i << _EOF
6HostKey $OBJ/host.ssh-ed25519
7Match host a
8 Banner /aa
9
10Match host b
11 Banner /bb
12 Include $OBJ/sshd_config.i.*
13
14Match host c
15 Include $OBJ/sshd_config.i.*
16 Banner /cc
17
18Match host m
19 Include $OBJ/sshd_config.i.*
20
21Match Host d
22 Banner /dd
23
24Match Host e
25 Banner /ee
26 Include $OBJ/sshd_config.i.*
27
28Match Host f
29 Include $OBJ/sshd_config.i.*
30 Banner /ff
31
32Match Host n
33 Include $OBJ/sshd_config.i.*
34_EOF
35
36cat > $OBJ/sshd_config.i.0 << _EOF
37Match host xxxxxx
38_EOF
39
40cat > $OBJ/sshd_config.i.1 << _EOF
41Match host a
42 Banner /aaa
43
44Match host b
45 Banner /bbb
46
47Match host c
48 Banner /ccc
49
50Match Host d
51 Banner /ddd
52
53Match Host e
54 Banner /eee
55
56Match Host f
57 Banner /fff
58_EOF
59
60cat > $OBJ/sshd_config.i.2 << _EOF
61Match host a
62 Banner /aaaa
63
64Match host b
65 Banner /bbbb
66
67Match host c
68 Banner /cccc
69
70Match Host d
71 Banner /dddd
72
73Match Host e
74 Banner /eeee
75
76Match Host f
77 Banner /ffff
78
79Match all
80 Banner /xxxx
81_EOF
82
83trial() {
84 _host="$1"
85 _exp="$2"
86 _desc="$3"
87 test -z "$_desc" && _desc="test match"
88 trace "$_desc host=$_host expect=$_exp"
89 ${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i -T \
90 -C "host=$_host,user=test,addr=127.0.0.1" > $OBJ/sshd_config.out ||
91 fatal "ssh config parse failed: $_desc host=$_host expect=$_exp"
92 _got=`grep -i '^banner ' $OBJ/sshd_config.out | awk '{print $2}'`
93 if test "x$_exp" != "x$_got" ; then
94 fail "$desc_ host $_host include fail: expected $_exp got $_got"
95 fi
96}
97
98trial a /aa
99trial b /bb
100trial c /ccc
101trial d /dd
102trial e /ee
103trial f /fff
104trial m /xxxx
105trial n /xxxx
106trial x none
107
108# Prepare an included config with an error.
109
110cat > $OBJ/sshd_config.i.3 << _EOF
111Banner xxxx
112 Junk
113_EOF
114
115trace "disallow invalid config host=a"
116${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i \
117 -C "host=a,user=test,addr=127.0.0.1" 2>/dev/null && \
118 fail "sshd include allowed invalid config"
119
120trace "disallow invalid config host=x"
121${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i \
122 -C "host=x,user=test,addr=127.0.0.1" 2>/dev/null && \
123 fail "sshd include allowed invalid config"
124
125rm -f $OBJ/sshd_config.i.*
126
127# Ensure that a missing include is not fatal.
128cat > $OBJ/sshd_config.i << _EOF
129HostKey $OBJ/host.ssh-ed25519
130Include $OBJ/sshd_config.i.*
131Banner /aa
132_EOF
133
134trial a /aa "missing include non-fatal"
135
136# Ensure that Match/Host in an included config does not affect parent.
137cat > $OBJ/sshd_config.i.x << _EOF
138Match host x
139_EOF
140
141trial a /aa "included file does not affect match state"
142
143# Ensure the empty include directive is not accepted
144cat > $OBJ/sshd_config.i.x << _EOF
145Include
146_EOF
147
148trace "disallow invalid with no argument"
149${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i.x \
150 -C "host=x,user=test,addr=127.0.0.1" 2>/dev/null && \
151 fail "sshd allowed Include with no argument"
152
153# cleanup
154rm -f $OBJ/sshd_config.i $OBJ/sshd_config.i.* $OBJ/sshd_config.out
diff --git a/regress/test-exec.sh b/regress/test-exec.sh
index 2c9c3f498..f5e3ee6f5 100644
--- a/regress/test-exec.sh
+++ b/regress/test-exec.sh
@@ -1,4 +1,4 @@
1# $OpenBSD: test-exec.sh,v 1.74 2020/01/25 02:57:53 dtucker Exp $ 1# $OpenBSD: test-exec.sh,v 1.75 2020/01/31 23:25:08 djm Exp $
2# Placed in the Public Domain. 2# Placed in the Public Domain.
3 3
4#SUDO=sudo 4#SUDO=sudo
@@ -239,6 +239,7 @@ echo "exec ${SSH} -E${TEST_SSH_LOGFILE} "'"$@"' >>$SSHLOGWRAP
239 239
240chmod a+rx $OBJ/ssh-log-wrapper.sh 240chmod a+rx $OBJ/ssh-log-wrapper.sh
241REAL_SSH="$SSH" 241REAL_SSH="$SSH"
242REAL_SSHD="$SSHD"
242SSH="$SSHLOGWRAP" 243SSH="$SSHLOGWRAP"
243 244
244# Some test data. We make a copy because some tests will overwrite it. 245# Some test data. We make a copy because some tests will overwrite it.