Updated Branches: refs/heads/test/TS-1570-parse_url-port-fail [created] 814141136
TS-1570: regression test for URLs that should fail We add a helper function to test urls, and run two sets of arrays now: One that should succeed, and one that should fail. Unfortunately, due to issue TS-1570, a port with garbage at the end is parsed "correctly". Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/81414113 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/81414113 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/81414113 Branch: refs/heads/test/TS-1570-parse_url-port-fail Commit: 8141411361fbafffa6aa8329fe5f3adaa8d68549 Parents: 0fc0820 Author: Igor GaliÄ <i.ga...@brainsware.org> Authored: Mon Jan 20 20:20:34 2014 +0100 Committer: Igor GaliÄ <i.ga...@brainsware.org> Committed: Mon Jan 20 20:20:34 2014 +0100 ---------------------------------------------------------------------- proxy/InkAPITest.cc | 118 ++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/81414113/proxy/InkAPITest.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc index 727cc26..417051d 100644 --- a/proxy/InkAPITest.cc +++ b/proxy/InkAPITest.cc @@ -5137,6 +5137,52 @@ REGRESSION_TEST(SDK_API_TSMimeHdrParse) (RegressionTest * test, int /* atype ATS // Unit Test for API: TSUrlParse ////////////////////////////////////////////// +static bool +parse_url_helper(RegressionTest *test, const char* url) { + + TSMBuffer bufp; + TSMLoc url_loc = (TSMLoc)NULL; + const char *start; + const char *end; + char *temp; + + int retval; + int length; + bool status = false; + + bufp = TSMBufferCreate(); + + if (TSUrlCreate(bufp, &url_loc) != TS_SUCCESS) { + SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Cannot create Url for parsing the url"); + if (TSMBufferDestroy(bufp) == TS_ERROR) { + SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Error in Destroying MBuffer"); + } + } else { + start = url; + end = url + strlen(url) + 1; + if ((retval = TSUrlParse(bufp, url_loc, &start, end)) == TS_PARSE_ERROR) { + SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "TSUrlParse returns TS_PARSE_ERROR"); + } else { + if (retval == TS_PARSE_DONE) { + temp = TSUrlStringGet(bufp, url_loc, &length); + if (strncmp(url, temp, length) == 0) { + SDK_RPRINT(test, "TSUrlParse", url, TC_PASS, "ok"); + status = true; + } else { + SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Value's Mismatch"); + } + TSfree(temp); + } else { + SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Parsing Error"); + } + } + } + + TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc); + TSMBufferDestroy(bufp); + return status; +} + REGRESSION_TEST(SDK_API_TSUrlParse) (RegressionTest * test, int /* atype ATS_UNUSED */, int *pstatus) { static char const * const urls[] = { @@ -5155,67 +5201,45 @@ REGRESSION_TEST(SDK_API_TSUrlParse) (RegressionTest * test, int /* atype ATS_UNU "foo://bar.com/baz/", "http://a.b.com/xx.jpg?newpath=http://b.c.com" // https://issues.apache.org/jira/browse/TS-1635 }; + static char const * const fail_urls[] = { + "http://www.example.com:8083xyz", + "https:://www.example.com/", + }; - static int const num_urls = sizeof(urls) / sizeof(urls[0]); - bool test_passed[num_urls] = {false}; - + static int const num_urls = sizeof(urls) / sizeof(urls[0]); + static int const num_fail_urls = sizeof(fail_urls) / sizeof(fail_urls[0]); - const char *start; - const char *end; - char *temp; - - int retval; - - TSMBuffer bufp; - TSMLoc url_loc = (TSMLoc)NULL; - int length; + bool test_passed[num_urls] = {false}; + bool test_failed[num_fail_urls] = {false}; *pstatus = REGRESSION_TEST_INPROGRESS; - int idx; - for (idx = 0; idx < num_urls; idx++) { - char const *url = urls[idx]; + int idx_pass; + int idx_fail; + for (idx_pass = 0; idx_pass < num_urls; idx_pass++) { + char const *url = urls[idx_pass]; + test_passed[idx_pass] = parse_url_helper(test, url); + } + for (idx_fail = 0; idx_fail < num_fail_urls; idx_fail++) { + char const *url = fail_urls[idx_fail]; + test_failed[idx_fail] = parse_url_helper(test, url); + } - bufp = TSMBufferCreate(); - if (TSUrlCreate(bufp, &url_loc) != TS_SUCCESS) { - SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Cannot create Url for parsing the url"); - if (TSMBufferDestroy(bufp) == TS_ERROR) { - SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Error in Destroying MBuffer"); - } - } else { - start = url; - end = url + strlen(url) + 1; - if ((retval = TSUrlParse(bufp, url_loc, &start, end)) == TS_PARSE_ERROR) { - SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "TSUrlParse returns TS_PARSE_ERROR"); - } else { - if (retval == TS_PARSE_DONE) { - temp = TSUrlStringGet(bufp, url_loc, &length); - if (strncmp(url, temp, length) == 0) { - SDK_RPRINT(test, "TSUrlParse", url, TC_PASS, "ok"); - test_passed[idx] = true; - } else { - SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Value's Mismatch"); - } - TSfree(temp); - } else { - SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Parsing Error"); - } - } + for (idx_pass = 0; idx_pass < num_urls; idx_pass++) { + if (test_passed[idx_pass] != true) { + *pstatus = REGRESSION_TEST_FAILED; + break; } - - TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc); - TSMBufferDestroy(bufp); } - - for (idx = 0; idx < num_urls; idx++) { - if (test_passed[idx] != true) { + for (idx_fail = 0; idx_fail < num_fail_urls; idx_fail++) { + if (test_failed[idx_fail] != false) { *pstatus = REGRESSION_TEST_FAILED; break; } } - if (idx >= num_urls) { + if (idx_pass >= num_urls && idx_fail >= num_fail_urls) { *pstatus = REGRESSION_TEST_PASSED; }