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_dkim_test.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (c) 2011, Vsevolod Stakhov
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
  13. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
  16. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  18. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #include "config.h"
  24. #include "tests.h"
  25. #include "main.h"
  26. #include "dkim.h"
  27. static const gchar test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; "
  28. "d=highsecure.ru; s=dkim; t=1410516996; "
  29. "bh=guFoWYHWVzFRqVyAQebnvPcdm7bUQo7pRHt/uIHD7gs=; "
  30. "h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; "
  31. "b=PCiECkOaPFb99DW+gApgfmdlTUo6XN6YXjnj52Cxoz2FoA857B0ZHFgeQe4JAKHuhW"
  32. "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy"
  33. "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;";
  34. extern struct event_base *base;
  35. static void
  36. test_key_handler (rspamd_dkim_key_t *key, gsize keylen, rspamd_dkim_context_t *ctx, gpointer ud, GError *err)
  37. {
  38. struct rspamd_async_session *s = ud;
  39. g_assert (key != NULL);
  40. destroy_session (s);
  41. }
  42. static gboolean
  43. session_fin (gpointer unused)
  44. {
  45. struct timeval tv;
  46. tv.tv_sec = 0;
  47. tv.tv_usec = 0;
  48. event_loopexit (&tv);
  49. return TRUE;
  50. }
  51. void
  52. rspamd_dkim_test_func ()
  53. {
  54. rspamd_dkim_context_t *ctx;
  55. rspamd_dkim_key_t *key;
  56. rspamd_mempool_t *pool;
  57. struct rspamd_dns_resolver *resolver;
  58. struct rspamd_config *cfg;
  59. GError *err = NULL;
  60. struct rspamd_async_session *s;
  61. cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
  62. bzero (cfg, sizeof (struct rspamd_config));
  63. cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
  64. cfg->dns_retransmits = 2;
  65. cfg->dns_timeout = 0.5;
  66. pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
  67. resolver = dns_resolver_init (NULL, base, cfg);
  68. g_assert (resolver != NULL);
  69. ctx = rspamd_create_dkim_context (test_dkim_sig, pool, 0, &err);
  70. g_assert (ctx != NULL);
  71. /* Key part */
  72. s = new_async_session (pool, session_fin, NULL, NULL, NULL);
  73. g_assert (rspamd_get_dkim_key (ctx, resolver, s, test_key_handler, s));
  74. event_base_loop (base, 0);
  75. }