]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/regress/envpass.sh
libevent: Import libevent 2.1.12
[FreeBSD/FreeBSD.git] / crypto / openssh / regress / envpass.sh
1 #       $OpenBSD: envpass.sh,v 1.5 2022/06/03 04:31:54 djm Exp $
2 #       Placed in the Public Domain.
3
4 tid="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
9 cat << EOF > $OBJ/ssh_proxy_envpass
10 Host test-sendenv-confparse-bug
11         SendEnv *
12 EOF
13 cat $OBJ/ssh_proxy >> $OBJ/ssh_proxy_envpass
14 cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
15
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 \
19         sh << 'EOF'
20         test -z "$_TEST_ENV"
21 EOF
22 r=$?
23 if [ $r -ne 0 ]; then
24         fail "environment found"
25 fi
26
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" \
30     otherhost \
31         sh << 'EOF'
32         test -z "$_TEST_ENV"
33 EOF
34 r=$?
35 if [ $r -ne 0 ]; then
36         fail "environment found"
37 fi
38
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 \
42         sh << 'EOF'
43         test -z "$_XXX_TEST_A" && test -z "$_XXX_TEST_B"
44 EOF
45 r=$?
46 if [ $r -ne 0 ]; then
47         fail "environment found"
48 fi
49
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 \
53     otherhost sh << 'EOF'
54         test X"$_XXX_TEST" = X"blah"
55 EOF
56 r=$?
57 if [ $r -ne 0 ]; then
58         fail "environment not found"
59 fi
60
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 \
65         sh << 'EOF'
66         test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
67 EOF
68 r=$?
69 if [ $r -ne 0 ]; then
70         fail "environment not found"
71 fi
72
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 \
77         sh << 'EOF'
78         test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
79 EOF
80 r=$?
81 if [ $r -ne 0 ]; then
82         fail "environment not found"
83 fi
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 \
88         sh << 'EOF'
89         test X"$_XXX_TEST_A" = X"1" -a X"$_XXX_TEST_B" = X"2"
90 EOF
91 r=$?
92 if [ $r -ne 0 ]; then
93         fail "environment not found"
94 fi
95
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 \
102         sh << 'EOF'
103         test X"$_XXX_TEST_A" = X"23" -a X"$_XXX_TEST_B" = X"2"
104 EOF
105 r=$?
106 if [ $r -ne 0 ]; then
107         fail "environment not found"
108 fi
109
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 \
116         sh << 'EOF'
117         test X"$_XXX_TEST_A" = X"23" -a X"$_XXX_TEST_B" = X"2"
118 EOF
119 r=$?
120 if [ $r -ne 0 ]; then
121         fail "environment not found"
122 fi
123
124
125 rm -f $OBJ/ssh_proxy_envpass