You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rspamd_url_test.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include <sys/types.h>
  2. #include <sys/time.h>
  3. #include <sys/wait.h>
  4. #include <sys/param.h>
  5. #include <netinet/in.h>
  6. #include <arpa/inet.h>
  7. #include <netdb.h>
  8. #include <syslog.h>
  9. #include <fcntl.h>
  10. #include <stdlib.h>
  11. #include "../config.h"
  12. #include "../main.h"
  13. #include "../cfg_file.h"
  14. #include "../url.h"
  15. #include "tests.h"
  16. const char *test_text =
  17. "www.schemeless.ru\n"
  18. "www.schemeless.rus\n"
  19. " as ftp.schemeless.ru dasd \n"
  20. "ftp12.schemeless.ru\n"
  21. "ftpsearch.schemeless.ru\n"
  22. "schemeless.ru\n"
  23. "www.schemeless.microsoft\n"
  24. "1.2.3.4\n"
  25. "1.2.3.4/a\n"
  26. "1.2.3\n"
  27. "1.2.3.4.5\n"
  28. "www.schemeless.ru,\n"
  29. "www.schemeless.ru.\n"
  30. "http://www.schemed.ru.\n"
  31. "http://www.schemed.ru.\n"
  32. "http://www.bolinfest.com/targetalert/'\n"
  33. "http://www.bolinfest.com/targetalert/'';\n"
  34. "https://www.schemed.ru.\n"
  35. "ufps://www.schemed.ru.\n"
  36. "http://ported.ru:8080\n"
  37. "http://ported.ru:8080\n"
  38. "http://1.2.3.4\n"
  39. "http://1.2.3.4:80\n"
  40. "1.2.3.4:80\n"
  41. "www.a9.com\n"
  42. "www.a-9.com\n"
  43. "http://www.schemed.ru/a.txt:\n"
  44. "http://www.schemed.ru/a.txt'\n"
  45. "http://www.schemed.ru/a.txt\"\n"
  46. "http://www.schemed.ru/a.txt>\n"
  47. "http://www.schemed.ru/a=3&b=4\n"
  48. "http://spam.ru/bad=user@domain.com\n"
  49. "http://spam.ru/bad=user@domain.com\n"
  50. "http://spam.ru user@domain.com\n"
  51. "http://a.foto.radikal.ru/0604/de7793c6ca62.jpg\n"
  52. "http://a.foto.radikal.ru/0604/de7793c6ca62.jpg\n"
  53. "schemeless.gz\n"
  54. "schemeless.jp\n"
  55. "schemeless.ua\n"
  56. "schemeless.gz/a\n"
  57. "mysql.so\n"
  58. "http://mysql.so\n"
  59. "3com.com\n"
  60. "lj-user.livejournal.com\n"
  61. "http://lj-user.livejournal.com\n"
  62. "http://vsem.ru?action;\n";
  63. const char *test_html = "<some_tag>This is test file with <a href=\"http://microsoft.com\">http://TesT.com/././?%45%46%20 url</a></some_tag>";
  64. /* Function for using in glib test suite */
  65. void
  66. rspamd_url_test_func ()
  67. {
  68. GByteArray *text, *html;
  69. struct worker_task task;
  70. struct uri *url;
  71. int i = 0;
  72. text = g_byte_array_new();
  73. text->data = (gchar *)test_text;
  74. text->len = strlen (test_text);
  75. html = g_byte_array_new();
  76. html->data = (gchar *)test_html;
  77. html->len = strlen (test_html);
  78. bzero (&task, sizeof (task));
  79. TAILQ_INIT (&task.urls);
  80. g_test_timer_start ();
  81. g_test_message ("Testing text URL regexp parser");
  82. msg_debug ("Passing string: %s", test_text);
  83. url_parse_text (&task, text);
  84. TAILQ_FOREACH (url, &task.urls, next) {
  85. msg_debug ("Found url: %s, hostname: %s, data: %s", struri (url), url->host, url->data);
  86. i ++;
  87. }
  88. while (!TAILQ_EMPTY (&task.urls)) {
  89. url = TAILQ_FIRST (&task.urls);
  90. TAILQ_REMOVE (&task.urls, url, next);
  91. g_free (url->string);
  92. g_free (url);
  93. }
  94. g_assert (i == 39);
  95. msg_debug ("Time elapsed: %.2f", g_test_timer_elapsed ());
  96. i = 0;
  97. g_test_timer_start ();
  98. g_test_message ("Testing html URL regexp parser");
  99. msg_debug ("Passing string: %s", test_html);
  100. url_parse_html (&task, html);
  101. TAILQ_FOREACH (url, &task.urls, next) {
  102. msg_debug ("Found url: %s, hostname: %s, data: %s", struri (url), url->host, url->data);
  103. i ++;
  104. }
  105. while (!TAILQ_EMPTY (&task.urls)) {
  106. url = TAILQ_FIRST (&task.urls);
  107. TAILQ_REMOVE (&task.urls, url, next);
  108. g_free (url->string);
  109. g_free (url);
  110. }
  111. g_assert (i == 1);
  112. msg_debug ("Time elapsed: %.2f", g_test_timer_elapsed ());
  113. }