aboutsummaryrefslogtreecommitdiffstats
path: root/test/rspamd_dns_test.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-09-12 11:56:42 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-09-12 11:56:42 +0100
commit491e42b434921ed3d102956bb7ad1fe3697fef46 (patch)
tree45986c3764c82d50f4fded5e7c05a25c875adfa9 /test/rspamd_dns_test.c
parentad29a3dd73648b23f818d7a62c6424a14a884e10 (diff)
downloadrspamd-491e42b434921ed3d102956bb7ad1fe3697fef46.tar.gz
rspamd-491e42b434921ed3d102956bb7ad1fe3697fef46.zip
Restore testing framework.
Diffstat (limited to 'test/rspamd_dns_test.c')
-rw-r--r--test/rspamd_dns_test.c115
1 files changed, 56 insertions, 59 deletions
diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c
index 781b39503..5728b5a2d 100644
--- a/test/rspamd_dns_test.c
+++ b/test/rspamd_dns_test.c
@@ -1,110 +1,107 @@
-#include "../src/config.h"
+#include "config.h"
#include "tests.h"
-#include "../src/dns.h"
-#include "../src/logger.h"
-#include "../src/main.h"
-#include "../src/events.h"
-#include "../src/cfg_file.h"
+#include "dns.h"
+#include "logger.h"
+#include "main.h"
+#include "events.h"
+#include "cfg_file.h"
static guint requests = 0;
extern struct event_base *base;
+struct rspamd_dns_resolver *resolver;
-static void
-test_dns_cb (struct rspamd_dns_reply *reply, gpointer arg)
+gboolean
+session_fin (gpointer unused)
{
- union rspamd_reply_element *elt;
- GList *cur;
+ struct timeval tv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ event_loopexit (&tv);
- msg_debug ("got reply with code %s for request %s", dns_strerror (reply->code), reply->request->requested_name);
- if (reply->code == DNS_RC_NOERROR) {
- cur = reply->elements;
+ return TRUE;
+}
+
+static void
+test_dns_cb (struct rdns_reply *reply, gpointer arg)
+{
+ struct rdns_reply_entry *cur;
+ const struct rdns_request_name *name =
+ rdns_request_get_name (reply->request, NULL);
+
+ msg_debug ("got reply with code %s for request %s",
+ rdns_strerror (reply->code), name->name);
+ if (reply->code == RDNS_RC_NOERROR) {
+ cur = reply->entries;
while (cur) {
- elt = cur->data;
- switch (reply->request->type) {
- case DNS_REQUEST_A:
- msg_debug ("got ip: %s", inet_ntoa (elt->a.addr[0]));
+ switch (cur->type) {
+ case RDNS_REQUEST_A:
+ msg_debug ("got ip: %s", inet_ntoa (cur->content.a.addr));
break;
- case DNS_REQUEST_PTR:
- msg_debug ("got name %s", elt->ptr.name);
+ case RDNS_REQUEST_PTR:
+ msg_debug ("got name %s", cur->content.ptr.name);
break;
- case DNS_REQUEST_TXT:
- msg_debug ("got txt %s", elt->txt.data);
+ case RDNS_REQUEST_TXT:
+ msg_debug ("got txt %s", cur->content.txt.data);
break;
- case DNS_REQUEST_SPF:
- msg_debug ("got spf %s", elt->spf.data);
+ case RDNS_REQUEST_SPF:
+ msg_debug ("got spf %s", cur->content.txt.data);
break;
- case DNS_REQUEST_SRV:
- msg_debug ("got srv pri: %d, weight: %d, port: %d, target: %s", elt->srv.weight,
- elt->srv.priority, elt->srv.port, elt->srv.target);
+ case RDNS_REQUEST_SRV:
+ msg_debug ("got srv pri: %d, weight: %d, port: %d, target: %s", cur->content.srv.weight,
+ cur->content.srv.priority, cur->content.srv.port, cur->content.srv.target);
break;
- case DNS_REQUEST_MX:
- msg_debug ("got mx %s:%d", elt->mx.name, elt->mx.priority);
+ case RDNS_REQUEST_MX:
+ msg_debug ("got mx %s:%d", cur->content.mx.name, cur->content.mx.priority);
break;
}
- cur = g_list_next (cur);
+ cur = cur->next;
}
}
if (-- requests == 0) {
- destroy_session (reply->request->session);
+ session_fin (NULL);
}
}
-gboolean
-session_fin (gpointer unused)
-{
- struct timeval tv;
-
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- event_loopexit (&tv);
-
- return TRUE;
-}
-
void
rspamd_dns_test_func ()
{
- struct rspamd_dns_resolver *resolver;
+
struct rspamd_config *cfg;
rspamd_mempool_t *pool;
struct rspamd_async_session *s;
- struct in_addr ina;
cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
bzero (cfg, sizeof (struct rspamd_config));
cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
- cfg->dns_retransmits = 10;
- cfg->dns_timeout = 1000;
+ cfg->dns_retransmits = 2;
+ cfg->dns_timeout = 0.5;
pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
s = new_async_session (pool, session_fin, NULL, NULL, NULL);
- resolver = dns_resolver_init (base, cfg);
-
- ina.s_addr = inet_addr ("81.19.70.3");
+ resolver = dns_resolver_init (NULL, base, cfg);
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_A, "google.com"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_A, "google.com"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_PTR, &ina));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_PTR, "81.19.70.3"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_MX, "rambler.ru"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_MX, "rambler.ru"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "rambler.ru"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_TXT, "rambler.ru"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "google.com"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_TXT, "google.com"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_SPF, "rambler.ru"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_SPF, "rambler.ru"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_SRV, "xmpp-server", "tcp", "jabber.org"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_SRV, "_xmpp-server._tcp.jabber.org"));
requests ++;
- g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "non-existent.arpa"));
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_TXT, "non-existent.arpa"));
g_assert (resolver != NULL);
-
-
event_loop (0);
}