xref: /freebsd/crypto/openssh/regress/proxyjump.sh (revision 2574974648c68c738aec3ff96644d888d7913a37)
1#	$OpenBSD: proxyjump.sh,v 1.1 2026/03/30 07:19:02 djm Exp $
2#	Placed in the Public Domain.
3
4tid="proxyjump"
5
6# Parsing tests
7verbose "basic parsing"
8for jspec in \
9	"jump1" \
10	"user@jump1" \
11	"jump1:2222" \
12	"user@jump1:2222" \
13	"jump1,jump2" \
14	"user1@jump1:2221,user2@jump2:2222" \
15	"ssh://user@host:2223" \
16	; do
17	case "$jspec" in
18	"jump1")		expected="jump1" ;;
19	"user@jump1")		expected="user@jump1" ;;
20	"jump1:2222")		expected="jump1:2222" ;;
21	"user@jump1:2222")	expected="user@jump1:2222" ;;
22	"jump1,jump2")		expected="jump1,jump2" ;;
23	"user1@jump1:2221,user2@jump2:2222")
24		expected="user1@jump1:2221,user2@jump2:2222" ;;
25	"ssh://user@host:2223")	expected="user@host:2223" ;;
26	esac
27	f=`${SSH} -GF /dev/null -oProxyJump="$jspec" somehost | \
28		awk '/^proxyjump /{print $2}'`
29	if [ "$f" != "$expected" ]; then
30		fail "ProxyJump $jspec: expected $expected, got $f"
31	fi
32	f=`${SSH} -GF /dev/null -J "$jspec" somehost | \
33		awk '/^proxyjump /{print $2}'`
34	if [ "$f" != "$expected" ]; then
35		fail "ssh -J $jspec: expected $expected, got $f"
36	fi
37done
38
39verbose "precedence"
40f=`${SSH} -GF /dev/null -oProxyJump=none -oProxyJump=jump1 somehost | \
41	grep "^proxyjump "`
42if [ -n "$f" ]; then
43	fail "ProxyJump=none first did not win"
44fi
45f=`${SSH} -GF /dev/null -oProxyJump=jump -oProxyCommand=foo somehost | \
46	grep "^proxyjump "`
47if [ "$f" != "proxyjump jump" ]; then
48	fail "ProxyJump first did not win over ProxyCommand"
49fi
50f=`${SSH} -GF /dev/null -oProxyCommand=foo -oProxyJump=jump somehost | \
51	grep "^proxycommand "`
52if [ "$f" != "proxycommand foo" ]; then
53	fail "ProxyCommand first did not win over ProxyJump"
54fi
55
56verbose "command-line -J invalid characters"
57cp $OBJ/ssh_config $OBJ/ssh_config.orig
58for jspec in \
59	"host;with;semicolon" \
60	"host'with'quote" \
61	"host\`with\`backtick" \
62	"host\$with\$dollar" \
63	"host(with)brace" \
64	"user;with;semicolon@host" \
65	"user'with'quote@host" \
66	"user\`with\`backtick@host" \
67	"user(with)brace@host" ; do
68	${SSH} -GF /dev/null -J "$jspec" somehost >/dev/null 2>&1
69	if [ $? -ne 255 ]; then
70		fail "ssh -J \"$jspec\" was not rejected"
71	fi
72	${SSH} -GF /dev/null -oProxyJump="$jspec" somehost >/dev/null 2>&1
73	if [ $? -ne 255 ]; then
74		fail "ssh -oProxyJump=\"$jspec\" was not rejected"
75	fi
76done
77# Special characters should be accepted in the config though.
78echo "ProxyJump user;with;semicolon@host;with;semicolon" >> $OBJ/ssh_config
79f=`${SSH} -GF $OBJ/ssh_config somehost | grep "^proxyjump "`
80if [ "$f" != "proxyjump user;with;semicolon@host;with;semicolon" ]; then
81	fail "ProxyJump did not allow special characters in config: $f"
82fi
83
84verbose "functional test"
85# Use different names to avoid the loop detection in ssh.c
86grep -iv HostKeyAlias $OBJ/ssh_config.orig > $OBJ/ssh_config
87cat << _EOF >> $OBJ/ssh_config
88Host jump-host
89	HostkeyAlias jump-host
90Host target-host
91	HostkeyAlias target-host
92_EOF
93cp $OBJ/known_hosts $OBJ/known_hosts.orig
94sed 's/^[^ ]* /jump-host /' < $OBJ/known_hosts.orig > $OBJ/known_hosts
95sed 's/^[^ ]* /target-host /' < $OBJ/known_hosts.orig >> $OBJ/known_hosts
96start_sshd
97
98verbose "functional ProxyJump"
99res=`${REAL_SSH} -F $OBJ/ssh_config -J jump-host target-host echo "SUCCESS" 2>/dev/null`
100if [ "$res" != "SUCCESS" ]; then
101	fail "functional test failed: expected SUCCESS, got $res"
102fi
103