netcdf-c/ncdap_test/t_auth.c

64 lines
1.5 KiB
C
Raw Normal View History

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
2014-03-15 04:07:35 +08:00
#include "netcdf.h"
2014-04-16 11:25:44 +08:00
/* Embedded user:pwd */
static char* URL1 =
"http://tiggeUser:tigge@remotetest.unidata.ucar.edu/thredds/dodsC/restrict/testData.nc";
/* user:pwd from .dodsrc*/
static char* URL2 =
"http://remotetest.unidata.ucar.edu/thredds/dodsC/restrict/testData.nc";
/* .dodsrc file */
static char* DODSRC = "HTTP.CREDENTIALS.USER=tiggeUser\nHTTP.CREDENTIALS.PASSWORD=tigge\n";
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);
}
int
main()
{
2014-03-15 04:07:35 +08:00
int ncid,retval,pass;
char** url;
2014-04-16 11:25:44 +08:00
FILE* dodsrc;
printf("Testing: Http Basic Authorization\n\n");
printf("Embedded user:pwd: %s\n",URL1);
pass = 1; /* assume success */
retval = nc_open(URL1, 0, &ncid);
if(retval != NC_NOERR) {
pass = 0;
printf("*** FAIL: Embedded user:pwd %s\n",URL1);
} else
retval = nc_close(ncid);
2014-04-16 11:25:44 +08:00
printf(".dodsrc user:pwd: %s\n",URL1);
dodsrc = fopen(".dodsrc","w");
if(dodsrc == NULL) {
fprintf(stderr,"Cannot create .dodsrc\n");
exit(1);
}
fprintf(dodsrc,DODSRC);
fclose(dodsrc);
retval = nc_open(URL1, 0, &ncid);
if(retval != NC_NOERR) {
pass = 0;
printf("*** FAIL: .dodsrc user:pwd %s\n",URL1);
} else
2014-03-15 04:07:35 +08:00
retval = nc_close(ncid);
2014-04-16 11:25:44 +08:00
// unlink(".dodsrc"); /* delete the file */
if(!pass)
2014-03-15 04:07:35 +08:00
return 1;
2014-04-16 11:25:44 +08:00
printf("*** PASS: Http Basic Authorization\n");
return 0;
}