mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-01 17:36:10 +03:00
Added dns_decode test for response
This commit is contained in:
parent
5beb814d8c
commit
d1c36f3db4
@ -29,6 +29,7 @@ void dns_login(int, char *, int);
|
|||||||
int dns_read(int, char *, int);
|
int dns_read(int, char *, int);
|
||||||
int dns_encode_hostname(const char *, char *, int);
|
int dns_encode_hostname(const char *, char *, int);
|
||||||
int dns_encode(char *, size_t, struct query *, int, char *, size_t);
|
int dns_encode(char *, size_t, struct query *, int, char *, size_t);
|
||||||
|
int dns_decode(char *, int, int, char *, int);
|
||||||
|
|
||||||
extern struct sockaddr_in peer;
|
extern struct sockaddr_in peer;
|
||||||
|
|
||||||
|
48
tests/dns.c
48
tests/dns.c
@ -28,6 +28,22 @@
|
|||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
|
static char queryPacket[] =
|
||||||
|
"\x05\x39\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x05\x73\x69\x6C\x6C"
|
||||||
|
"\x79\x04\x68\x6F\x73\x74\x02\x6F\x66\x06\x69\x6F\x64\x69\x6E\x65\x04"
|
||||||
|
"\x63\x6F\x64\x65\x04\x6B\x72\x79\x6F\x02\x73\x65\x00\x00\x0A\x00\x01"
|
||||||
|
"\x00\x00\x29\x10\x00\x00\x00\x80\x00\x00\x00";
|
||||||
|
|
||||||
|
static char answerPacket[] =
|
||||||
|
"\x05\x39\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x05\x73\x69\x6C\x6C"
|
||||||
|
"\x79\x04\x68\x6F\x73\x74\x02\x6F\x66\x06\x69\x6F\x64\x69\x6E\x65\x04"
|
||||||
|
"\x63\x6F\x64\x65\x04\x6B\x72\x79\x6F\x02\x73\x65\x00\x00\x0A\x00\x01"
|
||||||
|
"\xC0\x0C\x00\x0A\x00\x01\x00\x00\x00\x00\x00\x23\x74\x68\x69\x73\x20"
|
||||||
|
"\x69\x73\x20\x74\x68\x65\x20\x6D\x65\x73\x73\x61\x67\x65\x20\x74\x6F"
|
||||||
|
"\x20\x62\x65\x20\x64\x65\x6C\x69\x76\x65\x72\x65\x64";
|
||||||
|
|
||||||
|
static char *msgData = "this is the message to be delivered";
|
||||||
|
|
||||||
START_TEST(test_encode_hostname)
|
START_TEST(test_encode_hostname)
|
||||||
{
|
{
|
||||||
char out[] = "\x06" "BADGER\x06" "BADGER\x04" "KRYO\x02" "SE\x00";
|
char out[] = "\x06" "BADGER\x06" "BADGER\x04" "KRYO\x02" "SE\x00";
|
||||||
@ -83,12 +99,6 @@ START_TEST(test_encode_hostname_toolong)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
char queryPacket[] =
|
|
||||||
"\x05\x39\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x05\x73\x69\x6C\x6C"
|
|
||||||
"\x79\x04\x68\x6F\x73\x74\x02\x6F\x66\x06\x69\x6F\x64\x69\x6E\x65\x04"
|
|
||||||
"\x63\x6F\x64\x65\x04\x6B\x72\x79\x6F\x02\x73\x65\x00\x00\x0A\x00\x01"
|
|
||||||
"\x00\x00\x29\x10\x00\x00\x00\x80\x00\x00\x00";
|
|
||||||
|
|
||||||
START_TEST(test_encode_query)
|
START_TEST(test_encode_query)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
@ -110,19 +120,10 @@ START_TEST(test_encode_query)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
char answerPacket[] =
|
|
||||||
"\x05\x39\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x05\x73\x69\x6C\x6C"
|
|
||||||
"\x79\x04\x68\x6F\x73\x74\x02\x6F\x66\x06\x69\x6F\x64\x69\x6E\x65\x04"
|
|
||||||
"\x63\x6F\x64\x65\x04\x6B\x72\x79\x6F\x02\x73\x65\x00\x00\x0A\x00\x01"
|
|
||||||
"\xC0\x0C\x00\x0A\x00\x01\x00\x00\x00\x00\x00\x23\x74\x68\x69\x73\x20"
|
|
||||||
"\x69\x73\x20\x74\x68\x65\x20\x6D\x65\x73\x73\x61\x67\x65\x20\x74\x6F"
|
|
||||||
"\x20\x62\x65\x20\x64\x65\x6C\x69\x76\x65\x72\x65\x64";
|
|
||||||
|
|
||||||
START_TEST(test_encode_response)
|
START_TEST(test_encode_response)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
char *host = "silly.host.of.iodine.code.kryo.se";
|
char *host = "silly.host.of.iodine.code.kryo.se";
|
||||||
char *data = "this is the message to be delivered";
|
|
||||||
struct query q;
|
struct query q;
|
||||||
int len;
|
int len;
|
||||||
int ret;
|
int ret;
|
||||||
@ -133,7 +134,7 @@ START_TEST(test_encode_response)
|
|||||||
q.type = T_NULL;
|
q.type = T_NULL;
|
||||||
q.id = 1337;
|
q.id = 1337;
|
||||||
|
|
||||||
ret = dns_encode(buf, len, &q, QR_ANSWER, data, strlen(data));
|
ret = dns_encode(buf, len, &q, QR_ANSWER, msgData, strlen(msgData));
|
||||||
len = sizeof(answerPacket) - 1; // Skip extra null character
|
len = sizeof(answerPacket) - 1; // Skip extra null character
|
||||||
|
|
||||||
fail_unless(strncmp(answerPacket, buf, sizeof(answerPacket)) == 0, "Did not compile expected packet");
|
fail_unless(strncmp(answerPacket, buf, sizeof(answerPacket)) == 0, "Did not compile expected packet");
|
||||||
@ -141,6 +142,20 @@ START_TEST(test_encode_response)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(test_decode_response)
|
||||||
|
{
|
||||||
|
char buf[512];
|
||||||
|
int len;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
len = sizeof(buf);
|
||||||
|
|
||||||
|
ret = dns_decode(buf, len, QR_ANSWER, answerPacket, sizeof(answerPacket)-1);
|
||||||
|
fail_unless(strncmp(msgData, buf, sizeof(msgData)) == 0, "Did not extract expected data");
|
||||||
|
fail_unless(ret == strlen(msgData), va_str("Bad data length: %d, expected %d", ret, strlen(msgData)));
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
TCase *
|
TCase *
|
||||||
test_dns_create_tests()
|
test_dns_create_tests()
|
||||||
{
|
{
|
||||||
@ -152,6 +167,7 @@ test_dns_create_tests()
|
|||||||
tcase_add_test(tc, test_encode_hostname_toolong);
|
tcase_add_test(tc, test_encode_hostname_toolong);
|
||||||
tcase_add_test(tc, test_encode_query);
|
tcase_add_test(tc, test_encode_query);
|
||||||
tcase_add_test(tc, test_encode_response);
|
tcase_add_test(tc, test_encode_response);
|
||||||
|
tcase_add_test(tc, test_decode_response);
|
||||||
|
|
||||||
return tc;
|
return tc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user