Skip to content

Commit a1f8145

Browse files
authored
Merge pull request #2011 from DennisHeimbigner/authfix.dmh
Re-enable DAP2 authorization tests
2 parents 82271ff + b0f85f4 commit a1f8145

19 files changed

+294
-52
lines changed

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,9 @@ IF(MSVC)
10081008
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
10091009
DESTINATION ${netCDF_BINARY_DIR}/ncdump/)
10101010
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
1011-
DESTINATION ${netCDF_BINARY_DIR}/nczarr_test/)
1011+
DESTINATION ${netCDF_BINARY_DIR}/nczarr_test/)
1012+
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
1013+
DESTINATION ${netCDF_BINARY_DIR}/ncdap_test/)
10121014
ENDIF()
10131015
ENDIF()
10141016

RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release
77

88
## 4.8.1 - TBD
99

10+
* [Bug Fix] Re-enable DAP2 authorization testing. See [Github #2011](https://github.com/Unidata/netcdf-c/issues/2011).
1011
* [Bug Fix] Fix bug with windows version of mkstemp that causes failure to create more than 26 temp files. See [Github #1998](https://github.com/Unidata/netcdf-c/pull/1998).
1112
* [Bug Fix] Fix ncdump bug when printing VLENs with basetype char. See [Github #1986](https://github.com/Unidata/netcdf-c/issues/1986).
1213
* [Bug Fixes] The netcdf-c library was incorrectly determining the scope of types referred to by nc_inq_type_equal. See [Github #1959](https://github.com/Unidata/netcdf-c/pull/1959) for more information.

libdap2/cdf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ free1cdfnode(CDFnode* node)
10891089
nullfree(node->ocname);
10901090
nullfree(node->ncbasename);
10911091
nullfree(node->ncfullname);
1092+
nullfree(node->dodsspecial.dimname);
10921093
if(node->attributes != NULL) {
10931094
for(j=0;j<nclistlength(node->attributes);j++) {
10941095
NCattribute* att = (NCattribute*)nclistget(node->attributes,j);
@@ -1099,7 +1100,6 @@ free1cdfnode(CDFnode* node)
10991100
nullfree(att);
11001101
}
11011102
}
1102-
nullfree(node->dodsspecial.dimname);
11031103
nclistfree(node->subnodes);
11041104
nclistfree(node->attributes);
11051105
nclistfree(node->array.dimsetplus);

libdap2/dapattr.c

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ fprintf(stderr,"%s.maxstrlen=%d\n",node->ocname,(int)node->dodsspecial.maxstrlen
7979
#endif
8080
} else if(strcmp(ocname,"DODS.dimName")==0
8181
|| strcmp(ocname,"DODS_EXTRA.dimName")==0) {
82+
nullfree(node->dodsspecial.dimname); /* in case repeated */
83+
node->dodsspecial.dimname = NULL;
8284
if(values != NULL) {
8385
nullfree(node->dodsspecial.dimname);
8486
node->dodsspecial.dimname = nulldup(values[0]);

libdap2/ncd2dispatch.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ fprintf(stderr,"ce=%s\n",dumpconstraint(dapcomm->oc.dapconstraint));
403403
ocstat = oc_open(dapcomm->oc.urltext,&dapcomm->oc.conn);
404404
if(ocstat != OC_NOERR) {THROWCHK(ocstat); goto done;}
405405

406-
#ifdef DEBUG1
407-
(void)oc_trace_curl(dapcomm->oc.conn);
408-
#endif
406+
if(getenv("CURLOPT_VERBOSE") != NULL)
407+
(void)oc_trace_curl(dapcomm->oc.conn);
409408

410409
nullfree(dapcomm->oc.urltext); /* clean up */
411410
dapcomm->oc.urltext = NULL;

libdap4/d4curlfunctions.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ set_curlflag(NCD4INFO* state, int flag)
7171
break;
7272
case CURLOPT_NETRC: case CURLOPT_NETRC_FILE:
7373
if(state->auth->curlflags.netrc) {
74-
SETCURLOPT(state, CURLOPT_NETRC, (OPTARG)CURL_NETRC_REQUIRED);
75-
SETCURLOPT(state, CURLOPT_NETRC_FILE, state->auth->curlflags.netrc);
74+
SETCURLOPT(state, CURLOPT_NETRC, (OPTARG)CURL_NETRC_OPTIONAL);
75+
/* IF HTTP.NETRC is set with "", then assume the default .netrc file (which is apparently CWD) */
76+
if(strlen(state->auth->curlflags.netrc)>0)
77+
SETCURLOPT(state, CURLOPT_NETRC_FILE, state->auth->curlflags.netrc);
7678
}
7779
break;
7880
case CURLOPT_VERBOSE:

libdap4/d4file.c

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ NCD4_open(const char * path, int mode,
117117
ncsetlogging(1);
118118
}
119119

120+
/* Check env values */
121+
if(getenv("CURLOPT_VERBOSE") != NULL)
122+
d4info->auth->curlflags.verbose = 1;
123+
124+
120125
/* Setup a curl connection */
121126
{
122127
CURL* curl = NULL; /* curl handle*/

nc_test4/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ tst_h_scalar tst_rename tst_rename2 tst_rename3 tst_h5_endians \
3535
tst_atts_string_rewrite tst_hdf5_file_compat tst_fill_attr_vanish \
3636
tst_rehash tst_filterparser tst_bug324 tst_types tst_atts3 \
3737
tst_put_vars tst_elatefill tst_udf tst_put_vars_two_unlim_dim \
38-
tst_bug1442 tst_charvlenbug
38+
tst_bug1442
3939

4040
# Temporary I hoped, but hoped in vain.
4141
if !ISCYGWIN
4242
NC4_TESTS += tst_h_strbug tst_h_refs
4343
endif
4444

4545
# Build test programs plus programs used in test scripts.
46-
check_PROGRAMS = $(NC4_TESTS) tst_empty_vlen_unlim
46+
check_PROGRAMS = $(NC4_TESTS) tst_empty_vlen_unlim tst_charvlenbug
4747
TESTS = $(NC4_TESTS) run_empty_vlen_test.sh
4848

4949
# Add these if large file tests are turned on.

nc_test4/tst_misc.sh

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ echo "*** Fail: phony dimension creation"
1616
ECODE=1
1717
fi
1818

19+
if "x$NC_VLEN_NOTEST" = x1 ; then
1920
echo "*** Testing char(*) type printout error in ncdump"
2021
rm -f ./tst_charvlenbug.nc ./tmp
2122
${execdir}/tst_charvlenbug
@@ -25,6 +26,7 @@ else
2526
echo "*** Fail: char(*) ncdump printout"
2627
ECODE=1
2728
fi
29+
fi
2830

2931
rm -f tmp
3032

nc_test4/tst_szip.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -e
88
rm -f testnc.h5 testszip.nc szip_dump.cdl
99

1010
echo "*** Test read of known szip file"
11-
${NCDUMP} ${srcdir}/ref_szip.h5 >szip_dump.cdl
11+
${NCDUMP} -n ref_szip ${srcdir}/ref_szip.h5 >szip_dump.cdl
1212
diff -w ${srcdir}/ref_szip.cdl ./szip_dump.cdl
1313

1414
echo "*** Testing tst_szip "

ncdap_test/CMakeLists.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@ FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.sh)
1414

1515
FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE)
1616

17-
IF(ENABLE_DAP_REMOTE_TESTS)
17+
IF(ENABLE_TESTS)
18+
19+
IF(ENABLE_DAP_REMOTE_TESTS)
1820
BUILD_BIN_TEST(findtestserver)
1921
BUILD_BIN_TEST(pingurl)
20-
ENDIF()
22+
ENDIF()
23+
24+
IF(USE_X_GETOPT)
25+
SET(XGSRC XGetopt.c)
26+
ENDIF()
27+
BUILD_BIN_TEST(pathcvt ${XGSRC})
2128

22-
IF(ENABLE_TESTS)
2329
# Base tests
2430
# The tests are set up as a combination of shell scripts and executables that
2531
# must be run in a particular order. It is painful but will use macros to help
2632
# keep it from being too bad.
2733
# Binary Test Macro
2834

29-
add_sh_test(ncdap tst_ncdap3)
35+
IF(BUILD_UTILITIES)
36+
add_sh_test(ncdap tst_ncdap3)
37+
add_sh_test(ncdap testpathcvt)
38+
ENDIF()
3039

3140
IF(NOT MSVC)
3241
add_bin_env_test(ncdap t_dap3a)

ncdap_test/Makefile.am

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ check_PROGRAMS += t_dap3a test_cvt3 test_vara
3232
TESTS += t_dap3a test_cvt3 test_vara
3333
if BUILD_UTILITIES
3434
TESTS += tst_ncdap3.sh
35+
TESTS += testpathcvt.sh
3536
endif
3637

3738
# remote tests are optional
3839
# because the server may be down or inaccessible
3940

4041
if ENABLE_DAP_REMOTE_TESTS
41-
noinst_PROGRAMS = findtestserver pingurl
42+
noinst_PROGRAMS = findtestserver pingurl pathcvt
4243
findtestserver_SOURCES = findtestserver.c
4344
pingurl_SOURCES = pingurl.c
45+
pathcvt_SOURCES = pathcvt.c
4446
endif
4547

4648
if ENABLE_DAP_REMOTE_TESTS
@@ -91,10 +93,10 @@ EXTRA_DIST = tst_ncdap3.sh \
9193
tst_zero_len_var.sh \
9294
tst_filelists.sh tst_urls.sh tst_utils.sh \
9395
t_dap.c CMakeLists.txt tst_formatx.sh testauth.sh testurl.sh \
94-
t_ncf330.c tst_ber.sh tst_fillmismatch.sh tst_encode.sh \
95-
findtestserver.c.in
96+
t_ncf330.c tst_ber.sh tst_fillmismatch.sh tst_encode.sh testpathcvt.sh \
97+
findtestserver.c.in ref_pathcvt.txt
9698

97-
CLEANFILES = test_varm3 test_cvt3 file_results/* remote_results/* datadds* t_dap3a test_nstride_cached *.exe
99+
CLEANFILES = test_varm3 test_cvt3 file_results/* remote_results/* datadds* t_dap3a test_nstride_cached *.exe tmp*.txt
98100
# This should only be left behind if using parallel io
99101
CLEANFILES += tmp_*
100102

ncdap_test/pathcvt.c

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright 2018, University Corporation for Atmospheric Research
3+
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
4+
*/
5+
6+
#ifdef HAVE_CONFIG_H
7+
#include "config.h"
8+
#endif
9+
10+
#include <stdlib.h>
11+
#include <stdio.h>
12+
#include <string.h>
13+
14+
#ifdef HAVE_UNISTD_H
15+
#include <unistd.h>
16+
#endif
17+
#ifdef HAVE_GETOPT_H
18+
#include <getopt.h>
19+
#endif
20+
21+
#if defined(_WIN32) && !defined(__MINGW32__)
22+
#include "XGetopt.h"
23+
#endif
24+
25+
#include "ncpathmgr.h"
26+
27+
/*
28+
Synopsis
29+
30+
pathcvt [-u|-w|-m|-c] [-e] PATH
31+
32+
Options
33+
-e add backslash escapes to '\' and ' '
34+
Output type options:
35+
-u convert to Unix form of path
36+
-w convert to Windows form of path
37+
-m convert to MSYS form of path
38+
-c convert to Cygwin form of path
39+
40+
Default is to convert to the format used by the platform.
41+
42+
*/
43+
44+
#define DEBUG
45+
46+
struct Options {
47+
int target;
48+
int escape;
49+
int debug;
50+
} cvtoptions;
51+
52+
static char* escape(const char* path);
53+
static void usage(const char* msg);
54+
55+
int
56+
main(int argc, char** argv)
57+
{
58+
int c;
59+
char* cvtpath = NULL;
60+
char* inpath;
61+
62+
memset((void*)&cvtoptions,0,sizeof(cvtoptions));
63+
64+
while ((c = getopt(argc, argv, "cD:ehmuw")) != EOF) {
65+
switch(c) {
66+
case 'c': cvtoptions.target = NCPD_CYGWIN; break;
67+
case 'e': cvtoptions.escape = 1; break;
68+
case 'h': usage(NULL); break;
69+
case 'm': cvtoptions.target = NCPD_MSYS; break;
70+
case 'u': cvtoptions.target = NCPD_NIX; break;
71+
case 'w': cvtoptions.target = NCPD_WIN; break;
72+
case 'D':
73+
sscanf(optarg,"%d",&cvtoptions.debug);
74+
break;
75+
case '?':
76+
usage("unknown option");
77+
break;
78+
}
79+
}
80+
81+
argc -= optind;
82+
argv += optind;
83+
84+
/* If no file arguments left or more than one, print usage message. */
85+
if (argc == 0)
86+
usage("no path specified");
87+
if (argc > 1)
88+
usage("more than one path specified");
89+
inpath = argv[0];
90+
if(cvtoptions.target == NCPD_UNKNOWN)
91+
cvtpath = NCpathcvt(inpath);
92+
else
93+
cvtpath = NCpathcvt_test(inpath,cvtoptions.target,'c');
94+
if(cvtpath && cvtoptions.escape) {
95+
char* path = cvtpath; cvtpath = NULL;
96+
cvtpath = escape(path);
97+
free(path);
98+
}
99+
printf("%s",cvtpath);
100+
if(cvtpath) free(cvtpath);
101+
return 0;
102+
}
103+
104+
static void
105+
usage(const char* msg)
106+
{
107+
if(msg != NULL) fprintf(stderr,"%s\n",msg);
108+
fprintf(stderr,"pathcvt [-u|-w|-m|-c] PATH\n");
109+
if(msg == NULL) exit(0); else exit(1);
110+
}
111+
112+
static char*
113+
escape(const char* path)
114+
{
115+
size_t slen = strlen(path);
116+
const char* p;
117+
char* q;
118+
char* epath = NULL;
119+
120+
epath = (char*)malloc((2*slen) + 1);
121+
if(epath == NULL) usage("out of memtory");
122+
p = path;
123+
q = epath;
124+
for(;*p;p++) {
125+
switch (*p) {
126+
case '\\': case ' ':
127+
*q++ = '\\';
128+
/* fall thru */
129+
default:
130+
*q++ = *p;
131+
break;
132+
}
133+
}
134+
*q = '\0';
135+
return epath;
136+
}
137+

ncdap_test/ref_pathcvt.txt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
path: /xxx/a/b
2+
/xxx/a/b
3+
/cygdrive/c/xxx/a/b
4+
/c/xxx/a/b
5+
c:\\xxx\\a\\b
6+
path: d:/x/y
7+
/d/x/y
8+
/cygdrive/d/x/y
9+
/d/x/y
10+
d:\\x\\y
11+
path: /cygdrive/d/x/y
12+
/d/x/y
13+
/cygdrive/d/x/y
14+
/d/x/y
15+
d:\\x\\y
16+
path: /d/x/y
17+
/d/x/y
18+
/cygdrive/d/x/y
19+
/d/x/y
20+
d:\\x\\y
21+
path: /cygdrive/d
22+
/d
23+
/cygdrive/d
24+
/d
25+
d:
26+
path: /d
27+
/d
28+
/cygdrive/d
29+
/d
30+
d:
31+
path: /cygdrive/d/git/netcdf-c/dap4_test/test_anon_dim.2.syn
32+
/d/git/netcdf-c/dap4_test/test_anon_dim.2.syn
33+
/cygdrive/d/git/netcdf-c/dap4_test/test_anon_dim.2.syn
34+
/d/git/netcdf-c/dap4_test/test_anon_dim.2.syn
35+
d:\\git\\netcdf-c\\dap4_test\\test_anon_dim.2.syn
36+
path: d:\x\y
37+
/d/x/y
38+
/cygdrive/d/x/y
39+
/d/x/y
40+
d:\\x\\y
41+
path: d:\x\y w\z
42+
/d/x/y w/z
43+
/cygdrive/d/x/y w/z
44+
/d/x/y w/z
45+
d:\\x\\y\\ w\\z

0 commit comments

Comments
 (0)