1 # $OpenBSD: envpass.sh,v 1.5 2022/06/03 04:31:54 djm Exp $
2 # Placed in the Public Domain.
4 tid="environment passing"
6 # NB accepted env vars are in test-exec.sh (_XXX_TEST_* and _XXX_TEST)
8 # Prepare a custom config to test for a configuration parsing bug fixed in 4.0
9 cat << EOF > $OBJ/ssh_proxy_envpass
10 Host test-sendenv-confparse-bug
13 cat $OBJ/ssh_proxy >> $OBJ/ssh_proxy_envpass
14 cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
16 trace "pass env, don't accept"
17 verbose "test $tid: pass env, don't accept"
18 _TEST_ENV=blah ${SSH} -oSendEnv="*" -F $OBJ/ssh_proxy_envpass otherhost \
24 fail "environment found"
27 trace "setenv, don't accept"
28 verbose "test $tid: setenv, don't accept"
29 ${SSH} -oSendEnv="*" -F $OBJ/ssh_proxy_envpass -oSetEnv="_TEST_ENV=blah" \
36 fail "environment found"
39 trace "don't pass env, accept"
40 verbose "test $tid: don't pass env, accept"
41 _XXX_TEST_A=1 _XXX_TEST_B=2 ${SSH} -F $OBJ/ssh_proxy_envpass otherhost \
43 test -z "$_XXX_TEST_A" && test -z "$_XXX_TEST_B"
47 fail "environment found"
50 trace "pass single env, accept single env"
51 verbose "test $tid: pass single env, accept single env"
52 _XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -F $OBJ/ssh_proxy_envpass \
54 test X"$_XXX_TEST" = X"blah"
58 fail "environment not found"
61 trace "pass multiple env, accept multiple env"
62 verbose "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 \
66 test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
70 fail "environment not found"
73 trace "setenv, accept"
74 verbose "test $tid: setenv, accept"
75 ${SSH} -F $OBJ/ssh_proxy_envpass \
76 -oSetEnv="_XXX_TEST_A=1 _XXX_TEST_B=2" otherhost \
78 test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
82 fail "environment not found"
84 trace "setenv, first match wins"
85 verbose "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 \
89 test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
93 fail "environment not found"
96 trace "server setenv wins"
97 verbose "test $tid: server setenv wins"
98 cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
99 echo "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 \
103 test X"$_XXX_TEST_A" = X"23" -a X"$_XXX_TEST_B" = X"2"
106 if [ $r -ne 0 ]; then
107 fail "environment not found"
110 trace "server setenv first match wins"
111 verbose "test $tid: server setenv wins"
112 cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
113 echo "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 \
117 test X"$_XXX_TEST_A" = X"23" -a X"$_XXX_TEST_B" = X"2"
120 if [ $r -ne 0 ]; then
121 fail "environment not found"
125 rm -f $OBJ/ssh_proxy_envpass