2013-11-16 02:38:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-10-05 05:59:16 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-15 04:07:35 +08:00
|
|
|
#include "netcdf.h"
|
2013-11-16 02:38:54 +08:00
|
|
|
|
2014-10-05 05:59:16 +08:00
|
|
|
#define USERPWD "tiggeUser:tigge"
|
|
|
|
|
|
|
|
#define URL1 "https://tiggeUser:tigge@%s/thredds/dodsC/restrict/testData.nc"
|
|
|
|
#define URL2 "https://%s/thredds/dodsC/restrict/testData.nc"
|
|
|
|
|
2014-04-16 11:25:44 +08:00
|
|
|
/* Embedded user:pwd */
|
2014-10-05 05:59:16 +08:00
|
|
|
static char url1[1024];
|
|
|
|
|
2014-04-16 11:25:44 +08:00
|
|
|
/* user:pwd from .dodsrc*/
|
2014-10-05 05:59:16 +08:00
|
|
|
static char url2[1024];
|
|
|
|
|
2014-07-30 01:04:29 +08:00
|
|
|
/* Test redirect */
|
2014-10-05 05:59:16 +08:00
|
|
|
static char* url3 =
|
2014-07-30 01:04:29 +08:00
|
|
|
"http://tiggeUser:tigge@thredds-test.ucar.edu/thredds/dodsC/restrict/testData.nc";
|
2014-04-16 11:25:44 +08:00
|
|
|
|
|
|
|
/* .dodsrc file */
|
2014-04-17 04:08:12 +08:00
|
|
|
static char* CONTENT = "HTTP.CREDENTIALS.USER=tiggeUser\nHTTP.CREDENTIALS.PASSWORD=tigge\n";
|
2013-11-16 02:38:54 +08:00
|
|
|
|
2014-10-05 05:59:16 +08:00
|
|
|
#ifdef DEBUG
|
2013-11-16 02:38:54 +08:00
|
|
|
static void
|
|
|
|
CHECK(int e, const char* msg)
|
|
|
|
{
|
|
|
|
if(e == NC_NOERR) return;
|
|
|
|
if(msg == NULL) msg = "Error";
|
|
|
|
printf("%s: %s\n", msg, nc_strerror(e));
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-10-05 05:59:16 +08:00
|
|
|
#endif
|
2014-04-17 04:08:12 +08:00
|
|
|
|
2013-11-16 02:38:54 +08:00
|
|
|
int
|
2014-04-17 04:08:12 +08:00
|
|
|
main(int argc, char** argv)
|
2013-11-16 02:38:54 +08:00
|
|
|
{
|
2014-03-15 04:07:35 +08:00
|
|
|
int ncid,retval,pass;
|
2014-04-16 11:25:44 +08:00
|
|
|
FILE* dodsrc;
|
2014-10-05 05:59:16 +08:00
|
|
|
char* envv;
|
|
|
|
|
|
|
|
envv = getenv("THREDDSTESTSERVER");
|
|
|
|
if(envv == NULL) {
|
|
|
|
envv = "remotetest.unidata.ucar.edu";
|
|
|
|
} else { /* walk past the schema and // */
|
|
|
|
char* p = strchr(envv,':');
|
|
|
|
if(p == NULL) {
|
|
|
|
fprintf(stderr,"URL has no schema: %s\n",url1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
envv = p+3;
|
|
|
|
}
|
|
|
|
snprintf(url1,sizeof(url1),URL1,envv);
|
|
|
|
snprintf(url2,sizeof(url2),URL2,envv);
|
|
|
|
|
|
|
|
printf("url1: %s\n",url1);
|
|
|
|
printf("url2: %s\n",url2);
|
|
|
|
fflush(stdout);
|
|
|
|
|
2014-04-16 11:25:44 +08:00
|
|
|
pass = 1; /* assume success */
|
2014-04-17 04:08:12 +08:00
|
|
|
|
2014-04-16 11:25:44 +08:00
|
|
|
dodsrc = fopen(".dodsrc","w");
|
|
|
|
if(dodsrc == NULL) {
|
|
|
|
fprintf(stderr,"Cannot create .dodsrc\n");
|
2014-04-17 04:08:12 +08:00
|
|
|
exit(1);
|
2014-04-16 11:25:44 +08:00
|
|
|
}
|
2014-04-17 04:08:12 +08:00
|
|
|
fprintf(dodsrc,CONTENT);
|
2014-04-16 11:25:44 +08:00
|
|
|
fclose(dodsrc);
|
2014-04-17 04:08:12 +08:00
|
|
|
|
|
|
|
printf("Testing: Http Basic Authorization\n\n");
|
|
|
|
if(1) {
|
2014-10-05 05:59:16 +08:00
|
|
|
printf("Embedded user:pwd: %s\n",url1);
|
|
|
|
retval = nc_open(url1, 0, &ncid);
|
2014-04-17 04:08:12 +08:00
|
|
|
if(retval != NC_NOERR) {
|
|
|
|
pass = 0;
|
|
|
|
printf("*** FAIL: Embedded user:pwd\n");
|
|
|
|
} else {
|
|
|
|
printf("*** PASS: Embedded user:pwd\n");
|
|
|
|
retval = nc_close(ncid);
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(1) {
|
2014-10-05 05:59:16 +08:00
|
|
|
printf(".dodsrc user:pwd: %s\n",url2);
|
2014-04-17 04:08:12 +08:00
|
|
|
|
2014-10-05 05:59:16 +08:00
|
|
|
retval = nc_open(url2, 0, &ncid);
|
2014-04-17 04:08:12 +08:00
|
|
|
if(retval != NC_NOERR) {
|
|
|
|
pass = 0;
|
|
|
|
printf("*** FAIL: .dodsrc user:pwd\n");
|
|
|
|
} else {
|
|
|
|
retval = nc_close(ncid);
|
|
|
|
printf("*** PASS: .dodsrc user:pwd\n");
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
unlink(".dodsrc"); /* delete the file */
|
2014-07-30 01:04:29 +08:00
|
|
|
|
|
|
|
printf("Testing: Http Basic Redirect\n\n");
|
|
|
|
if(1) {
|
2014-10-05 05:59:16 +08:00
|
|
|
printf("Basic redirect: %s\n",url3);
|
|
|
|
retval = nc_open(url3, 0, &ncid);
|
2014-07-30 01:04:29 +08:00
|
|
|
if(retval != NC_NOERR) {
|
|
|
|
printf("*** XFAIL: Basic redirect\n");
|
|
|
|
} else {
|
|
|
|
printf("*** PASS: Basic redirect\n");
|
|
|
|
retval = nc_close(ncid);
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2014-04-17 04:08:12 +08:00
|
|
|
return !pass;
|
2013-11-16 02:38:54 +08:00
|
|
|
}
|