forked from aliyun/aliyun-oss-c-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6ca01e
commit d26e9e3
Showing
4 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1673,6 +1673,47 @@ void test_oss_fill_read_response_header(CuTest *tc) { | |
} | ||
|
||
|
||
static void test_oss_is_valid_host(CuTest *tc) { | ||
int i; | ||
const char *valid_host[] = | ||
{ | ||
"www.test.com:8192", | ||
"www.test.com", | ||
"test:[email protected]:80", | ||
"test:[email protected]", | ||
"192.168.1.1:8192", | ||
"192.168.1.1", | ||
"test:[email protected]:8192", | ||
"test:[email protected]", | ||
"www.test-inc_CN.com", | ||
"a" | ||
}; | ||
|
||
const char *invalid_host[] = | ||
{ | ||
"www.test.com#www.test.cn:8192", | ||
"test:[email protected]#www.test.cn:8192", | ||
"www.test.com#www.test.cn", | ||
"www.test.com\\www.test.cn", | ||
"", | ||
":", | ||
"@:", | ||
NULL | ||
}; | ||
|
||
for (i = 0; i < sizeof(valid_host) / sizeof(valid_host[0]); i++) { | ||
CuAssertIntEquals(tc, 1, oss_is_valid_host(valid_host[i])); | ||
} | ||
CuAssertIntEquals(tc, 10, i); | ||
|
||
for (i = 0; i < sizeof(invalid_host) / sizeof(invalid_host[0]); i++) { | ||
CuAssertIntEquals(tc, 0, oss_is_valid_host(invalid_host[i])); | ||
} | ||
CuAssertIntEquals(tc, 8, i); | ||
|
||
printf("%s ok\n", __FUNCTION__); | ||
} | ||
|
||
CuSuite *test_aos() | ||
{ | ||
CuSuite* suite = CuSuiteNew(); | ||
|
@@ -1745,6 +1786,7 @@ CuSuite *test_aos() | |
SUITE_ADD_TEST(suite, test_oss_preprocess_endpoint); | ||
SUITE_ADD_TEST(suite, test_oss_fill_read_response_header); | ||
SUITE_ADD_TEST(suite, test_oss_get_host_from_authority); | ||
|
||
SUITE_ADD_TEST(suite, test_oss_is_valid_host); | ||
|
||
return suite; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1844,6 +1844,61 @@ void test_get_object_to_buffer_use_invalid_sts(CuTest *tc) | |
|
||
} | ||
|
||
void test_object_with_invalid_endpoint(CuTest *tc) | ||
{ | ||
aos_pool_t *p = NULL; | ||
aos_string_t bucket; | ||
char *object_name = "video_1.ts"; | ||
aos_string_t object; | ||
int is_cname = 0; | ||
oss_request_options_t *options = NULL; | ||
aos_table_t *headers = NULL; | ||
aos_table_t *params = NULL; | ||
aos_table_t *resp_headers = NULL; | ||
aos_status_t *s = NULL; | ||
aos_list_t buffer; | ||
char endpoint_buf[256]; | ||
|
||
aos_pool_create(&p, NULL); | ||
options = oss_request_options_create(p); | ||
init_test_request_options(options, is_cname); | ||
|
||
aos_str_set(&bucket, TEST_BUCKET_NAME); | ||
aos_str_set(&object, object_name); | ||
aos_list_init(&buffer); | ||
|
||
aos_str_set(&options->config->endpoint, "www.test.com\\www.aliyuncs.com"); | ||
s = oss_get_object_to_buffer(options, &bucket, &object, headers, | ||
params, &buffer, &resp_headers); | ||
CuAssertIntEquals(tc, AOSE_INVALID_ARGUMENT, s->code); | ||
CuAssertStrEquals(tc, AOS_CLIENT_ERROR_CODE, s->error_code); | ||
CuAssertStrEquals(tc, "The endpoint is invalid.", s->error_msg); | ||
|
||
aos_str_set(&options->config->endpoint, "test:[email protected]*www.aliyuncs.com:80"); | ||
s = oss_get_object_to_buffer(options, &bucket, &object, headers, | ||
params, &buffer, &resp_headers); | ||
CuAssertIntEquals(tc, AOSE_INVALID_ARGUMENT, s->code); | ||
CuAssertStrEquals(tc, AOS_CLIENT_ERROR_CODE, s->error_code); | ||
CuAssertStrEquals(tc, "The endpoint is invalid.", s->error_msg); | ||
|
||
aos_str_set(&options->config->endpoint, "www.test.com*www.aliyuncs.com"); | ||
s = oss_get_object_to_buffer(options, &bucket, &object, headers, | ||
params, &buffer, &resp_headers); | ||
CuAssertIntEquals(tc, AOSE_INVALID_ARGUMENT, s->code); | ||
CuAssertStrEquals(tc, AOS_CLIENT_ERROR_CODE, s->error_code); | ||
CuAssertStrEquals(tc, "The endpoint is invalid.", s->error_msg); | ||
|
||
sprintf(endpoint_buf, "%s:80/test?x=1#segment", TEST_OSS_ENDPOINT); | ||
aos_str_set(&options->config->endpoint, endpoint_buf); | ||
s = oss_get_object_to_buffer(options, &bucket, &object, headers, | ||
params, &buffer, &resp_headers); | ||
CuAssertIntEquals(tc, 200, s->code); | ||
|
||
aos_pool_destroy(p); | ||
|
||
printf("test_object_with_invalid_endpoint ok\n"); | ||
|
||
} | ||
|
||
|
||
CuSuite *test_oss_object() | ||
|
@@ -1889,6 +1944,7 @@ CuSuite *test_oss_object() | |
SUITE_ADD_TEST(suite, test_object_invalid_parameter); | ||
SUITE_ADD_TEST(suite, test_get_object_to_buffer_with_maxbuffersize); | ||
SUITE_ADD_TEST(suite, test_get_object_to_buffer_use_invalid_sts); | ||
SUITE_ADD_TEST(suite, test_object_with_invalid_endpoint); | ||
SUITE_ADD_TEST(suite, test_object_cleanup); | ||
|
||
return suite; | ||
|