xref: /freebsd/crypto/openssh/regress/envpass.sh (revision cb7aa33ac6cd46a5434798e50363136e64f3ae98)
1#	$OpenBSD: envpass.sh,v 1.5 2022/06/03 04:31:54 djm Exp $
2#	Placed in the Public Domain.
3
4tid="environment passing"
5
6# NB accepted env vars are in test-exec.sh (_XXX_TEST_* and _XXX_TEST)
7
8# Prepare a custom config to test for a configuration parsing bug fixed in 4.0
9cat << EOF > $OBJ/ssh_proxy_envpass
10Host test-sendenv-confparse-bug
11	SendEnv *
12EOF
13cat $OBJ/ssh_proxy >> $OBJ/ssh_proxy_envpass
14cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
15
16trace "pass env, don't accept"
17verbose "test $tid: pass env, don't accept"
18_TEST_ENV=blah ${SSH} -oSendEnv="*" -F $OBJ/ssh_proxy_envpass otherhost \
19	sh << 'EOF'
20	test -z "$_TEST_ENV"
21EOF
22r=$?
23if [ $r -ne 0 ]; then
24	fail "environment found"
25fi
26
27trace "setenv, don't accept"
28verbose "test $tid: setenv, don't accept"
29${SSH} -oSendEnv="*" -F $OBJ/ssh_proxy_envpass -oSetEnv="_TEST_ENV=blah" \
30    otherhost \
31	sh << 'EOF'
32	test -z "$_TEST_ENV"
33EOF
34r=$?
35if [ $r -ne 0 ]; then
36	fail "environment found"
37fi
38
39trace "don't pass env, accept"
40verbose "test $tid: don't pass env, accept"
41_XXX_TEST_A=1 _XXX_TEST_B=2 ${SSH} -F $OBJ/ssh_proxy_envpass otherhost \
42	sh << 'EOF'
43	test -z "$_XXX_TEST_A" && test -z "$_XXX_TEST_B"
44EOF
45r=$?
46if [ $r -ne 0 ]; then
47	fail "environment found"
48fi
49
50trace "pass single env, accept single env"
51verbose "test $tid: pass single env, accept single env"
52_XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -F $OBJ/ssh_proxy_envpass \
53    otherhost sh << 'EOF'
54	test X"$_XXX_TEST" = X"blah"
55EOF
56r=$?
57if [ $r -ne 0 ]; then
58	fail "environment not found"
59fi
60
61trace "pass multiple env, accept multiple env"
62verbose "test $tid: pass multiple env, accept multiple env"
63_XXX_TEST_A=1 _XXX_TEST_B=2 ${SSH} -oSendEnv="_XXX_TEST_*" \
64    -F $OBJ/ssh_proxy_envpass otherhost \
65	sh << 'EOF'
66	test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
67EOF
68r=$?
69if [ $r -ne 0 ]; then
70	fail "environment not found"
71fi
72
73trace "setenv, accept"
74verbose "test $tid: setenv, accept"
75${SSH} -F $OBJ/ssh_proxy_envpass \
76    -oSetEnv="_XXX_TEST_A=1 _XXX_TEST_B=2" otherhost \
77	sh << 'EOF'
78	test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
79EOF
80r=$?
81if [ $r -ne 0 ]; then
82	fail "environment not found"
83fi
84trace "setenv, first match wins"
85verbose "test $tid: setenv, first match wins"
86${SSH} -F $OBJ/ssh_proxy_envpass \
87    -oSetEnv="_XXX_TEST_A=1 _XXX_TEST_A=11 _XXX_TEST_B=2" otherhost \
88	sh << 'EOF'
89	test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
90EOF
91r=$?
92if [ $r -ne 0 ]; then
93	fail "environment not found"
94fi
95
96trace "server setenv wins"
97verbose "test $tid: server setenv wins"
98cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
99echo "SetEnv _XXX_TEST_A=23" >> $OBJ/sshd_proxy
100${SSH} -F $OBJ/ssh_proxy_envpass \
101    -oSetEnv="_XXX_TEST_A=1 _XXX_TEST_B=2" otherhost \
102	sh << 'EOF'
103	test X"$_XXX_TEST_A" = X"23" -a X"$_XXX_TEST_B" = X"2"
104EOF
105r=$?
106if [ $r -ne 0 ]; then
107	fail "environment not found"
108fi
109
110trace "server setenv first match wins"
111verbose "test $tid: server setenv wins"
112cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
113echo "SetEnv _XXX_TEST_A=23 _XXX_TEST_A=42" >> $OBJ/sshd_proxy
114${SSH} -F $OBJ/ssh_proxy_envpass \
115    -oSetEnv="_XXX_TEST_A=1 _XXX_TEST_B=2" otherhost \
116	sh << 'EOF'
117	test X"$_XXX_TEST_A" = X"23" -a X"$_XXX_TEST_B" = X"2"
118EOF
119r=$?
120if [ $r -ne 0 ]; then
121	fail "environment not found"
122fi
123
124
125rm -f $OBJ/ssh_proxy_envpass
126