lighttpd 1.4.x https://www.lighttpd.net/
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

208 líneas
7.2 KiB

  1. #include "first.h"
  2. #undef NDEBUG
  3. #include <assert.h>
  4. #include <stdlib.h>
  5. #include "mod_userdir.c"
  6. static void test_mod_userdir_reset(request_st * const r)
  7. {
  8. r->http_status = 0;
  9. buffer_clear(&r->physical.basedir);
  10. buffer_clear(&r->physical.path);
  11. }
  12. static void
  13. test_mod_userdir_docroot_handler(request_st * const r, plugin_data * const p)
  14. {
  15. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN(""));
  16. test_mod_userdir_reset(r);
  17. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  18. assert(buffer_is_empty(&r->physical.basedir));
  19. assert(buffer_is_empty(&r->physical.path));
  20. p->defaults.active = 1;
  21. test_mod_userdir_reset(r);
  22. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  23. assert(buffer_is_empty(&r->physical.basedir));
  24. assert(buffer_is_empty(&r->physical.path));
  25. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/"));
  26. test_mod_userdir_reset(r);
  27. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  28. assert(buffer_is_empty(&r->physical.basedir));
  29. assert(buffer_is_empty(&r->physical.path));
  30. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/other"));
  31. test_mod_userdir_reset(r);
  32. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  33. assert(buffer_is_empty(&r->physical.basedir));
  34. assert(buffer_is_empty(&r->physical.path));
  35. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~"));
  36. test_mod_userdir_reset(r);
  37. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  38. assert(buffer_is_empty(&r->physical.basedir));
  39. assert(buffer_is_empty(&r->physical.path));
  40. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~no-trailing-slash"));
  41. test_mod_userdir_reset(r);
  42. assert(HANDLER_FINISHED == mod_userdir_docroot_handler(r, p));
  43. assert(301 == r->http_status);
  44. assert(buffer_is_empty(&r->physical.basedir));
  45. assert(buffer_is_empty(&r->physical.path));
  46. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~/"));
  47. test_mod_userdir_reset(r);
  48. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  49. assert(buffer_is_empty(&r->physical.basedir));
  50. assert(buffer_is_empty(&r->physical.path));
  51. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/"));
  52. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/"));
  53. test_mod_userdir_reset(r);
  54. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  55. assert(buffer_eq_slen(&r->physical.basedir,
  56. CONST_STR_LEN("/web/u/jan/public_html")));
  57. assert(buffer_eq_slen(&r->physical.path,
  58. CONST_STR_LEN("/web/u/jan/public_html/")));
  59. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/more"));
  60. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/more"));
  61. test_mod_userdir_reset(r);
  62. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  63. assert(buffer_eq_slen(&r->physical.basedir,
  64. CONST_STR_LEN("/web/u/jan/public_html")));
  65. assert(buffer_eq_slen(&r->physical.path,
  66. CONST_STR_LEN("/web/u/jan/public_html/more")));
  67. p->defaults.letterhomes = 1;
  68. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~.jan/"));
  69. test_mod_userdir_reset(r);
  70. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  71. assert(buffer_is_empty(&r->physical.basedir));
  72. assert(buffer_is_empty(&r->physical.path));
  73. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/"));
  74. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/"));
  75. test_mod_userdir_reset(r);
  76. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  77. assert(buffer_eq_slen(&r->physical.basedir,
  78. CONST_STR_LEN("/web/u/j/jan/public_html")));
  79. assert(buffer_eq_slen(&r->physical.path,
  80. CONST_STR_LEN("/web/u/j/jan/public_html/")));
  81. p->defaults.letterhomes = 0;
  82. array *include_user = array_init(2);
  83. array *exclude_user = array_init(2);
  84. array_insert_value(include_user, CONST_STR_LEN("notjan"));
  85. p->defaults.include_user = include_user;
  86. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/"));
  87. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/"));
  88. test_mod_userdir_reset(r);
  89. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  90. assert(buffer_is_empty(&r->physical.basedir));
  91. assert(buffer_is_empty(&r->physical.path));
  92. array_insert_value(include_user, CONST_STR_LEN("jan"));
  93. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/"));
  94. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/"));
  95. test_mod_userdir_reset(r);
  96. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  97. assert(buffer_eq_slen(&r->physical.basedir,
  98. CONST_STR_LEN("/web/u/jan/public_html")));
  99. assert(buffer_eq_slen(&r->physical.path,
  100. CONST_STR_LEN("/web/u/jan/public_html/")));
  101. p->defaults.exclude_user = exclude_user;
  102. array_insert_value(exclude_user, CONST_STR_LEN("notjan"));
  103. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/"));
  104. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/"));
  105. test_mod_userdir_reset(r);
  106. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  107. assert(buffer_eq_slen(&r->physical.basedir,
  108. CONST_STR_LEN("/web/u/jan/public_html")));
  109. assert(buffer_eq_slen(&r->physical.path,
  110. CONST_STR_LEN("/web/u/jan/public_html/")));
  111. array_insert_value(exclude_user, CONST_STR_LEN("jan"));
  112. buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/~jan/"));
  113. buffer_copy_string_len(&r->physical.rel_path, CONST_STR_LEN("/~jan/"));
  114. test_mod_userdir_reset(r);
  115. assert(HANDLER_GO_ON == mod_userdir_docroot_handler(r, p));
  116. assert(buffer_is_empty(&r->physical.basedir));
  117. assert(buffer_is_empty(&r->physical.path));
  118. p->defaults.include_user = NULL;
  119. p->defaults.exclude_user = NULL;
  120. array_free(include_user);
  121. array_free(exclude_user);
  122. }
  123. int main (void)
  124. {
  125. plugin_data * const p = mod_userdir_init();
  126. assert(NULL != p);
  127. buffer *basepath = buffer_init_string("/web/u/"); /*(skip getpwnam())*/
  128. buffer *path = buffer_init_string("public_html");
  129. p->defaults.basepath = basepath;
  130. p->defaults.path = path;
  131. request_st r;
  132. memset(&r, 0, sizeof(request_st));
  133. r.tmp_buf = buffer_init();
  134. r.conf.errh = log_error_st_init();
  135. r.conf.errh->errorlog_fd = -1; /* (disable) */
  136. test_mod_userdir_docroot_handler(&r, p);
  137. free(r.uri.path.ptr);
  138. free(r.physical.basedir.ptr);
  139. free(r.physical.path.ptr);
  140. free(r.physical.rel_path.ptr);
  141. log_error_st_free(r.conf.errh);
  142. buffer_free(r.tmp_buf);
  143. buffer_free(basepath);
  144. buffer_free(path);
  145. free(p);
  146. return 0;
  147. }
  148. /*
  149. * stub functions
  150. */
  151. int http_response_redirect_to_directory(request_st *r, int status) {
  152. r->http_status = status;
  153. return 0;
  154. }
  155. int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname) {
  156. UNUSED(srv);
  157. UNUSED(p_d);
  158. UNUSED(cpk);
  159. UNUSED(mname);
  160. return 0;
  161. }
  162. int config_check_cond(request_st *r, int context_ndx) {
  163. UNUSED(r);
  164. UNUSED(context_ndx);
  165. return 0;
  166. }