]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/regress/sshcfgparse.sh
Merge once more from ^/vendor/llvm-project/release-10.x, to get the
[FreeBSD/FreeBSD.git] / crypto / openssh / regress / sshcfgparse.sh
1 #       $OpenBSD: sshcfgparse.sh,v 1.4 2018/07/04 13:51:12 djm Exp $
2 #       Placed in the Public Domain.
3
4 tid="ssh config parse"
5
6 expect_result_present() {
7         _str="$1" ; shift
8         for _expect in "$@" ; do
9                 echo "$f" | tr ',' '\n' | grep "^$_expect\$" >/dev/null
10                 if test $? -ne 0 ; then
11                         fail "missing expected \"$_expect\" from \"$_str\""
12                 fi
13         done
14 }
15 expect_result_absent() {
16         _str="$1" ; shift
17         for _expect in "$@" ; do
18                 echo "$f" | tr ',' '\n' | grep "^$_expect\$" >/dev/null
19                 if test $? -eq 0 ; then
20                         fail "unexpected \"$_expect\" present in \"$_str\""
21                 fi
22         done
23 }
24
25 verbose "reparse minimal config"
26 (${SSH} -G -F $OBJ/ssh_config somehost >$OBJ/ssh_config.1 &&
27  ${SSH} -G -F $OBJ/ssh_config.1 somehost >$OBJ/ssh_config.2 &&
28  diff $OBJ/ssh_config.1 $OBJ/ssh_config.2) || fail "reparse minimal config"
29
30 verbose "ssh -W opts"
31 f=`${SSH} -GF $OBJ/ssh_config host | awk '/exitonforwardfailure/{print $2}'`
32 test "$f" = "no" || fail "exitonforwardfailure default"
33 f=`${SSH} -GF $OBJ/ssh_config -W a:1 h | awk '/exitonforwardfailure/{print $2}'`
34 test "$f" = "yes" || fail "exitonforwardfailure enable"
35 f=`${SSH} -GF $OBJ/ssh_config -W a:1 -o exitonforwardfailure=no h | \
36     awk '/exitonforwardfailure/{print $2}'`
37 test "$f" = "no" || fail "exitonforwardfailure override"
38
39 f=`${SSH} -GF $OBJ/ssh_config host | awk '/clearallforwardings/{print $2}'`
40 test "$f" = "no" || fail "clearallforwardings default"
41 f=`${SSH} -GF $OBJ/ssh_config -W a:1 h | awk '/clearallforwardings/{print $2}'`
42 test "$f" = "yes" || fail "clearallforwardings enable"
43 f=`${SSH} -GF $OBJ/ssh_config -W a:1 -o clearallforwardings=no h | \
44     awk '/clearallforwardings/{print $2}'`
45 test "$f" = "no" || fail "clearallforwardings override"
46
47 verbose "user first match"
48 user=`awk '$1=="User" {print $2}' $OBJ/ssh_config`
49 f=`${SSH} -GF $OBJ/ssh_config host | awk '/^user /{print $2}'`
50 test "$f" = "$user" || fail "user from config, expected '$user' got '$f'"
51 f=`${SSH} -GF $OBJ/ssh_config -o user=foo -l bar baz@host | awk '/^user /{print $2}'`
52 test "$f" = "foo" || fail "user first match -oUser, expected 'foo' got '$f' "
53 f=`${SSH} -GF $OBJ/ssh_config -lbar baz@host user=foo baz@host | awk '/^user /{print $2}'`
54 test "$f" = "bar" || fail "user first match -l, expected 'bar' got '$f'"
55 f=`${SSH} -GF $OBJ/ssh_config baz@host -o user=foo -l bar baz@host | awk '/^user /{print $2}'`
56 test "$f" = "baz" || fail "user first match user@host, expected 'baz' got '$f'"
57
58 verbose "pubkeyacceptedkeytypes"
59 # Default set
60 f=`${SSH} -GF none host | awk '/^pubkeyacceptedkeytypes /{print $2}'`
61 expect_result_present "$f" "ssh-ed25519" "ssh-ed25519-cert-v01.*"
62 expect_result_absent "$f" "ssh-dss"
63 # Explicit override
64 f=`${SSH} -GF none -opubkeyacceptedkeytypes=ssh-ed25519 host | \
65     awk '/^pubkeyacceptedkeytypes /{print $2}'`
66 expect_result_present "$f" "ssh-ed25519"
67 expect_result_absent "$f" "ssh-ed25519-cert-v01.*" "ssh-dss"
68 # Removal from default set
69 f=`${SSH} -GF none -opubkeyacceptedkeytypes=-ssh-ed25519-cert* host | \
70     awk '/^pubkeyacceptedkeytypes /{print $2}'`
71 expect_result_present "$f" "ssh-ed25519"
72 expect_result_absent "$f" "ssh-ed25519-cert-v01.*" "ssh-dss"
73 f=`${SSH} -GF none -opubkeyacceptedkeytypes=-ssh-ed25519 host | \
74     awk '/^pubkeyacceptedkeytypes /{print $2}'`
75 expect_result_present "$f" "ssh-ed25519-cert-v01.*"
76 expect_result_absent "$f" "ssh-ed25519" "ssh-dss"
77 # Append to default set.
78 # XXX this will break for !WITH_OPENSSL
79 f=`${SSH} -GF none -opubkeyacceptedkeytypes=+ssh-dss-cert* host | \
80     awk '/^pubkeyacceptedkeytypes /{print $2}'`
81 expect_result_present "$f" "ssh-ed25519" "ssh-dss-cert-v01.*"
82 expect_result_absent "$f" "ssh-dss"
83 f=`${SSH} -GF none -opubkeyacceptedkeytypes=+ssh-dss host | \
84     awk '/^pubkeyacceptedkeytypes /{print $2}'`
85 expect_result_present "$f" "ssh-ed25519" "ssh-ed25519-cert-v01.*" "ssh-dss"
86 expect_result_absent "$f" "ssh-dss-cert-v01.*"
87
88 # cleanup
89 rm -f $OBJ/ssh_config.[012]