diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-09-30 14:27:10 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-09-30 14:27:10 (GMT) |
commit | b2d661b508a7fc7a2592c13bc6bdc175551f075d (patch) | |
tree | 13baeb0d83a7c2a4c6299993c182b1227c2f6114 /test/s3comms.c | |
parent | 29ab58b58dce556639ea3154e262895773a8a8df (diff) | |
download | hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2 |
Clang-format of source files
Diffstat (limited to 'test/s3comms.c')
-rw-r--r-- | test/s3comms.c | 1661 |
1 files changed, 788 insertions, 873 deletions
diff --git a/test/s3comms.c b/test/s3comms.c index ef48d7a..862914e 100644 --- a/test/s3comms.c +++ b/test/s3comms.c @@ -67,7 +67,6 @@ * *****************************************************************************/ - /*---------------------------------------------------------------------------- * * ifdef flag: JSVERIFY_EXP_ACT @@ -79,7 +78,6 @@ */ #define JSVERIFY_EXP_ACT 1L - /*---------------------------------------------------------------------------- * * Macro: JSFAILED_AT() @@ -96,10 +94,10 @@ * *---------------------------------------------------------------------------- */ -#define JSFAILED_AT() { \ - HDprintf("*FAILED* at %s:%d in %s()...\n", __FILE__, __LINE__, FUNC); \ -} - +#define JSFAILED_AT() \ + { \ + HDprintf("*FAILED* at %s:%d in %s()...\n", __FILE__, __LINE__, FUNC); \ + } /*---------------------------------------------------------------------------- * @@ -124,12 +122,11 @@ * *---------------------------------------------------------------------------- */ -#define FAIL_IF(condition) \ -if (condition) { \ - JSFAILED_AT() \ - goto error; \ -} - +#define FAIL_IF(condition) \ + if (condition) { \ + JSFAILED_AT() \ + goto error; \ + } /*---------------------------------------------------------------------------- * @@ -153,12 +150,11 @@ if (condition) { \ * *---------------------------------------------------------------------------- */ -#define FAIL_UNLESS(condition) \ -if (!(condition)) { \ - JSFAILED_AT() \ - goto error; \ -} - +#define FAIL_UNLESS(condition) \ + if (!(condition)) { \ + JSFAILED_AT() \ + goto error; \ + } /*---------------------------------------------------------------------------- * @@ -190,16 +186,17 @@ jserr_long(long expected, long actual, const char *reason) { if (reason != NULL) { HDprintf("%s\n", reason); - } else { + } + else { HDprintf(" ! Expected %ld\n ! Actual %ld\n", expected, actual); } } -#define JSERR_LONG(expected, actual, reason) { \ - JSFAILED_AT() \ - jserr_long((long)(expected), (long)(actual), reason);\ -} - +#define JSERR_LONG(expected, actual, reason) \ + { \ + JSFAILED_AT() \ + jserr_long((long)(expected), (long)(actual), reason); \ + } /*---------------------------------------------------------------------------- * @@ -234,21 +231,22 @@ jserr_str(const char *expected, const char *actual, const char *reason) { if (reason != NULL) { HDprintf("%s\n", reason); - } else { + } + else { HDprintf("!!! Expected:\n%s\n!!!Actual:\n%s\n", expected, actual); } } -#define JSERR_STR(expected, actual, reason) { \ - JSFAILED_AT() \ - jserr_str((expected), (actual), (reason)); \ -} +#define JSERR_STR(expected, actual, reason) \ + { \ + JSFAILED_AT() \ + jserr_str((expected), (actual), (reason)); \ + } #ifdef JSVERIFY_EXP_ACT /* VERIFY rountines with paramter order (<expected>, <actual> [, <msg> ]) */ - /*---------------------------------------------------------------------------- * * Macro: JSVERIFY() @@ -265,11 +263,11 @@ jserr_str(const char *expected, const char *actual, const char *reason) * *---------------------------------------------------------------------------- */ -#define JSVERIFY(expected, actual, reason) \ -if ((long)(actual) != (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)) \ - goto error; \ -} /* JSVERIFY */ +#define JSVERIFY(expected, actual, reason) \ + if ((long)(actual) != (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)) \ + goto error; \ + } /* JSVERIFY */ #if 0 /* UNUSED */ @@ -289,14 +287,13 @@ if ((long)(actual) != (long)(expected)) { \ * *---------------------------------------------------------------------------- */ -#define JSVERIFY_NOT(expected, actual, reason) \ -if ((long)(actual) == (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)) \ - goto error; \ -} /* JSVERIFY_NOT */ +#define JSVERIFY_NOT(expected, actual, reason) \ + if ((long)(actual) == (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)) \ + goto error; \ + } /* JSVERIFY_NOT */ #endif /* JSVERIFY_NOT unused */ - /*---------------------------------------------------------------------------- * * Macro: JSVERIFY_STR() @@ -313,12 +310,11 @@ if ((long)(actual) == (long)(expected)) { \ * *---------------------------------------------------------------------------- */ -#define JSVERIFY_STR(expected, actual, reason) \ -if (strcmp((actual), (expected)) != 0) { \ - JSERR_STR((expected), (actual), (reason)); \ - goto error; \ -} /* JSVERIFY_STR */ - +#define JSVERIFY_STR(expected, actual, reason) \ + if (strcmp((actual), (expected)) != 0) { \ + JSERR_STR((expected), (actual), (reason)); \ + goto error; \ + } /* JSVERIFY_STR */ #else /* JSVERIFY_EXP_ACT not defined @@ -326,7 +322,6 @@ if (strcmp((actual), (expected)) != 0) { \ * Repeats macros above, but with actual/expected parameters reversed. */ - /*---------------------------------------------------------------------------- * Macro: JSVERIFY() * See: JSVERIFY documentation above. @@ -334,11 +329,11 @@ if (strcmp((actual), (expected)) != 0) { \ * 2017-10-14 *---------------------------------------------------------------------------- */ -#define JSVERIFY(actual, expected, reason) \ -if ((long)(actual) != (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)); \ - goto error; \ -} /* JSVERIFY */ +#define JSVERIFY(actual, expected, reason) \ + if ((long)(actual) != (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)); \ + goto error; \ + } /* JSVERIFY */ #if 0 /* UNUSED */ @@ -349,14 +344,13 @@ if ((long)(actual) != (long)(expected)) { \ * 2017-10-14 *---------------------------------------------------------------------------- */ -#define JSVERIFY_NOT(actual, expected, reason) \ -if ((long)(actual) == (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)) \ - goto error; \ -} /* JSVERIFY_NOT */ +#define JSVERIFY_NOT(actual, expected, reason) \ + if ((long)(actual) == (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)) \ + goto error; \ + } /* JSVERIFY_NOT */ #endif /* JSVERIFY_NOT unused */ - /*---------------------------------------------------------------------------- * Macro: JSVERIFY_STR() * See: JSVERIFY_STR documentation above. @@ -364,22 +358,21 @@ if ((long)(actual) == (long)(expected)) { \ * 2017-10-14 *---------------------------------------------------------------------------- */ -#define JSVERIFY_STR(actual, expected, reason) \ -if (strcmp((actual), (expected)) != 0) { \ - JSERR_STR((expected), (actual), (reason)); \ - goto error; \ -} /* JSVERIFY_STR */ +#define JSVERIFY_STR(actual, expected, reason) \ + if (strcmp((actual), (expected)) != 0) { \ + JSERR_STR((expected), (actual), (reason)); \ + goto error; \ + } /* JSVERIFY_STR */ #endif /* ifdef/else JSVERIFY_EXP_ACT */ - #define S3_TEST_PROFILE_NAME "ros3_vfd_test" #define S3_TEST_RESOURCE_TEXT_RESTRICTED "t8.shakespeare.txt" -#define S3_TEST_RESOURCE_TEXT_PUBLIC "Poe_Raven.txt" -#define S3_TEST_RESOURCE_MISSING "missing.csv" +#define S3_TEST_RESOURCE_TEXT_PUBLIC "Poe_Raven.txt" +#define S3_TEST_RESOURCE_MISSING "missing.csv" -#define S3_TEST_RUN_TIMEOUT 0 /* run tests that might hang */ +#define S3_TEST_RUN_TIMEOUT 0 /* run tests that might hang */ #define S3_TEST_MAX_URL_SIZE 256 /* char array size */ /* Global variables for aws test profile. @@ -394,7 +387,6 @@ static char s3_test_aws_secret_access_key[128] = ""; static char s3_test_bucket_url[S3_TEST_MAX_URL_SIZE] = ""; static hbool_t s3_test_bucket_defined = FALSE; - /*--------------------------------------------------------------------------- * * Function: test_macro_format_credential() @@ -421,15 +413,13 @@ test_macro_format_credential(void) const char date[] = "20130524"; const char region[] = "us-east-1"; const char service[] = "s3"; - const char expected[] = - "AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request"; + const char expected[] = "AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request"; TESTING("test_macro_format_credential"); - FAIL_IF( S3COMMS_MAX_CREDENTIAL_SIZE < - S3COMMS_FORMAT_CREDENTIAL(dest, access, date, region, service) ) + FAIL_IF(S3COMMS_MAX_CREDENTIAL_SIZE < S3COMMS_FORMAT_CREDENTIAL(dest, access, date, region, service)) - JSVERIFY_STR( expected, dest, NULL ) + JSVERIFY_STR(expected, dest, NULL) PASSED(); return 0; @@ -439,7 +429,6 @@ error: } /* end test_macro_format_credential() */ - /*--------------------------------------------------------------------------- * * Function: test_aws_canonical_request() @@ -470,54 +459,65 @@ test_aws_canonical_request(void) }; struct testcase { - const char *exp_request; - const char *exp_headers; - const char *verb; - const char *resource; - unsigned int listsize; - struct header list[5]; + const char * exp_request; + const char * exp_headers; + const char * verb; + const char * resource; + unsigned int listsize; + struct header list[5]; }; /************************ * test-local variables * ************************/ - struct testcase cases[] = { - { "GET\n/some/path.file\n\nhost:somebucket.someserver.somedomain\nrange:bytes=150-244\n\nhost;range\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + struct testcase cases[] = { + { + "GET\n/some/" + "path.file\n\nhost:somebucket.someserver.somedomain\nrange:bytes=150-244\n\nhost;" + "range\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "host;range", "GET", "/some/path.file", 2, - { {"Range", "bytes=150-244"}, + { + {"Range", "bytes=150-244"}, {"Host", "somebucket.someserver.somedomain"}, }, }, - { "HEAD\n/bucketpath/myfile.dat\n\nhost:place.domain\nx-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nx-amz-date:19411207T150803Z\n\nhost;x-amz-content-sha256;x-amz-date\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "host;x-amz-content-sha256;x-amz-date", - "HEAD", - "/bucketpath/myfile.dat", - 3, - { {"x-amz-content-sha256", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, - {"host", "place.domain"}, - {"x-amz-date", "19411207T150803Z"}, - } - }, - { "PUT\n/\n\n\n\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + {"HEAD\n/bucketpath/" + "myfile.dat\n\nhost:place.domain\nx-amz-content-sha256:" + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nx-amz-date:" + "19411207T150803Z\n\nhost;x-amz-content-sha256;x-amz-" + "date\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "host;x-amz-content-sha256;x-amz-date", + "HEAD", + "/bucketpath/myfile.dat", + 3, + { + {"x-amz-content-sha256", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, + {"host", "place.domain"}, + {"x-amz-date", "19411207T150803Z"}, + }}, + { + "PUT\n/\n\n\n\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "", "PUT", "/", 0, - {{"",""},}, /* unused; satisfies compiler */ + { + {"", ""}, + }, /* unused; satisfies compiler */ }, }; /* struct testcase cases[] */ - struct testcase *C = NULL; - char cr_dest[512]; /* canonical request */ - hrb_t *hrb = NULL; /* http request buffer object */ - unsigned int i = 0; /* looping/indexing */ - unsigned int j = 0; /* looping/indexing */ - hrb_node_t *node = NULL; /* http headers list pointer */ - unsigned int n_cases = 3; - char sh_dest[64]; /* signed headers */ + struct testcase *C = NULL; + char cr_dest[512]; /* canonical request */ + hrb_t * hrb = NULL; /* http request buffer object */ + unsigned int i = 0; /* looping/indexing */ + unsigned int j = 0; /* looping/indexing */ + hrb_node_t * node = NULL; /* http headers list pointer */ + unsigned int n_cases = 3; + char sh_dest[64]; /* signed headers */ TESTING("test_aws_canonical_request"); @@ -525,49 +525,40 @@ test_aws_canonical_request(void) /* pre-test bookkeeping */ C = &cases[i]; - for (j = 0; j < 256; j++) { cr_dest[j] = 0; } /* zero request buffer */ - for (j = 0; j < 64; j++) { sh_dest[j] = 0; } /* zero headers buffer */ + for (j = 0; j < 256; j++) { + cr_dest[j] = 0; + } /* zero request buffer */ + for (j = 0; j < 64; j++) { + sh_dest[j] = 0; + } /* zero headers buffer */ /* create HTTP request object with given verb, resource/path */ - hrb = H5FD_s3comms_hrb_init_request(C->verb, - C->resource, - "HTTP/1.1"); + hrb = H5FD_s3comms_hrb_init_request(C->verb, C->resource, "HTTP/1.1"); HDassert(hrb->body == NULL); /* Create headers list from test case input */ for (j = 0; j < C->listsize; j++) { - FAIL_IF( FAIL == - H5FD_s3comms_hrb_node_set( - &node, - C->list[j].name, - C->list[j].value)); + FAIL_IF(FAIL == H5FD_s3comms_hrb_node_set(&node, C->list[j].name, C->list[j].value)); } hrb->first_header = node; /* test */ - JSVERIFY( SUCCEED, - H5FD_s3comms_aws_canonical_request( - cr_dest, - 512, - sh_dest, - 64, - hrb), - " unable to compose canonical request" ) - JSVERIFY_STR( C->exp_headers, sh_dest, NULL ) - JSVERIFY_STR( C->exp_request, cr_dest, NULL ) + JSVERIFY(SUCCEED, H5FD_s3comms_aws_canonical_request(cr_dest, 512, sh_dest, 64, hrb), + " unable to compose canonical request") + JSVERIFY_STR(C->exp_headers, sh_dest, NULL) + JSVERIFY_STR(C->exp_request, cr_dest, NULL) /* tear-down */ while (node != NULL) { - FAIL_IF( FAIL == - H5FD_s3comms_hrb_node_set(&node, node->name, NULL)); + FAIL_IF(FAIL == H5FD_s3comms_hrb_node_set(&node, node->name, NULL)); } HDassert(NULL == node); - FAIL_IF( FAIL == H5FD_s3comms_hrb_destroy(&hrb)); + FAIL_IF(FAIL == H5FD_s3comms_hrb_destroy(&hrb)); HDassert(NULL == hrb); } /* for each test case */ @@ -576,35 +567,20 @@ test_aws_canonical_request(void) * ERROR CASES * ***************/ - /* malformed hrb and/or node-list - */ - JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request( - cr_dest, - 20, - sh_dest, - 20, - NULL), - "http request object cannot be null" ) + /* malformed hrb and/or node-list + */ + JSVERIFY(FAIL, H5FD_s3comms_aws_canonical_request(cr_dest, 20, sh_dest, 20, NULL), + "http request object cannot be null") hrb = H5FD_s3comms_hrb_init_request("GET", "/", "HTTP/1.1"); - JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request( - NULL, - 20, - sh_dest, - 20, - hrb), - "canonical request destination cannot be NULL" ) - - JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request( - cr_dest, - 20, - NULL, - 20, - hrb), - "signed headers destination cannot be null" ) - - FAIL_IF( FAIL == H5FD_s3comms_hrb_destroy(&hrb) ) - HDassert( NULL == hrb ); + JSVERIFY(FAIL, H5FD_s3comms_aws_canonical_request(NULL, 20, sh_dest, 20, hrb), + "canonical request destination cannot be NULL") + + JSVERIFY(FAIL, H5FD_s3comms_aws_canonical_request(cr_dest, 20, NULL, 20, hrb), + "signed headers destination cannot be null") + + FAIL_IF(FAIL == H5FD_s3comms_hrb_destroy(&hrb)) + HDassert(NULL == hrb); PASSED(); return 0; @@ -613,8 +589,8 @@ error: if (node != NULL) { while (node != NULL) - (void)H5FD_s3comms_hrb_node_set(&node, node->name, NULL); - HDassert( node == NULL ); + (void)H5FD_s3comms_hrb_node_set(&node, node->name, NULL); + HDassert(node == NULL); } if (hrb != NULL) { (void)H5FD_s3comms_hrb_destroy(&hrb); @@ -624,7 +600,6 @@ error: } /* end test_aws_canonical_request() */ - /*--------------------------------------------------------------------------- * * Function: test_bytes_to_hex @@ -662,20 +637,20 @@ test_bytes_to_hex(void) ************************/ struct testcase cases[] = { - { "52F3000C9A", - {82,243,0,12,154}, + { + "52F3000C9A", + {82, 243, 0, 12, 154}, 5, FALSE, }, - { "009a0cf3005200", /* lowercase alphas */ - {0,154,12,243,0,82,0}, + { + "009a0cf3005200", /* lowercase alphas */ + {0, 154, 12, 243, 0, 82, 0}, 7, TRUE, }, - { "", - {17,63,26,56}, - 0, - FALSE, /* irrelevant */ + { + "", {17, 63, 26, 56}, 0, FALSE, /* irrelevant */ }, }; int i = 0; @@ -683,8 +658,6 @@ test_bytes_to_hex(void) char out[17]; int out_off = 0; - - TESTING("bytes-to-hex"); for (i = 0; i < n_cases; i++) { @@ -692,25 +665,15 @@ test_bytes_to_hex(void) out[out_off] = 0; } - JSVERIFY( SUCCEED, - H5FD_s3comms_bytes_to_hex(out, - cases[i].in, - cases[i].size, - cases[i].lower), - NULL ) + JSVERIFY(SUCCEED, H5FD_s3comms_bytes_to_hex(out, cases[i].in, cases[i].size, cases[i].lower), NULL) JSVERIFY_STR(cases[i].exp, out, NULL) } /* dest cannot be null */ - JSVERIFY( FAIL, - H5FD_s3comms_bytes_to_hex( - NULL, - (const unsigned char *)"nada", - 5, - FALSE), - "destination cannot be null" ) + JSVERIFY(FAIL, H5FD_s3comms_bytes_to_hex(NULL, (const unsigned char *)"nada", 5, FALSE), + "destination cannot be null") PASSED(); return 0; @@ -720,7 +683,6 @@ error: } /* end test_bytes_to_hex() */ - /*--------------------------------------------------------------------------- * * Function: test_hrb_init_request() @@ -759,35 +721,40 @@ test_hrb_init_request(void) ************************/ struct testcase cases[] = { - { "get HTTP request just as we provided", + { + "get HTTP request just as we provided", "GET", "/path/to/some/file", "/path/to/some/file", "HTTP/1.1", FALSE, }, - { "null verb substitues to GET", + { + "null verb substitues to GET", NULL, "/MYPATH/MYFILE.tiff", "/MYPATH/MYFILE.tiff", "HTTP/1.1", FALSE, }, - { "demonstrate non-GET verb", + { + "demonstrate non-GET verb", "HEAD", "/MYPATH/MYFILE.tiff", "/MYPATH/MYFILE.tiff", "HTTP/1.1", FALSE, }, - { "slash prepended to resource path, if necessary", + { + "slash prepended to resource path, if necessary", NULL, "MYPATH/MYFILE.tiff", "/MYPATH/MYFILE.tiff", NULL, FALSE, }, - { "null resource path causes problem", + { + "null resource path causes problem", "GET", NULL, NULL, @@ -798,36 +765,32 @@ test_hrb_init_request(void) struct testcase *C = NULL; unsigned int i = 0; unsigned int ncases = 5; - hrb_t *req = NULL; + hrb_t * req = NULL; TESTING("hrb_init_request"); for (i = 0; i < ncases; i++) { - C = &cases[i]; - req = H5FD_s3comms_hrb_init_request( - C->verb, - C->resource, - C->version); + C = &cases[i]; + req = H5FD_s3comms_hrb_init_request(C->verb, C->resource, C->version); if (cases[i].ret_null == TRUE) { - FAIL_IF( req != NULL ); + FAIL_IF(req != NULL); } else { - FAIL_IF( req == NULL ); - JSVERIFY( S3COMMS_HRB_MAGIC, req->magic, NULL ) + FAIL_IF(req == NULL); + JSVERIFY(S3COMMS_HRB_MAGIC, req->magic, NULL) if (C->verb == NULL) { - JSVERIFY_STR( "GET", req->verb, NULL ) + JSVERIFY_STR("GET", req->verb, NULL) } else { - JSVERIFY_STR( req->verb, C->verb, NULL ) + JSVERIFY_STR(req->verb, C->verb, NULL) } - JSVERIFY_STR( "HTTP/1.1", req->version, NULL ) - JSVERIFY_STR( C->exp_res, req->resource, NULL ) - FAIL_IF( req->first_header != NULL ); - FAIL_IF( req->body != NULL ); - JSVERIFY( 0, req->body_len, NULL ) - JSVERIFY( SUCCEED, H5FD_s3comms_hrb_destroy(&req), - "unable to destroy hrb_t" ) - FAIL_IF( NULL != req ); /* should annull pointer as well as free */ + JSVERIFY_STR("HTTP/1.1", req->version, NULL) + JSVERIFY_STR(C->exp_res, req->resource, NULL) + FAIL_IF(req->first_header != NULL); + FAIL_IF(req->body != NULL); + JSVERIFY(0, req->body_len, NULL) + JSVERIFY(SUCCEED, H5FD_s3comms_hrb_destroy(&req), "unable to destroy hrb_t") + FAIL_IF(NULL != req); /* should annull pointer as well as free */ } } /* end for each testcase */ @@ -842,7 +805,6 @@ error: } /* end test_hrb_init_request() */ - /*--------------------------------------------------------------------------- * * Function: test_hrb_node_set() @@ -890,11 +852,11 @@ test_hrb_node_set(void) * representing the empty list. */ typedef struct testcase { - const char *message; - node_mock_t delta; - herr_t returned; - const char *given[11]; /* name/value pairs in array; NULL sentinel */ - const char *expected[11]; + const char *message; + node_mock_t delta; + herr_t returned; + const char *given[11]; /* name/value pairs in array; NULL sentinel */ + const char *expected[11]; } testcase; /************************ @@ -902,188 +864,279 @@ test_hrb_node_set(void) ************************/ testcase cases[] = { - { "cannot remove node from null list", - { "Host", NULL }, + { + "cannot remove node from null list", + {"Host", NULL}, FAIL, {NULL}, {NULL}, }, - { "cannot create list with NULL field name", - { NULL, "somevalue" }, + { + "cannot create list with NULL field name", + {NULL, "somevalue"}, FAIL, {NULL}, {NULL}, }, - { "create a new list", - { "Host", "somevalue" }, + { + "create a new list", + {"Host", "somevalue"}, SUCCEED, {NULL}, - { "Host", "somevalue", + { + "Host", + "somevalue", NULL, }, }, - { "insert new node at head list", - { "Host", "somevalue" }, + { + "insert new node at head list", + {"Host", "somevalue"}, SUCCEED, - { "Range", "bytes=20-40", + { + "Range", + "bytes=20-40", NULL, }, - { "Host", "somevalue", - "Range", "bytes=20-40", + { + "Host", + "somevalue", + "Range", + "bytes=20-40", NULL, }, }, - { "append new node at list end", - { "x-amz-date", "somevalue" }, + { + "append new node at list end", + {"x-amz-date", "somevalue"}, SUCCEED, - { "Range", "bytes=20-40", + { + "Range", + "bytes=20-40", NULL, }, - { "Range", "bytes=20-40", - "x-amz-date", "somevalue", + { + "Range", + "bytes=20-40", + "x-amz-date", + "somevalue", NULL, }, }, - { "insert new node inside list", - { "Intermediary", "somevalue" }, + { + "insert new node inside list", + {"Intermediary", "somevalue"}, SUCCEED, - { "Host", "somehost" , - "Range", "bytes=20-40", + { + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, - { "Host", "somehost", - "Intermediary", "somevalue", - "Range", "bytes=20-40", + { + "Host", + "somehost", + "Intermediary", + "somevalue", + "Range", + "bytes=20-40", NULL, }, }, - { "modify node", - { "Range", "bytes=40-80" }, + { + "modify node", + {"Range", "bytes=40-80"}, SUCCEED, - { "Host", "somehost", - "Range", "bytes=20-40", + { + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, - { "Host", "somehost", - "Range", "bytes=40-80", + { + "Host", + "somehost", + "Range", + "bytes=40-80", NULL, }, }, - { "modify node with new case", - { "RANGE", "bytes=40-80" }, + { + "modify node with new case", + {"RANGE", "bytes=40-80"}, SUCCEED, - { "Host", "somehost", - "Range", "bytes=20-40", + { + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, - { "Host", "somehost", - "RANGE", "bytes=40-80", + { + "Host", + "somehost", + "RANGE", + "bytes=40-80", NULL, }, }, - { "cannot add node with no name", - { NULL, "bytes=40-80" }, + { + "cannot add node with no name", + {NULL, "bytes=40-80"}, FAIL, - { "Host", "somehost", + { + "Host", + "somehost", NULL, }, - { "Host", "somehost", + { + "Host", + "somehost", NULL, }, }, - { "add node with 'empty' name", - { "", "bytes=40-80" }, + { + "add node with 'empty' name", + {"", "bytes=40-80"}, SUCCEED, - { "Host", "somehost", + { + "Host", + "somehost", NULL, }, - { "", "bytes=40-80", - "Host", "somehost", + { + "", + "bytes=40-80", + "Host", + "somehost", NULL, }, }, - { "remove node from end of list", - { "Host", NULL }, + { + "remove node from end of list", + {"Host", NULL}, SUCCEED, - { "Date", "Thr, 25 Jan 2018", - "Host", "somehost", + { + "Date", + "Thr, 25 Jan 2018", + "Host", + "somehost", NULL, }, - { "Date", "Thr, 25 Jan 2018", + { + "Date", + "Thr, 25 Jan 2018", NULL, }, }, - { "remove node from middle of list", - { "Host", NULL }, + { + "remove node from middle of list", + {"Host", NULL}, SUCCEED, - { "Date", "Thr, 25 Jan 2018", - "Host", "somehost", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, - { "Date", "Thr, 25 Jan 2018", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Range", + "bytes=20-40", NULL, }, }, - { "remove node from start of list", - { "Date", NULL }, + { + "remove node from start of list", + {"Date", NULL}, SUCCEED, - { "Date", "Thr, 25 Jan 2018", - "Host", "somehost", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, - { "Host", "somehost", - "Range", "bytes=20-40", + { + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, }, - { "remove only node in list", - { "Date", NULL }, + { + "remove only node in list", + {"Date", NULL}, SUCCEED, - { "Date", "Thr, 25 Jan 2018", + { + "Date", + "Thr, 25 Jan 2018", NULL, }, - { NULL, + { + NULL, }, }, - { "attempt to remove absent node fails", - { "Host", NULL }, + { + "attempt to remove absent node fails", + {"Host", NULL}, FAIL, - { "Date", "Thr, 25 Jan 2018", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Range", + "bytes=20-40", NULL, }, - { "Date", "Thr, 25 Jan 2018", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Range", + "bytes=20-40", NULL, }, }, - { "removal is case-insensitive", - { "hOsT", NULL }, + { + "removal is case-insensitive", + {"hOsT", NULL}, SUCCEED, - { "Date", "Thr, 25 Jan 2018", - "Host", "somehost", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Host", + "somehost", + "Range", + "bytes=20-40", NULL, }, - { "Date", "Thr, 25 Jan 2018", - "Range", "bytes=20-40", + { + "Date", + "Thr, 25 Jan 2018", + "Range", + "bytes=20-40", NULL, }, }, }; - unsigned testcases_count = 16; - unsigned test_i = 0; - hrb_node_t *list = NULL; + unsigned testcases_count = 16; + unsigned test_i = 0; + hrb_node_t *list = NULL; TESTING("hrb_node_t (test_hrb_node_set)"); for (test_i = 0; test_i < testcases_count; test_i++) { - const hrb_node_t *node = NULL; - const testcase *test = &(cases[test_i]); - unsigned mock_i = 0; + const hrb_node_t *node = NULL; + const testcase * test = &(cases[test_i]); + unsigned mock_i = 0; /********* * SETUP * @@ -1091,10 +1144,9 @@ test_hrb_node_set(void) for (mock_i = 0; test->given[mock_i] != NULL; mock_i += 2) { const char *name = test->given[mock_i]; - const char *valu = test->given[mock_i+1]; + const char *valu = test->given[mock_i + 1]; - FAIL_IF( SUCCEED != - H5FD_s3comms_hrb_node_set(&list, name, valu) ) + FAIL_IF(SUCCEED != H5FD_s3comms_hrb_node_set(&list, name, valu)) } /******** * TEST * @@ -1102,37 +1154,32 @@ test_hrb_node_set(void) /* perform modification on list */ - JSVERIFY( test->returned, - H5FD_s3comms_hrb_node_set(&list, - test->delta.name, - test->delta.value), - test->message ) - + JSVERIFY(test->returned, H5FD_s3comms_hrb_node_set(&list, test->delta.name, test->delta.value), + test->message) /* verify resulting list */ - node = list; + node = list; mock_i = 0; while (test->expected[mock_i] != NULL && node != NULL) { const char *name = test->expected[mock_i]; - const char *valu = test->expected[mock_i+1]; + const char *valu = test->expected[mock_i + 1]; - JSVERIFY_STR( name, node->name, NULL ) - JSVERIFY_STR( valu, node->value, NULL ) + JSVERIFY_STR(name, node->name, NULL) + JSVERIFY_STR(valu, node->value, NULL) mock_i += 2; node = node->next; } - FAIL_IF( test->expected[mock_i] != NULL ) - FAIL_IF( node != NULL ) + FAIL_IF(test->expected[mock_i] != NULL) + FAIL_IF(node != NULL) /************ * TEARDOWN * ************/ while (list != NULL) { - FAIL_IF( SUCCEED != - H5FD_s3comms_hrb_node_set(&list, list->name, NULL) ) + FAIL_IF(SUCCEED != H5FD_s3comms_hrb_node_set(&list, list->name, NULL)) } } /* end for each testcase */ @@ -1148,8 +1195,6 @@ error: } /* end test_hrb_node_t() */ - - /*--------------------------------------------------------------------------- * * Function: test_HMAC_SHA256() @@ -1172,13 +1217,13 @@ test_HMAC_SHA256(void) *************************/ struct testcase { - herr_t ret; /* SUCCEED/FAIL expected from call */ - const unsigned char key[SHA256_DIGEST_LENGTH]; - size_t key_len; - const char *msg; - size_t msg_len; - const char *exp; /* not used if ret == FAIL */ - size_t dest_size; /* if 0, `dest` is not malloc'd */ + herr_t ret; /* SUCCEED/FAIL expected from call */ + const unsigned char key[SHA256_DIGEST_LENGTH]; + size_t key_len; + const char * msg; + size_t msg_len; + const char * exp; /* not used if ret == FAIL */ + size_t dest_size; /* if 0, `dest` is not malloc'd */ }; /************************ @@ -1186,33 +1231,33 @@ test_HMAC_SHA256(void) ************************/ struct testcase cases[] = { - { SUCCEED, - { 0xdb, 0xb8, 0x93, 0xac, 0xc0, 0x10, 0x96, 0x49, - 0x18, 0xf1, 0xfd, 0x43, 0x3a, 0xdd, 0x87, 0xc7, - 0x0e, 0x8b, 0x0d, 0xb6, 0xbe, 0x30, 0xc1, 0xfb, - 0xea, 0xfe, 0xfa, 0x5e, 0xc6, 0xba, 0x83, 0x78, + { + SUCCEED, + { + 0xdb, 0xb8, 0x93, 0xac, 0xc0, 0x10, 0x96, 0x49, 0x18, 0xf1, 0xfd, + 0x43, 0x3a, 0xdd, 0x87, 0xc7, 0x0e, 0x8b, 0x0d, 0xb6, 0xbe, 0x30, + 0xc1, 0xfb, 0xea, 0xfe, 0xfa, 0x5e, 0xc6, 0xba, 0x83, 0x78, }, SHA256_DIGEST_LENGTH, - "AWS4-HMAC-SHA256\n20130524T000000Z\n20130524/us-east-1/s3/aws4_request\n7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972", - HDstrlen("AWS4-HMAC-SHA256\n20130524T000000Z\n20130524/us-east-1/s3/aws4_request\n7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972"), + "AWS4-HMAC-SHA256\n20130524T000000Z\n20130524/us-east-1/s3/" + "aws4_request\n7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972", + HDstrlen("AWS4-HMAC-SHA256\n20130524T000000Z\n20130524/us-east-1/s3/" + "aws4_request\n7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972"), "f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41", SHA256_DIGEST_LENGTH * 2 + 1, /* +1 for null terminator */ }, - { SUCCEED, - {'J','e','f','e'}, + { + SUCCEED, + {'J', 'e', 'f', 'e'}, 4, "what do ya want for nothing?", 28, "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843", SHA256_DIGEST_LENGTH * 2 + 1, }, - { FAIL, - "DOESN'T MATTER", - 14, - "ALSO IRRELEVANT", - 15, - NULL, - 0, /* dest -> null, resulting in immediate error */ + { + FAIL, "DOESN'T MATTER", 14, "ALSO IRRELEVANT", 15, NULL, + 0, /* dest -> null, resulting in immediate error */ }, }; char *dest = NULL; @@ -1223,44 +1268,32 @@ test_HMAC_SHA256(void) for (i = 0; i < n_cases; i++) { if (cases[i].dest_size == 0) { - dest = NULL; - } else { - dest = (char *)HDmalloc(sizeof(char) * cases[i].dest_size); - HDassert(dest != NULL); + dest = NULL; + } + else { + dest = (char *)HDmalloc(sizeof(char) * cases[i].dest_size); + HDassert(dest != NULL); } - JSVERIFY( cases[i].ret, - H5FD_s3comms_HMAC_SHA256( - cases[i].key, - cases[i].key_len, - cases[i].msg, - cases[i].msg_len, - dest), - cases[i].msg ); + JSVERIFY( + cases[i].ret, + H5FD_s3comms_HMAC_SHA256(cases[i].key, cases[i].key_len, cases[i].msg, cases[i].msg_len, dest), + cases[i].msg); if (cases[i].ret == SUCCEED) { #ifdef VERBOSE - if (0 != - strncmp(cases[i].exp, - dest, - HDstrlen(cases[i].exp))) - { + if (0 != strncmp(cases[i].exp, dest, HDstrlen(cases[i].exp))) { /* print out how wrong things are, and then fail */ dest = (char *)realloc(dest, cases[i].dest_size + 1); HDassert(dest != NULL); dest[cases[i].dest_size] = 0; - HDfprintf(stdout, - "ERROR:\n!!! \"%s\"\n != \"%s\"\n", - cases[i].exp, - dest); + HDfprintf(stdout, "ERROR:\n!!! \"%s\"\n != \"%s\"\n", cases[i].exp, dest); TEST_ERROR; } -#else /* VERBOSE not defined */ +#else /* VERBOSE not defined */ /* simple pass/fail test */ - JSVERIFY( 0, - strncmp(cases[i].exp, dest, HDstrlen(cases[i].exp)), - NULL); + JSVERIFY(0, strncmp(cases[i].exp, dest, HDstrlen(cases[i].exp)), NULL); #endif /* VERBOSE */ } free(dest); @@ -1275,7 +1308,6 @@ error: } /* end test_HMAC_SHA256() */ - /*---------------------------------------------------------------------------- * * Function: test_nlowercase() @@ -1310,15 +1342,18 @@ test_nlowercase(void) * in this test, kept as the null character for simplicity. */ struct testcase cases[] = { - { "HALlEluJAh", + { + "HALlEluJAh", 6, "hallel", }, - { "all\0 lower", + { + "all\0 lower", 10, "all\0 lower", }, - { "to meeeeeee", + { + "to meeeeeee", 0, "", }, @@ -1332,22 +1367,14 @@ test_nlowercase(void) for (i = 0; i < n_cases; i++) { dest = (char *)HDmalloc(sizeof(char) * 16); - JSVERIFY( SUCCEED, - H5FD_s3comms_nlowercase(dest, - cases[i].in, - cases[i].len), - cases[i].in ) + JSVERIFY(SUCCEED, H5FD_s3comms_nlowercase(dest, cases[i].in, cases[i].len), cases[i].in) if (cases[i].len > 0) { - JSVERIFY( 0, strncmp(dest, cases[i].exp, cases[i].len), NULL ) + JSVERIFY(0, strncmp(dest, cases[i].exp, cases[i].len), NULL) } free(dest); } /* end for each testcase */ - JSVERIFY( FAIL, - H5FD_s3comms_nlowercase(NULL, - cases[0].in, - cases[0].len), - "null distination should fail" ) + JSVERIFY(FAIL, H5FD_s3comms_nlowercase(NULL, cases[0].in, cases[0].len), "null distination should fail") PASSED(); return 0; @@ -1358,7 +1385,6 @@ error: } /* end test_nlowercase() */ - /*--------------------------------------------------------------------------- * * Function: test_parse_url() @@ -1388,34 +1414,38 @@ test_parse_url(void) } const_purl_t; struct testcase { - const char *url; - herr_t exp_ret; /* expected return; */ - /* if FAIL, `expected` is unused */ - const_purl_t expected; - const char *msg; + const char *url; + herr_t exp_ret; /* expected return; */ + /* if FAIL, `expected` is unused */ + const_purl_t expected; + const char * msg; }; /************************ * test-local variables * ************************/ - parsed_url_t *purl = NULL; + parsed_url_t * purl = NULL; unsigned int i = 0; unsigned int ncases = 15; struct testcase cases[] = { - { NULL, + { + NULL, FAIL, - { NULL, NULL, NULL, NULL, NULL }, + {NULL, NULL, NULL, NULL, NULL}, "null url", }, - { "", + { + "", FAIL, - { NULL, NULL, NULL, NULL, NULL }, + {NULL, NULL, NULL, NULL, NULL}, "empty url", }, - { "ftp://[1000:4000:0002:2010]", + { + "ftp://[1000:4000:0002:2010]", SUCCEED, - { "ftp", + { + "ftp", "[1000:4000:0002:2010]", NULL, NULL, @@ -1423,9 +1453,11 @@ test_parse_url(void) }, "IPv6 ftp and empty path (root)", }, - { "ftp://[1000:4000:0002:2010]:2040", + { + "ftp://[1000:4000:0002:2010]:2040", SUCCEED, - { "ftp", + { + "ftp", "[1000:4000:0002:2010]", "2040", NULL, @@ -1433,9 +1465,11 @@ test_parse_url(void) }, "root IPv6 ftp with port", }, - { "http://some.domain.org:9000/path/to/resource.txt", + { + "http://some.domain.org:9000/path/to/resource.txt", SUCCEED, - { "http", + { + "http", "some.domain.org", "9000", "path/to/resource.txt", @@ -1443,9 +1477,11 @@ test_parse_url(void) }, "without query", }, - { "https://domain.me:00/file.txt?some_params unchecked", + { + "https://domain.me:00/file.txt?some_params unchecked", SUCCEED, - { "https", + { + "https", "domain.me", "00", "file.txt", @@ -1453,9 +1489,11 @@ test_parse_url(void) }, "with query", }, - { "ftp://domain.com/", + { + "ftp://domain.com/", SUCCEED, - { "ftp", + { + "ftp", "domain.com", NULL, NULL, @@ -1463,9 +1501,11 @@ test_parse_url(void) }, "explicit root w/out port", }, - { "ftp://domain.com:1234/", + { + "ftp://domain.com:1234/", SUCCEED, - { "ftp", + { + "ftp", "domain.com", "1234", NULL, @@ -1473,24 +1513,47 @@ test_parse_url(void) }, "explicit root with port", }, - { "ftp://domain.com:1234/file?", + { + "ftp://domain.com:1234/file?", FAIL, - { NULL, NULL, NULL, NULL, NULL, }, + { + NULL, + NULL, + NULL, + NULL, + NULL, + }, "empty query is invalid", }, - { "ftp://:1234/file", + { + "ftp://:1234/file", FAIL, - { NULL, NULL, NULL, NULL, NULL, }, + { + NULL, + NULL, + NULL, + NULL, + NULL, + }, "no host", }, - { "h&r block", + { + "h&r block", FAIL, - { NULL, NULL, NULL, NULL, NULL, }, + { + NULL, + NULL, + NULL, + NULL, + NULL, + }, "no scheme (bad URL)", }, - { "http://domain.com?a=b&d=b", + { + "http://domain.com?a=b&d=b", SUCCEED, - { "http", + { + "http", "domain.com", NULL, NULL, @@ -1498,9 +1561,11 @@ test_parse_url(void) }, "QUERY with implict PATH", }, - { "http://[5]/path?a=b&d=b", + { + "http://[5]/path?a=b&d=b", SUCCEED, - { "http", + { + "http", "[5]", NULL, "path", @@ -1508,14 +1573,28 @@ test_parse_url(void) }, "IPv6 extraction is really dumb", }, - { "http://[1234:5678:0910:1112]:port/path", + { + "http://[1234:5678:0910:1112]:port/path", FAIL, - { NULL, NULL, NULL, NULL, NULL, }, + { + NULL, + NULL, + NULL, + NULL, + NULL, + }, "non-decimal PORT (port)", }, - { "http://mydomain.com:01a3/path", + { + "http://mydomain.com:01a3/path", FAIL, - { NULL, NULL, NULL, NULL, NULL, }, + { + NULL, + NULL, + NULL, + NULL, + NULL, + }, "non-decimal PORT (01a3)", }, }; @@ -1527,70 +1606,63 @@ test_parse_url(void) *********/ for (i = 0; i < ncases; i++) { - HDassert( purl == NULL ); + HDassert(purl == NULL); - JSVERIFY( cases[i].exp_ret, - H5FD_s3comms_parse_url(cases[i].url, &purl), - cases[i].msg ) + JSVERIFY(cases[i].exp_ret, H5FD_s3comms_parse_url(cases[i].url, &purl), cases[i].msg) if (cases[i].exp_ret == FAIL) { /* on FAIL, `purl` should be untouched--remains NULL */ - FAIL_UNLESS( purl == NULL ) + FAIL_UNLESS(purl == NULL) } else { /* on SUCCEED, `purl` should be set */ - FAIL_IF( purl == NULL ) + FAIL_IF(purl == NULL) if (cases[i].expected.scheme != NULL) { - FAIL_IF( NULL == purl->scheme ) - JSVERIFY_STR( cases[i].expected.scheme, - purl->scheme, - cases[i].msg ) - } else { - FAIL_UNLESS( NULL == purl->scheme ) + FAIL_IF(NULL == purl->scheme) + JSVERIFY_STR(cases[i].expected.scheme, purl->scheme, cases[i].msg) + } + else { + FAIL_UNLESS(NULL == purl->scheme) } if (cases[i].expected.host != NULL) { - FAIL_IF( NULL == purl->host ) - JSVERIFY_STR( cases[i].expected.host, - purl->host, - cases[i].msg ) - } else { - FAIL_UNLESS( NULL == purl->host ) + FAIL_IF(NULL == purl->host) + JSVERIFY_STR(cases[i].expected.host, purl->host, cases[i].msg) + } + else { + FAIL_UNLESS(NULL == purl->host) } if (cases[i].expected.port != NULL) { - FAIL_IF( NULL == purl->port ) - JSVERIFY_STR( cases[i].expected.port, - purl->port, - cases[i].msg ) - } else { - FAIL_UNLESS( NULL == purl->port ) + FAIL_IF(NULL == purl->port) + JSVERIFY_STR(cases[i].expected.port, purl->port, cases[i].msg) + } + else { + FAIL_UNLESS(NULL == purl->port) } if (cases[i].expected.path != NULL) { - FAIL_IF( NULL == purl->path ) - JSVERIFY_STR( cases[i].expected.path, - purl->path, - cases[i].msg ) - } else { - FAIL_UNLESS( NULL == purl->path ) + FAIL_IF(NULL == purl->path) + JSVERIFY_STR(cases[i].expected.path, purl->path, cases[i].msg) + } + else { + FAIL_UNLESS(NULL == purl->path) } if (cases[i].expected.query != NULL) { - FAIL_IF( NULL == purl->query ) - JSVERIFY_STR( cases[i].expected.query, - purl->query, - cases[i].msg ) - } else { - FAIL_UNLESS( NULL == purl->query ) + FAIL_IF(NULL == purl->query) + JSVERIFY_STR(cases[i].expected.query, purl->query, cases[i].msg) + } + else { + FAIL_UNLESS(NULL == purl->query) } } /* end if parse-url return SUCCEED/FAIL */ /* per-test cleanup * well-behaved, even if `purl` is NULL */ - FAIL_IF( FAIL == H5FD_s3comms_free_purl(purl) ) + FAIL_IF(FAIL == H5FD_s3comms_free_purl(purl)) purl = NULL; } /* end for each testcase */ @@ -1608,7 +1680,6 @@ error: } /* end test_parse_url() */ - /*--------------------------------------------------------------------------- * * Function: test_percent_encode_char() @@ -1645,10 +1716,10 @@ test_percent_encode_char(void) ************************/ struct testcase cases[] = { - {'$', "%24", 3}, /* u+0024 dollar sign */ - {' ', "%20", 3}, /* u+0020 space */ - {'^', "%5E", 3}, /* u+0094 carat */ - {'/', "%2F", 3}, /* u+002f solidus (forward slash) */ + {'$', "%24", 3}, /* u+0024 dollar sign */ + {' ', "%20", 3}, /* u+0020 space */ + {'^', "%5E", 3}, /* u+0094 carat */ + {'/', "%2F", 3}, /* u+002f solidus (forward slash) */ /* {??, "%C5%8C", 6},*/ /* u+014c Latin Capital Letter O with Macron */ /* Not included because it is multibyte "wide" character that poses */ /* issues both in the underlying function and in being written in */ @@ -1667,23 +1738,14 @@ test_percent_encode_char(void) TESTING("percent encode characters"); for (i = 0; i < n_cases; i++) { - JSVERIFY( SUCCEED, - H5FD_s3comms_percent_encode_char( - dest, - (const unsigned char)cases[i].c, - &dest_len), - NULL ) - JSVERIFY(cases[i].exp_len, dest_len, NULL ) - JSVERIFY(0, strncmp(dest, cases[i].exp, dest_len), NULL ) - JSVERIFY_STR( cases[i].exp, dest, NULL ) + JSVERIFY(SUCCEED, H5FD_s3comms_percent_encode_char(dest, (const unsigned char)cases[i].c, &dest_len), + NULL) + JSVERIFY(cases[i].exp_len, dest_len, NULL) + JSVERIFY(0, strncmp(dest, cases[i].exp, dest_len), NULL) + JSVERIFY_STR(cases[i].exp, dest, NULL) } - JSVERIFY( FAIL, - H5FD_s3comms_percent_encode_char( - NULL, - (const unsigned char)'^', - &dest_len), - NULL ) + JSVERIFY(FAIL, H5FD_s3comms_percent_encode_char(NULL, (const unsigned char)'^', &dest_len), NULL) PASSED(); return 0; @@ -1692,7 +1754,6 @@ error: return -1; } /* end test_percent_encode_char() */ - /*--------------------------------------------------------------------------- * Function: test_s3r_open() * @@ -1710,7 +1771,7 @@ test_s3r_get_filesize(void) * test-local variables * ************************/ - char url_raven[S3_TEST_MAX_URL_SIZE]; + char url_raven[S3_TEST_MAX_URL_SIZE]; s3r_t *handle = NULL; TESTING("s3r_get_filesize"); @@ -1724,23 +1785,17 @@ test_s3r_get_filesize(void) return 0; } - FAIL_IF( S3_TEST_MAX_URL_SIZE < - HDsnprintf(url_raven, - S3_TEST_MAX_URL_SIZE, - "%s/%s", - s3_test_bucket_url, - S3_TEST_RESOURCE_TEXT_PUBLIC) ); + FAIL_IF(S3_TEST_MAX_URL_SIZE < HDsnprintf(url_raven, S3_TEST_MAX_URL_SIZE, "%s/%s", s3_test_bucket_url, + S3_TEST_RESOURCE_TEXT_PUBLIC)); - JSVERIFY( 0, H5FD_s3comms_s3r_get_filesize(NULL), - "filesize of the null handle should be 0" ) + JSVERIFY(0, H5FD_s3comms_s3r_get_filesize(NULL), "filesize of the null handle should be 0") handle = H5FD_s3comms_s3r_open(url_raven, NULL, NULL, NULL); - FAIL_IF( handle == NULL ) + FAIL_IF(handle == NULL) - JSVERIFY( 6464, H5FD_s3comms_s3r_get_filesize(handle), NULL ) + JSVERIFY(6464, H5FD_s3comms_s3r_get_filesize(handle), NULL) - - FAIL_IF( SUCCEED != H5FD_s3comms_s3r_close(handle) ) + FAIL_IF(SUCCEED != H5FD_s3comms_s3r_close(handle)) PASSED(); return 0; @@ -1753,7 +1808,6 @@ error: } /* end test_s3r_get_filesize() */ - /*--------------------------------------------------------------------------- * Function: test_s3r_open() * @@ -1771,16 +1825,16 @@ test_s3r_open(void) * test-local variables * ************************/ - char url_missing[S3_TEST_MAX_URL_SIZE]; - char url_raven[S3_TEST_MAX_URL_SIZE]; - char url_raven_badport[S3_TEST_MAX_URL_SIZE]; - char url_shakespeare[S3_TEST_MAX_URL_SIZE]; - unsigned char signing_key[SHA256_DIGEST_LENGTH]; - struct tm *now = NULL; - char iso8601now[ISO8601_SIZE]; - s3r_t *handle = NULL; - hbool_t curl_ready = FALSE; - parsed_url_t *purl = NULL; + char url_missing[S3_TEST_MAX_URL_SIZE]; + char url_raven[S3_TEST_MAX_URL_SIZE]; + char url_raven_badport[S3_TEST_MAX_URL_SIZE]; + char url_shakespeare[S3_TEST_MAX_URL_SIZE]; + unsigned char signing_key[SHA256_DIGEST_LENGTH]; + struct tm * now = NULL; + char iso8601now[ISO8601_SIZE]; + s3r_t * handle = NULL; + hbool_t curl_ready = FALSE; + parsed_url_t *purl = NULL; TESTING("s3r_open"); @@ -1801,65 +1855,46 @@ test_s3r_open(void) * PRE-TEST SETUP * ******************/ - FAIL_IF( S3_TEST_MAX_URL_SIZE < - HDsnprintf(url_shakespeare, - S3_TEST_MAX_URL_SIZE, - "%s/%s", - s3_test_bucket_url, - S3_TEST_RESOURCE_TEXT_RESTRICTED) ); - - FAIL_IF( S3_TEST_MAX_URL_SIZE < - HDsnprintf(url_missing, - S3_TEST_MAX_URL_SIZE, - "%s/%s", - s3_test_bucket_url, - S3_TEST_RESOURCE_MISSING) ); - - FAIL_IF( S3_TEST_MAX_URL_SIZE < - HDsnprintf(url_raven, - S3_TEST_MAX_URL_SIZE, - "%s/%s", - s3_test_bucket_url, - S3_TEST_RESOURCE_TEXT_PUBLIC) ); + FAIL_IF(S3_TEST_MAX_URL_SIZE < HDsnprintf(url_shakespeare, S3_TEST_MAX_URL_SIZE, "%s/%s", + s3_test_bucket_url, S3_TEST_RESOURCE_TEXT_RESTRICTED)); + + FAIL_IF(S3_TEST_MAX_URL_SIZE < HDsnprintf(url_missing, S3_TEST_MAX_URL_SIZE, "%s/%s", s3_test_bucket_url, + S3_TEST_RESOURCE_MISSING)); + + FAIL_IF(S3_TEST_MAX_URL_SIZE < HDsnprintf(url_raven, S3_TEST_MAX_URL_SIZE, "%s/%s", s3_test_bucket_url, + S3_TEST_RESOURCE_TEXT_PUBLIC)); /* Set given bucket url with invalid/inactive port number for badport. * Note, this sort of micro-management of parsed_url_t is not advised */ - FAIL_IF( FAIL == H5FD_s3comms_parse_url(s3_test_bucket_url, &purl) ) + FAIL_IF(FAIL == H5FD_s3comms_parse_url(s3_test_bucket_url, &purl)) if (purl->port == NULL) { purl->port = (char *)H5MM_malloc(sizeof(char) * 5); - FAIL_IF( purl->port == NULL ); - FAIL_IF( 5 < HDsnprintf(purl->port, 5, "9000") ) - } else if (strcmp(purl->port, "9000") != 0) { - FAIL_IF( 5 < HDsnprintf(purl->port, 5, "9000") ) - } else { - FAIL_IF( 5 < HDsnprintf(purl->port, 5, "1234") ) + FAIL_IF(purl->port == NULL); + FAIL_IF(5 < HDsnprintf(purl->port, 5, "9000")) + } + else if (strcmp(purl->port, "9000") != 0) { + FAIL_IF(5 < HDsnprintf(purl->port, 5, "9000")) + } + else { + FAIL_IF(5 < HDsnprintf(purl->port, 5, "1234")) } - FAIL_IF( S3_TEST_MAX_URL_SIZE < - HDsnprintf(url_raven_badport, - S3_TEST_MAX_URL_SIZE, - "%s://%s:%s/%s", - purl->scheme, - purl->host, - purl->port, - S3_TEST_RESOURCE_TEXT_PUBLIC) ); + FAIL_IF(S3_TEST_MAX_URL_SIZE < HDsnprintf(url_raven_badport, S3_TEST_MAX_URL_SIZE, "%s://%s:%s/%s", + purl->scheme, purl->host, purl->port, + S3_TEST_RESOURCE_TEXT_PUBLIC)); curl_global_init(CURL_GLOBAL_DEFAULT); curl_ready = TRUE; now = gmnow(); - FAIL_IF( now == NULL ) - FAIL_IF( ISO8601NOW(iso8601now, now) != (ISO8601_SIZE - 1) ); + FAIL_IF(now == NULL) + FAIL_IF(ISO8601NOW(iso8601now, now) != (ISO8601_SIZE - 1)); /* It is desired to have means available to verify that signing_key * was set successfully and to an expected value. */ - FAIL_IF( FAIL == - H5FD_s3comms_signing_key( - signing_key, - (const char *)s3_test_aws_secret_access_key, - (const char *)s3_test_aws_region, - (const char *)iso8601now) ); + FAIL_IF(FAIL == H5FD_s3comms_signing_key(signing_key, (const char *)s3_test_aws_secret_access_key, + (const char *)s3_test_aws_region, (const char *)iso8601now)); /************************* * OPEN NONEXISTENT FILE * @@ -1868,16 +1903,14 @@ test_s3r_open(void) /* attempt anonymously */ handle = H5FD_s3comms_s3r_open(url_missing, NULL, NULL, NULL); - FAIL_IF( handle != NULL ); + FAIL_IF(handle != NULL); /* attempt with authentication */ - handle = H5FD_s3comms_s3r_open( - url_missing, - (const char *)s3_test_aws_region, - (const char *)s3_test_aws_access_key_id, - (const unsigned char *)signing_key); - FAIL_IF( handle != NULL ); + handle = + H5FD_s3comms_s3r_open(url_missing, (const char *)s3_test_aws_region, + (const char *)s3_test_aws_access_key_id, (const unsigned char *)signing_key); + FAIL_IF(handle != NULL); /************************* * INACTIVE PORT ON HOST * @@ -1886,7 +1919,7 @@ test_s3r_open(void) #if S3_TEST_RUN_TIMEOUT HDprintf("Opening on inactive port may hang for a minute; waiting for timeout\n"); handle = H5FD_s3comms_s3r_open(url_raven_badport, NULL, NULL, NULL); - FAIL_IF( handle != NULL ); + FAIL_IF(handle != NULL); #endif /******************************* @@ -1896,25 +1929,20 @@ test_s3r_open(void) /* anonymous access on restricted file */ handle = H5FD_s3comms_s3r_open(url_shakespeare, NULL, NULL, NULL); - FAIL_IF( handle != NULL ); + FAIL_IF(handle != NULL); /* passed in a bad ID */ - handle = H5FD_s3comms_s3r_open( - url_shakespeare, - (const char *)s3_test_aws_region, - "I_MADE_UP_MY_ID", - (const unsigned char *)signing_key); - FAIL_IF( handle != NULL ); + handle = H5FD_s3comms_s3r_open(url_shakespeare, (const char *)s3_test_aws_region, "I_MADE_UP_MY_ID", + (const unsigned char *)signing_key); + FAIL_IF(handle != NULL); /* using an invalid signing key */ - handle = H5FD_s3comms_s3r_open( - url_shakespeare, - (const char *)s3_test_aws_region, - (const char *)s3_test_aws_access_key_id, - (const unsigned char *)EMPTY_SHA256); - FAIL_IF( handle != NULL ); + handle = + H5FD_s3comms_s3r_open(url_shakespeare, (const char *)s3_test_aws_region, + (const char *)s3_test_aws_access_key_id, (const unsigned char *)EMPTY_SHA256); + FAIL_IF(handle != NULL); /******************************* * SUCCESSFUL OPEN (AND CLOSE) * @@ -1923,48 +1951,35 @@ test_s3r_open(void) /* anonymous */ handle = H5FD_s3comms_s3r_open(url_raven, NULL, NULL, NULL); - FAIL_IF( handle == NULL ); - JSVERIFY( 6464, H5FD_s3comms_s3r_get_filesize(handle), - "did not get expected filesize" ) - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_close(handle), - "unable to close file" ) + FAIL_IF(handle == NULL); + JSVERIFY(6464, H5FD_s3comms_s3r_get_filesize(handle), "did not get expected filesize") + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_close(handle), "unable to close file") handle = NULL; /* using authentication on anonymously-accessible file? */ - handle = H5FD_s3comms_s3r_open( - url_raven, - (const char *)s3_test_aws_region, - (const char *)s3_test_aws_access_key_id, - (const unsigned char *)signing_key); - FAIL_IF( handle == NULL ); - JSVERIFY( 6464, H5FD_s3comms_s3r_get_filesize(handle), NULL ) - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_close(handle), - "unable to close file" ) + handle = + H5FD_s3comms_s3r_open(url_raven, (const char *)s3_test_aws_region, + (const char *)s3_test_aws_access_key_id, (const unsigned char *)signing_key); + FAIL_IF(handle == NULL); + JSVERIFY(6464, H5FD_s3comms_s3r_get_filesize(handle), NULL) + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_close(handle), "unable to close file") handle = NULL; /* authenticating */ - handle = H5FD_s3comms_s3r_open( - url_shakespeare, - (const char *)s3_test_aws_region, - (const char *)s3_test_aws_access_key_id, - (const unsigned char *)signing_key); - FAIL_IF( handle == NULL ); - JSVERIFY( 5458199, H5FD_s3comms_s3r_get_filesize(handle), NULL ) - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_close(handle), - "unable to close file" ) + handle = + H5FD_s3comms_s3r_open(url_shakespeare, (const char *)s3_test_aws_region, + (const char *)s3_test_aws_access_key_id, (const unsigned char *)signing_key); + FAIL_IF(handle == NULL); + JSVERIFY(5458199, H5FD_s3comms_s3r_get_filesize(handle), NULL) + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_close(handle), "unable to close file") handle = NULL; - - curl_global_cleanup(); curl_ready = FALSE; - FAIL_IF( FAIL == H5FD_s3comms_free_purl(purl) ) + FAIL_IF(FAIL == H5FD_s3comms_free_purl(purl)) purl = NULL; PASSED(); @@ -1985,7 +2000,6 @@ error: } /* end test_s3r_open() */ - /*--------------------------------------------------------------------------- * * Function: test_s3r_read() @@ -2017,11 +2031,11 @@ test_s3r_read(void) * test-local variables * ************************/ - char url_raven[S3_TEST_MAX_URL_SIZE]; - char buffer[S3COMMS_TEST_BUFFER_SIZE]; - s3r_t *handle = NULL; - hbool_t curl_ready = FALSE; - unsigned int i = 0; + char url_raven[S3_TEST_MAX_URL_SIZE]; + char buffer[S3COMMS_TEST_BUFFER_SIZE]; + s3r_t * handle = NULL; + hbool_t curl_ready = FALSE; + unsigned int i = 0; TESTING("test_s3r_read"); @@ -2037,12 +2051,8 @@ test_s3r_read(void) curl_global_init(CURL_GLOBAL_DEFAULT); curl_ready = TRUE; - FAIL_IF( S3_TEST_MAX_URL_SIZE < - HDsnprintf(url_raven, - S3_TEST_MAX_URL_SIZE, - "%s/%s", - s3_test_bucket_url, - S3_TEST_RESOURCE_TEXT_PUBLIC) ); + FAIL_IF(S3_TEST_MAX_URL_SIZE < HDsnprintf(url_raven, S3_TEST_MAX_URL_SIZE, "%s/%s", s3_test_bucket_url, + S3_TEST_RESOURCE_TEXT_PUBLIC)); for (i = 0; i < S3COMMS_TEST_BUFFER_SIZE; i++) buffer[i] = '\0'; @@ -2050,8 +2060,8 @@ test_s3r_read(void) /* open file */ handle = H5FD_s3comms_s3r_open(url_raven, NULL, NULL, NULL); - FAIL_IF( handle == NULL ) - JSVERIFY( 6464, H5FD_s3comms_s3r_get_filesize(handle), NULL ) + FAIL_IF(handle == NULL) + JSVERIFY(6464, H5FD_s3comms_s3r_get_filesize(handle), NULL) for (i = 0; i < S3COMMS_TEST_BUFFER_SIZE; i++) buffer[i] = '\0'; @@ -2060,18 +2070,10 @@ test_s3r_read(void) * read start of file * **********************/ - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)0, - (size_t)118, - buffer), - NULL ) - JSVERIFY_STR ( - "Once upon a midnight dreary, while I pondered, weak and weary,\n" \ - "Over many a quaint and curious volume of forgotten lore", - buffer, - NULL ) + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_read(handle, (haddr_t)0, (size_t)118, buffer), NULL) + JSVERIFY_STR("Once upon a midnight dreary, while I pondered, weak and weary,\n" + "Over many a quaint and curious volume of forgotten lore", + buffer, NULL) for (i = 0; i < S3COMMS_TEST_BUFFER_SIZE; i++) buffer[i] = '\0'; @@ -2080,16 +2082,8 @@ test_s3r_read(void) * read arbitrary range * ************************/ - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)2540, - (size_t)54, - buffer), - NULL ) - JSVERIFY_STR( "the grave and stern decorum of the countenance it wore", - buffer, - NULL ) + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_read(handle, (haddr_t)2540, (size_t)54, buffer), NULL) + JSVERIFY_STR("the grave and stern decorum of the countenance it wore", buffer, NULL) for (i = 0; i < S3COMMS_TEST_BUFFER_SIZE; i++) buffer[i] = '\0'; @@ -2098,15 +2092,8 @@ test_s3r_read(void) * read one character * **********************/ - JSVERIFY(SUCCEED, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)2540, - (size_t)1, - buffer), - NULL ) - JSVERIFY_STR( "t", buffer, NULL ) - + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_read(handle, (haddr_t)2540, (size_t)1, buffer), NULL) + JSVERIFY_STR("t", buffer, NULL) for (i = 0; i < S3COMMS_TEST_BUFFER_SIZE; i++) buffer[i] = '\0'; @@ -2115,18 +2102,14 @@ test_s3r_read(void) * read to EoF * ***************/ - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)6370, - (size_t)0, - buffer), - NULL ) - JSVERIFY( 0, - strncmp(buffer, - "And my soul from out that shadow that lies floating on the floor\nShall be lifted—nevermore!\n", - 94), - buffer ) + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_read(handle, (haddr_t)6370, (size_t)0, buffer), NULL) + JSVERIFY( + 0, + strncmp( + buffer, + "And my soul from out that shadow that lies floating on the floor\nShall be lifted—nevermore!\n", + 94), + buffer) for (i = 0; i < S3COMMS_TEST_BUFFER_SIZE; i++) buffer[i] = '\0'; @@ -2135,48 +2118,34 @@ test_s3r_read(void) * read past eof * *****************/ - JSVERIFY( FAIL, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)6400, - (size_t)100, /* 6400+100 > 6464 */ - buffer), - NULL ) - JSVERIFY( 0, strcmp("", buffer), NULL ) + JSVERIFY(FAIL, + H5FD_s3comms_s3r_read(handle, (haddr_t)6400, (size_t)100, /* 6400+100 > 6464 */ + buffer), + NULL) + JSVERIFY(0, strcmp("", buffer), NULL) /************************ * read starts past eof * ************************/ - JSVERIFY( FAIL, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)1200699, /* 1200699 > 6464 */ - (size_t)100, - buffer), - NULL ) - JSVERIFY( 0, strcmp("", buffer), NULL ) + JSVERIFY(FAIL, + H5FD_s3comms_s3r_read(handle, (haddr_t)1200699, /* 1200699 > 6464 */ + (size_t)100, buffer), + NULL) + JSVERIFY(0, strcmp("", buffer), NULL) /********************** * read starts on eof * **********************/ - JSVERIFY( FAIL, - H5FD_s3comms_s3r_read( - handle, - (haddr_t)6464, - (size_t)0, - buffer), - NULL ) - JSVERIFY( 0, strcmp("", buffer), NULL ) + JSVERIFY(FAIL, H5FD_s3comms_s3r_read(handle, (haddr_t)6464, (size_t)0, buffer), NULL) + JSVERIFY(0, strcmp("", buffer), NULL) /************* * TEAR DOWN * *************/ - JSVERIFY( SUCCEED, - H5FD_s3comms_s3r_close(handle), - "unable to close file" ) + JSVERIFY(SUCCEED, H5FD_s3comms_s3r_close(handle), "unable to close file") handle = NULL; curl_global_cleanup(); @@ -2202,7 +2171,6 @@ error: } /* end test_s3r_read() */ - /*--------------------------------------------------------------------------- * * Function: test_signing_key() @@ -2226,10 +2194,10 @@ test_signing_key(void) *************************/ struct testcase { - const char *region; - const char *secret_key; - const char *when; - unsigned char exp[SHA256_DIGEST_LENGTH]; + const char * region; + const char * secret_key; + const char * when; + unsigned char exp[SHA256_DIGEST_LENGTH]; }; /************************ @@ -2237,13 +2205,14 @@ test_signing_key(void) ************************/ struct testcase cases[] = { - { "us-east-1", + { + "us-east-1", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "20130524T000000Z", - { 0xdb, 0xb8, 0x93, 0xac, 0xc0, 0x10, 0x96, 0x49, - 0x18, 0xf1, 0xfd, 0x43, 0x3a, 0xdd, 0x87, 0xc7, - 0x0e, 0x8b, 0x0d, 0xb6, 0xbe, 0x30, 0xc1, 0xfb, - 0xea, 0xfe, 0xfa, 0x5e, 0xc6, 0xba, 0x83, 0x78, + { + 0xdb, 0xb8, 0x93, 0xac, 0xc0, 0x10, 0x96, 0x49, 0x18, 0xf1, 0xfd, + 0x43, 0x3a, 0xdd, 0x87, 0xc7, 0x0e, 0x8b, 0x0d, 0xb6, 0xbe, 0x30, + 0xc1, 0xfb, 0xea, 0xfe, 0xfa, 0x5e, 0xc6, 0xba, 0x83, 0x78, }, }, }; @@ -2254,68 +2223,37 @@ test_signing_key(void) TESTING("signing_key"); for (i = 0; i < ncases; i++) { - key = (unsigned char *)HDmalloc(sizeof(unsigned char) * \ - SHA256_DIGEST_LENGTH); - HDassert(key != NULL); + key = (unsigned char *)HDmalloc(sizeof(unsigned char) * SHA256_DIGEST_LENGTH); + HDassert(key != NULL); - JSVERIFY( SUCCEED, - H5FD_s3comms_signing_key( - key, - cases[i].secret_key, - cases[i].region, - cases[i].when), - NULL ) + JSVERIFY(SUCCEED, H5FD_s3comms_signing_key(key, cases[i].secret_key, cases[i].region, cases[i].when), + NULL) - JSVERIFY( 0, - strncmp((const char *)cases[i].exp, - (const char *)key, - SHA256_DIGEST_LENGTH), - (const char *)cases[i].exp ) + JSVERIFY(0, strncmp((const char *)cases[i].exp, (const char *)key, SHA256_DIGEST_LENGTH), + (const char *)cases[i].exp) free(key); key = NULL; } - /*************** * ERROR CASES * ***************/ - key = (unsigned char *)HDmalloc(sizeof(unsigned char) * \ - SHA256_DIGEST_LENGTH); + key = (unsigned char *)HDmalloc(sizeof(unsigned char) * SHA256_DIGEST_LENGTH); HDassert(key != NULL); - JSVERIFY( FAIL, - H5FD_s3comms_signing_key( - NULL, - cases[0].secret_key, - cases[0].region, - cases[0].when), - "destination cannot be NULL" ) - - JSVERIFY( FAIL, - H5FD_s3comms_signing_key( - key, - NULL, - cases[0].region, - cases[0].when), - "secret key cannot be NULL" ) - - JSVERIFY( FAIL, - H5FD_s3comms_signing_key( - key, - cases[0].secret_key, - NULL, - cases[0].when), - "aws region cannot be NULL" ) - - JSVERIFY( FAIL, - H5FD_s3comms_signing_key( - key, - cases[0].secret_key, - cases[0].region, - NULL), - "time string cannot be NULL" ) + JSVERIFY(FAIL, H5FD_s3comms_signing_key(NULL, cases[0].secret_key, cases[0].region, cases[0].when), + "destination cannot be NULL") + + JSVERIFY(FAIL, H5FD_s3comms_signing_key(key, NULL, cases[0].region, cases[0].when), + "secret key cannot be NULL") + + JSVERIFY(FAIL, H5FD_s3comms_signing_key(key, cases[0].secret_key, NULL, cases[0].when), + "aws region cannot be NULL") + + JSVERIFY(FAIL, H5FD_s3comms_signing_key(key, cases[0].secret_key, cases[0].region, NULL), + "time string cannot be NULL") free(key); key = NULL; @@ -2332,7 +2270,6 @@ error: } /* end test_signing_key() */ - /*--------------------------------------------------------------------------- * * Function: test_tostringtosign() @@ -2361,41 +2298,39 @@ test_tostringtosign(void) * test-local variables * ************************/ - const char canonreq[] = "GET\n/test.txt\n\nhost:examplebucket.s3.amazonaws.com\nrange:bytes=0-9\nx-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nx-amz-date:20130524T000000Z\n\nhost;range;x-amz-content-sha256;x-amz-date\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + const char canonreq[] = "GET\n/" + "test.txt\n\nhost:examplebucket.s3.amazonaws.com\nrange:bytes=0-9\nx-amz-content-" + "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nx-amz-" + "date:20130524T000000Z\n\nhost;range;x-amz-content-sha256;x-amz-" + "date\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; const char iso8601now[] = "20130524T000000Z"; const char region[] = "us-east-1"; - char s2s[512]; + char s2s[512]; TESTING("s3comms tostringtosign"); - JSVERIFY( SUCCEED, - H5FD_s3comms_tostringtosign(s2s, canonreq, iso8601now, region), - "unable to create string to sign" ) + JSVERIFY(SUCCEED, H5FD_s3comms_tostringtosign(s2s, canonreq, iso8601now, region), + "unable to create string to sign") - JSVERIFY_STR( "AWS4-HMAC-SHA256\n20130524T000000Z\n20130524/us-east-1/s3/aws4_request\n7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972", - s2s, NULL ) + JSVERIFY_STR("AWS4-HMAC-SHA256\n20130524T000000Z\n20130524/us-east-1/s3/" + "aws4_request\n7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972", + s2s, NULL) - JSVERIFY( FAIL, - H5FD_s3comms_tostringtosign(s2s, NULL, iso8601now, region), - "canonical request string cannot be NULL" ) + JSVERIFY(FAIL, H5FD_s3comms_tostringtosign(s2s, NULL, iso8601now, region), + "canonical request string cannot be NULL") - JSVERIFY( FAIL, - H5FD_s3comms_tostringtosign(s2s, canonreq, NULL, region), - "time string cannot be NULL" ) + JSVERIFY(FAIL, H5FD_s3comms_tostringtosign(s2s, canonreq, NULL, region), "time string cannot be NULL") - JSVERIFY( FAIL, - H5FD_s3comms_tostringtosign(s2s, canonreq, iso8601now, NULL), - "aws region cannot be NULL" ) + JSVERIFY(FAIL, H5FD_s3comms_tostringtosign(s2s, canonreq, iso8601now, NULL), "aws region cannot be NULL") PASSED(); return 0; -error : +error: return -1; } /* end test_tostringtosign() */ - /*---------------------------------------------------------------------------- * * Function: test_trim() @@ -2428,39 +2363,42 @@ test_trim(void) ************************/ struct testcase cases[] = { - { "block string", + { + "block string", 12, "block string", 12, }, - { " \n\r \t", + { + " \n\r \t", 6, "", 0, }, - { " \twhite b4", + { + " \twhite b4", 10, "white b4", 8, }, - { "white after\r\n ", + { + "white after\r\n ", 15, "white after", 11, }, - { " on\nends\t", + { + " on\nends\t", 9, "on\nends", 7, }, }; - char dest[32]; - size_t dest_len = 0; - int i = 0; - int n_cases = 5; - char *str = NULL; - - + char dest[32]; + size_t dest_len = 0; + int i = 0; + int n_cases = 5; + char * str = NULL; TESTING("s3comms trim"); @@ -2470,28 +2408,24 @@ test_trim(void) HDassert(str != NULL); HDstrncpy(str, cases[i].in, cases[i].in_len); - JSVERIFY( SUCCEED, - H5FD_s3comms_trim(dest, str, cases[i].in_len, &dest_len), - NULL ) - JSVERIFY( cases[i].exp_len, dest_len, cases[i].in ) + JSVERIFY(SUCCEED, H5FD_s3comms_trim(dest, str, cases[i].in_len, &dest_len), NULL) + JSVERIFY(cases[i].exp_len, dest_len, cases[i].in) if (dest_len > 0) { - JSVERIFY( 0, strncmp(cases[i].exp, dest, dest_len), - cases[i].exp ) + JSVERIFY(0, strncmp(cases[i].exp, dest, dest_len), cases[i].exp) } free(str); str = NULL; } /* end for each testcase */ - JSVERIFY( SUCCEED, H5FD_s3comms_trim(dest, NULL, 3, &dest_len), - "should not fail when trimming a null string" ); - JSVERIFY( 0, dest_len, "trimming NULL string writes 0 characters" ) + JSVERIFY(SUCCEED, H5FD_s3comms_trim(dest, NULL, 3, &dest_len), + "should not fail when trimming a null string"); + JSVERIFY(0, dest_len, "trimming NULL string writes 0 characters") HDassert(str == NULL); str = (char *)HDmalloc(sizeof(char *) * 11); HDassert(str != NULL); memcpy(str, "some text ", 11); /* string with null terminator */ - JSVERIFY( FAIL, H5FD_s3comms_trim(NULL, str, 10, &dest_len), - "destination for trim cannot be NULL" ); + JSVERIFY(FAIL, H5FD_s3comms_trim(NULL, str, 10, &dest_len), "destination for trim cannot be NULL"); free(str); str = NULL; @@ -2506,7 +2440,6 @@ error: } /* end test_trim() */ - /*---------------------------------------------------------------------------- * * Function: test_uriencode() @@ -2538,68 +2471,61 @@ test_uriencode(void) * test-local variables * ************************/ - struct testcase cases[] = { - { "/path/to/resource.jpg", - 21, - FALSE, - "/path/to/resource.jpg", - }, - { "/path/to/resource.jpg", - 21, - TRUE, - "%2Fpath%2Fto%2Fresource.jpg", - }, - { "string got_spaa ces", - 20, - TRUE, - "string%20got_spaa%20%20ces", - }, - { "sp ac~es/and-sl ash.encoded", - 27, - TRUE, - "sp%20ac~es%2Fand-sl%20ash.encoded", - }, - { "sp ac~es/and-sl ash.unencoded", - 29, - FALSE, - "sp%20ac~es/and-sl%20ash.unencoded", - }, - { "/path/to/resource.txt", - 0, - FALSE, - "", - - } - }; - char *dest = NULL; - size_t dest_written = 0; - int i = 0; - int ncases = 6; - size_t str_len = 0; - - + struct testcase cases[] = {{ + "/path/to/resource.jpg", + 21, + FALSE, + "/path/to/resource.jpg", + }, + { + "/path/to/resource.jpg", + 21, + TRUE, + "%2Fpath%2Fto%2Fresource.jpg", + }, + { + "string got_spaa ces", + 20, + TRUE, + "string%20got_spaa%20%20ces", + }, + { + "sp ac~es/and-sl ash.encoded", + 27, + TRUE, + "sp%20ac~es%2Fand-sl%20ash.encoded", + }, + { + "sp ac~es/and-sl ash.unencoded", + 29, + FALSE, + "sp%20ac~es/and-sl%20ash.unencoded", + }, + { + "/path/to/resource.txt", + 0, + FALSE, + "", + + }}; + char * dest = NULL; + size_t dest_written = 0; + int i = 0; + int ncases = 6; + size_t str_len = 0; TESTING("s3comms uriencode") for (i = 0; i < ncases; i++) { str_len = cases[i].s_len; - dest = (char *)HDmalloc(sizeof(char) * str_len * 3 + 1); - FAIL_IF( dest == NULL ) - - JSVERIFY( SUCCEED, - H5FD_s3comms_uriencode( - dest, - cases[i].str, - str_len, - cases[i].encode_slash, - &dest_written), - NULL ); - JSVERIFY( HDstrlen(cases[i].expected), - dest_written, - NULL ) - JSVERIFY( 0, - strncmp(dest, cases[i].expected, dest_written), - cases[i].expected ); + dest = (char *)HDmalloc(sizeof(char) * str_len * 3 + 1); + FAIL_IF(dest == NULL) + + JSVERIFY(SUCCEED, + H5FD_s3comms_uriencode(dest, cases[i].str, str_len, cases[i].encode_slash, &dest_written), + NULL); + JSVERIFY(HDstrlen(cases[i].expected), dest_written, NULL) + JSVERIFY(0, strncmp(dest, cases[i].expected, dest_written), cases[i].expected); free(dest); dest = NULL; @@ -2612,12 +2538,10 @@ test_uriencode(void) dest = (char *)HDmalloc(sizeof(char) * 15); HDassert(dest != NULL); - JSVERIFY( FAIL, - H5FD_s3comms_uriencode(NULL, "word$", 5, false, &dest_written), - "destination cannot be NULL" ); - JSVERIFY( FAIL, - H5FD_s3comms_uriencode(dest, NULL, 5, false, &dest_written), - "source string cannot be NULL" ); + JSVERIFY(FAIL, H5FD_s3comms_uriencode(NULL, "word$", 5, false, &dest_written), + "destination cannot be NULL"); + JSVERIFY(FAIL, H5FD_s3comms_uriencode(dest, NULL, 5, false, &dest_written), + "source string cannot be NULL"); free(dest); dest = NULL; @@ -2635,8 +2559,6 @@ error: #endif /* H5_HAVE_ROS3_VFD */ - - /*------------------------------------------------------------------------- * Function: main() * @@ -2658,7 +2580,7 @@ int main(void) { #ifdef H5_HAVE_ROS3_VFD - int nerrors = 0; + int nerrors = 0; const char *bucket_url_env = NULL; h5_reset(); @@ -2675,24 +2597,20 @@ main(void) s3_test_aws_region[0] = '\0'; s3_test_bucket_url[0] = '\0'; -/* TODO: unit/regression test for H5FD_s3comms_load_aws_profile() - * requires a few test files and/or manipulation of default path - */ + /* TODO: unit/regression test for H5FD_s3comms_load_aws_profile() + * requires a few test files and/or manipulation of default path + */ /* attempt to load test credentials * if unable, certain tests will be skipped */ - if (SUCCEED == H5FD_s3comms_load_aws_profile( - S3_TEST_PROFILE_NAME, - s3_test_aws_access_key_id, - s3_test_aws_secret_access_key, - s3_test_aws_region)) - { + if (SUCCEED == H5FD_s3comms_load_aws_profile(S3_TEST_PROFILE_NAME, s3_test_aws_access_key_id, + s3_test_aws_secret_access_key, s3_test_aws_region)) { s3_test_credentials_loaded = 1; } bucket_url_env = HDgetenv("HDF5_ROS3_TEST_BUCKET_URL"); if (bucket_url_env == NULL || bucket_url_env[0] == '\0') { - HDprintf("WARNING: S3 bucket url is not defined in enviornment " \ + HDprintf("WARNING: S3 bucket url is not defined in enviornment " "variable 'HDF5_ROS3_TEST_BUCKET_URL'!\n"); } else { @@ -2702,26 +2620,24 @@ main(void) /* tests ordered rougly by dependence */ nerrors += test_macro_format_credential() < 0 ? 1 : 0; - nerrors += test_trim() < 0 ? 1 : 0; - nerrors += test_nlowercase() < 0 ? 1 : 0; - nerrors += test_uriencode() < 0 ? 1 : 0; - nerrors += test_percent_encode_char() < 0 ? 1 : 0; - nerrors += test_bytes_to_hex() < 0 ? 1 : 0; - nerrors += test_HMAC_SHA256() < 0 ? 1 : 0; - nerrors += test_signing_key() < 0 ? 1 : 0; - nerrors += test_hrb_node_set() < 0 ? 1 : 0; - nerrors += test_hrb_init_request() < 0 ? 1 : 0; - nerrors += test_parse_url() < 0 ? 1 : 0; - nerrors += test_aws_canonical_request() < 0 ? 1 : 0; - nerrors += test_tostringtosign() < 0 ? 1 : 0; - nerrors += test_s3r_open() < 0 ? 1 : 0; - nerrors += test_s3r_get_filesize() < 0 ? 1 : 0; - nerrors += test_s3r_read() < 0 ? 1 : 0; + nerrors += test_trim() < 0 ? 1 : 0; + nerrors += test_nlowercase() < 0 ? 1 : 0; + nerrors += test_uriencode() < 0 ? 1 : 0; + nerrors += test_percent_encode_char() < 0 ? 1 : 0; + nerrors += test_bytes_to_hex() < 0 ? 1 : 0; + nerrors += test_HMAC_SHA256() < 0 ? 1 : 0; + nerrors += test_signing_key() < 0 ? 1 : 0; + nerrors += test_hrb_node_set() < 0 ? 1 : 0; + nerrors += test_hrb_init_request() < 0 ? 1 : 0; + nerrors += test_parse_url() < 0 ? 1 : 0; + nerrors += test_aws_canonical_request() < 0 ? 1 : 0; + nerrors += test_tostringtosign() < 0 ? 1 : 0; + nerrors += test_s3r_open() < 0 ? 1 : 0; + nerrors += test_s3r_get_filesize() < 0 ? 1 : 0; + nerrors += test_s3r_read() < 0 ? 1 : 0; if (nerrors) { - HDprintf("***** %d S3comms TEST%s FAILED! *****\n", - nerrors, - nerrors > 1 ? "S" : ""); + HDprintf("***** %d S3comms TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : ""); return 1; } @@ -2737,4 +2653,3 @@ main(void) #endif /* H5_HAVE_ROS3_VFD */ } /* end main() */ - |