test_oss_proxy.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "CuTest.h"
  2. #include "aos_log.h"
  3. #include "aos_util.h"
  4. #include "aos_string.h"
  5. #include "aos_status.h"
  6. #include "oss_auth.h"
  7. #include "oss_util.h"
  8. #include "oss_xml.h"
  9. #include "oss_api.h"
  10. #include "oss_config.h"
  11. #include "oss_test_util.h"
  12. #include "aos_crc64.h"
  13. void test_proxy_setup(CuTest *tc)
  14. {
  15. aos_pool_t *p = NULL;
  16. int is_cname = 0;
  17. aos_status_t *s = NULL;
  18. oss_request_options_t *options = NULL;
  19. oss_acl_e oss_acl = OSS_ACL_PRIVATE;
  20. /* create test bucket */
  21. aos_pool_create(&p, NULL);
  22. options = oss_request_options_create(p);
  23. init_test_request_options(options, is_cname);
  24. s = create_test_bucket(options, TEST_BUCKET_NAME, oss_acl);
  25. CuAssertIntEquals(tc, 200, s->code);
  26. aos_pool_destroy(p);
  27. }
  28. void test_proxy_cleanup(CuTest *tc)
  29. {
  30. aos_pool_t *p = NULL;
  31. int is_cname = 0;
  32. aos_string_t bucket;
  33. oss_request_options_t *options = NULL;
  34. char *object_name1 = "oss_test_proxy_put_object.txt";
  35. aos_table_t *resp_headers = NULL;
  36. aos_pool_create(&p, NULL);
  37. options = oss_request_options_create(p);
  38. init_test_request_options(options, is_cname);
  39. /* delete test object */
  40. delete_test_object(options, TEST_BUCKET_NAME, object_name1);
  41. /* delete test bucket */
  42. aos_str_set(&bucket, TEST_BUCKET_NAME);
  43. oss_delete_bucket(options, &bucket, &resp_headers);
  44. apr_sleep(apr_time_from_sec(3));
  45. aos_pool_destroy(p);
  46. }
  47. void init_test_proxy_request_options(oss_request_options_t *options, int is_cname)
  48. {
  49. options->config = oss_config_create(options->pool);
  50. init_test_config(options->config, is_cname);
  51. aos_str_set(&options->config->proxy_host, decrypt("^]DRRDR^D^Z", options->pool));
  52. aos_str_set(&options->config->proxy_user, decrypt("\x1e\xf\x19\x1e\xf\x18", options->pool));
  53. aos_str_set(&options->config->proxy_passwd, decrypt("\"\xf\x6\x6\x5[XY^_", options->pool));
  54. options->config->proxy_port = 3128;
  55. options->ctl = aos_http_controller_create(options->pool, 0);
  56. oss_config_resolve(options->pool, options->config, options->ctl);
  57. }
  58. void test_proxy_put_object_from_buffer(CuTest *tc)
  59. {
  60. aos_pool_t *p = NULL;
  61. char *object_name = "oss_test_proxy_put_object.txt";
  62. char *str = "Sow nothing, reap nothing.";
  63. aos_status_t *s = NULL;
  64. int is_cname = 0;
  65. aos_string_t bucket;
  66. aos_string_t object;
  67. oss_request_options_t *options = NULL;
  68. aos_table_t *headers = NULL;
  69. aos_list_t buffer;
  70. aos_buf_t *content;
  71. /* init test*/
  72. aos_pool_create(&p, NULL);
  73. options = oss_request_options_create(p);
  74. init_test_proxy_request_options(options, is_cname);
  75. aos_str_set(&bucket, TEST_BUCKET_NAME);
  76. aos_str_set(&object, object_name);
  77. aos_list_init(&buffer);
  78. content = aos_buf_pack(options->pool, str, strlen(str));
  79. aos_list_add_tail(&content->node, &buffer);
  80. headers = aos_table_make(p, 2);
  81. apr_table_set(headers, "Expect", "");
  82. apr_table_set(headers, "Transfer-Encoding", "");
  83. /* test put object */
  84. s = oss_put_object_from_buffer(options, &bucket, &object, &buffer, headers, NULL);
  85. CuAssertIntEquals(tc, 200, s->code);
  86. aos_pool_destroy(p);
  87. /* test get object */
  88. aos_pool_create(&p, NULL);
  89. options = oss_request_options_create(p);
  90. init_test_proxy_request_options(options, is_cname);
  91. s = oss_get_object_to_buffer(options, &bucket, &object, NULL, NULL, &buffer, NULL);
  92. CuAssertIntEquals(tc, 200, s->code);
  93. aos_pool_destroy(p);
  94. printf("test_proxy_put_object_from_buffer ok\n");
  95. }
  96. void test_proxy_list_object(CuTest *tc)
  97. {
  98. aos_pool_t *p = NULL;
  99. aos_string_t bucket;
  100. oss_request_options_t *options = NULL;
  101. int is_cname = 0;
  102. aos_table_t *resp_headers = NULL;
  103. aos_status_t *s = NULL;
  104. oss_list_object_params_t *params = NULL;
  105. oss_list_object_content_t *content = NULL;
  106. int size = 0;
  107. aos_pool_create(&p, NULL);
  108. options = oss_request_options_create(p);
  109. init_test_proxy_request_options(options, is_cname);
  110. params = oss_create_list_object_params(p);
  111. params->max_ret = 1;
  112. params->truncated = 0;
  113. aos_str_set(&params->prefix, "oss_test_proxy_");
  114. aos_str_set(&bucket, TEST_BUCKET_NAME);
  115. s = oss_list_object(options, &bucket, params, &resp_headers);
  116. CuAssertIntEquals(tc, 200, s->code);
  117. aos_list_for_each_entry(oss_list_object_content_t, content, &params->object_list, node) {
  118. ++size;
  119. }
  120. CuAssertIntEquals(tc, 1 ,size);
  121. printf("test_proxy_list_object ok\n");
  122. }
  123. CuSuite *test_oss_proxy()
  124. {
  125. CuSuite* suite = CuSuiteNew();
  126. SUITE_ADD_TEST(suite, test_proxy_setup);
  127. SUITE_ADD_TEST(suite, test_proxy_put_object_from_buffer);
  128. SUITE_ADD_TEST(suite, test_proxy_list_object);
  129. SUITE_ADD_TEST(suite, test_proxy_cleanup);
  130. return suite;
  131. }