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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "rspamd.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. rspamd_session_destroy (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. #if 0
  55. rspamd_dkim_context_t *ctx;
  56. rspamd_dkim_key_t *key;
  57. rspamd_mempool_t *pool;
  58. struct rspamd_dns_resolver *resolver;
  59. struct rspamd_config *cfg;
  60. GError *err = NULL;
  61. struct rspamd_async_session *s;
  62. cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
  63. bzero (cfg, sizeof (struct rspamd_config));
  64. cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
  65. cfg->dns_retransmits = 2;
  66. cfg->dns_timeout = 0.5;
  67. pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
  68. resolver = dns_resolver_init (NULL, base, cfg);
  69. g_assert (resolver != NULL);
  70. ctx = rspamd_create_dkim_context (test_dkim_sig, pool, 0, &err);
  71. g_assert (ctx != NULL);
  72. /* Key part */
  73. s = rspamd_session_create (pool, session_fin, NULL, NULL, NULL);
  74. g_assert (rspamd_get_dkim_key (ctx, resolver, s, test_key_handler, s));
  75. event_base_loop (base, 0);
  76. #endif
  77. }