forked from Unidata/netcdf-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testauth.sh
executable file
·299 lines (255 loc) · 5.98 KB
/
testauth.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/sh
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
. ../test_common.sh
# Enable if using localhost
LOCAL=1
RCEMBED=1
RCLOCAL=1
RCHOME=1
RCENV=1
RCPREC=1
# Not currently testable in netcdf
#RCSPEC=1
#SHOW=1
#DBG=1
# Choose at most 1
#GDB=1
#VG=1
NFL=1
WD=`pwd`
NETRCFILE=$WD/test_auth_netrc
# This is the control variable; set when needed
unset NETRC
COOKIES="${WD}/test_auth_cookies"
RC=.daprc
OCLOGFILE=stderr
if test "x$DBG" = x1 ; then
SHOW=1
fi
# Major parameters
BASICCOMBO="tiggeUser:tigge"
BADCOMBO="tiggeUser:xxxxx"
URLPATH="thredds/dodsC/testRestrictedDataset/testData2.nc"
PROTO=http
if test "x$LOCAL" = x ; then
URLSERVER="remotetest.unidata.ucar.edu"
else
URLSERVER="localhost:8081"
fi
# See if we need to override
if test "x$URS" != "x" ; then
#https://54.86.135.31/opendap/data/nc/fnoc1.nc.dds
URLSERVER="54.86.135.31"
URLPATH="opendap/data/nc/fnoc1.nc"
BASICCOMBO="$URS"
RCEMBED=0
NETRC=$NETRCFILE
PROTO=https
fi
if test "x$DBG" = x1 ; then
URLPATH="${URLPATH}#log&show=fetch"
fi
# Split the combo
BASICUSER=`echo $BASICCOMBO | cut -d: -f1`
BASICPWD=`echo $BASICCOMBO | cut -d: -f2`
OUTPUT="./.output"
if test "x$TEMP" = x ; then
TEMP="/tmp"
fi
TEMP=`echo "$TEMP" | sed -e "s|/$||"`
LOCALRC=./$RC
HOMERC=${HOME}/$RC
HOMERC=`echo "$HOMERC" | sed -e "s|//|/|g"`
SPECRC="$TEMP/temprc"
ENVRC="$WD/envrc"
createrc() {
RCP="$1" ; shift
unset NOPWD
unset BADPWD
while [[ $# > 0 ]] ; do
case "$1" in
nopwd) NOPWD=1 ;;
badpwd) BADPWD=1 ;;
*) ;;
esac
shift
done
if test "x$RCP" != x ; then
rm -f $RCP
echo "Creating rc file $RCP"
else
echo "createrc: no rc specified"
exit 1
fi
if test "x${DBG}" != x ; then
echo "HTTP.VERBOSE=1" >>$RCP
fi
echo "HTTP.COOKIEJAR=${COOKIES}" >>$RCP
if test "x${URS}" = x ; then
if test "x${NOPWD}" = x ; then
if test "x${BADPWD}" = x ; then
echo "HTTP.CREDENTIALS.USERPASSWORD=${BASICCOMBO}" >>$RCP
else
echo "HTTP.CREDENTIALS.USERPASSWORD=${BADCOMBO}" >>$RCP
fi
fi
fi
if test "x${NETRC}" != x && test "x$NFL" = x ; then
echo "HTTP.NETRC=${NETRC}" >>$RCP
fi
}
createnetrc() {
NCP="$1" ; shift
unset NOPWD
unset BADPWD
while [[ $# > 0 ]] ; do
case "$1" in
nopwd) NOPWD=1 ;;
badpwd) BADPWD=1 ;;
*) ;;
esac
shift
done
if test "x$NCP" != x ; then
rm -f $NCP
echo "Creating netrc file $NCP"
else
echo "createnetrc: no rc specified"
exit 1
fi
if test "x$URS" != x ; then
echo "machine uat.urs.earthdata.nasa.gov login $BASICUSER password $BASICPWD" >>$NCP
#echo "machine 54.86.135.31 login $BASICUSER password $BASICPWD" >>$1
else
echo -n "${PROTO}://$URLSERVER/$URLPATH" >>$NCP
if test "x$NOPWD" = x ; then
if test "x$BADPWD" = x ; then
echo -n " login $BASICUSER password $BASICPWD" >>$NCP
else
echo -n " login $BASICUSER password xxxxxx" >>$NCP
fi
fi
echo "" >>$NCP
fi
}
reset() {
for f in ./$RC $HOME/$RC $SPECRC $ENVRC $COOKIES $NETRC $OUTPUT ; do
rm -f ${f}
done
unset DAPRCFILE
}
restore() {
reset
for f in ./$RC $HOME/$RC $SPECRC $ENVRC $COOKIES $NETRC ; do
if test -f ${f}.save ; then
echo "restoring old ${f}"
cp ${f}.save ${f}
fi
done
}
save() {
for f in ./$RC $HOME/$RC $SPECRC $ENVRC $COOKIES $NETRC ; do
if test -f $f ; then
if test -f ${f}.save ; then
ignore=1
else
echo "saving $f"
cp ${f} ${f}.save
fi
fi
done
}
show() {
if test "x$SHOW" = x1 ; then cat $OUTPUT; fi
if test "x$OUTPUT" != "x"; then rm -f $OUTPUT; fi
}
# Assemble the ncdump command
if test "x$DBG" = x1; then
NCDUMP="$NCDUMP -D1"
fi
if test "x$GDB" = x1 ; then
NCDUMP="gdb --args $NCDUMP"
fi
if test "x$VG" = x1 ; then
NCDUMP="valgrind --leak-check=full $NCDUMP"
fi
# Initialize
save
reset
if test "x$RCEMBED" = x1 ; then
echo "***Testing rc file with embedded user:pwd"
URL="${PROTO}://${BASICCOMBO}@${URLSERVER}/$URLPATH"
unset NETRC
# Invoke ncdump to extract a file the URL
echo "command: ${NCDUMP} -h ${URL} > $OUTPUT"
${NCDUMP} -h "$URL" > $OUTPUT
show
fi
# Rest of tests assume these defaults
URL="${PROTO}://${URLSERVER}/$URLPATH"
NETRC=$NETRCFILE
if test "x$RCLOCAL" = x1 ; then
echo "***Testing rc file in local directory"
# Create the rc file and (optional) netrc fil in ./
reset
createnetrc $NETRC
createrc $LOCALRC
# Invoke ncdump to extract a file using the URL
echo "command: ${NCDUMP} -h ${URL} > $OUTPUT"
${NCDUMP} -h "$URL" > $OUTPUT
show
fi
if test "x$RCHOME" = x1 ; then
echo "***Testing rc file in home directory"
# Create the rc file and (optional) netrc file in ./
reset
createnetrc $NETRC
createrc $HOMERC
# Invoke ncdump to extract a file the URL
echo "command: ${NCDUMP} -h ${URL} > $OUTPUT"
${NCDUMP} -h "$URL" > $OUTPUT
show
fi
if test "x$RCSPEC" == x1 ; then
echo "*** Testing rc file in specified directory"
# Create the rc file and (optional) netrc file
reset
createnetrc $NETRC
createrc $SPECRC
# Invoke ncdump to extract a file the URL
echo "command: ${NCDUMP} -h ${URL} > $OUTPUT"
${NCDUMP} -h "$URL" > $OUTPUT
show
fi
if test "x$RCENV" = x1 ; then
echo "*** Testing rc file using env variable"
# Create the rc file and (optional) netrc file
reset
createnetrc $NETRC
echo "ENV: export DAPRCFILE=$ENVRC"
export DAPRCFILE=$ENVRC
createrc $DAPRCFILE
# Invoke ncdump to extract a file the URL
echo "command: ${NCDUMP} -h ${URL} > $OUTPUT"
${NCDUMP} -h "$URL" > $OUTPUT
show
export DAPRCFILE=
fi
# Test that .daprc overrides netcrc for password
URL="${PROTO}://${URLSERVER}/$URLPATH"
NETRC=$NETRCFILE
if test "x$RCPREC" = x1 ; then
echo "***Testing rc vs netrc file precedence"
# Create the rc file and (optional) netrc file in ./
reset
createnetrc $NETRC badpwd
createrc $LOCALRC
# Invoke ncdump to extract a file using the URL
echo "command: ${NCDUMP} -h ${URL} > $OUTPUT"
${NCDUMP} -h "$URL" > $OUTPUT
${NCDUMP} -h "$URL"
show
fi
reset
restore
exit