Commit d3730100 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

updated log/debug prints and added resolver tests

removed some debug statements, updated some dlog() calls
Added two tests for resolver. Right now, these tests make it resolve
addresses in the public dns (www.isc.org and an nxdomain in isc.org),
we'll need to do something better in the long run, but for now i just
want to able to test resolving
parent bd458146
......@@ -416,11 +416,11 @@ private:
// returns false if we are not done
bool handleRecursiveAnswer(const Message& incoming) {
if (incoming.getRRCount(Message::SECTION_ANSWER) > 0) {
dlog("[XX] this looks like the final result");
dlog("Got final result, copying answer.");
copyAnswerMessage(incoming, answer_message_);
return true;
} else {
dlog("[XX] this looks like a delegation");
dlog("Got delegation, continuing");
// ok we need to do some more processing.
// the ns list should contain all nameservers
// while the additional may contain addresses for
......@@ -484,10 +484,9 @@ public:
retries_(retries),
zone_servers_()
{
dlog("[XX] Started a new RunningQuery");
dlog("Started a new RunningQuery");
done = false;
dlog("[XX] zone_servers size: " + zone_servers_.size());
// hardcoded f.root-servers.net now, should use NSAS
if (upstream_->empty()) {
zone_servers_.push_back(addr_t("192.5.5.241", 53));
......@@ -498,15 +497,12 @@ public:
// This function is used as callback from DNSQuery.
virtual void operator()(UDPQuery::Result result) {
dlog("[XX] RunningQuery operator() called with result: " + result);
// XXX is this the place for TCP retry?
if (result != UDPQuery::TIME_OUT) {
// we got an answer
std::cout << "[XX] for question: " << question_.toText() << std::endl;
Message incoming(Message::PARSE);
InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
incoming.fromWire(ibuf);
std::cout << "[XX] received answer: " << incoming.toText() << std::endl;
if (upstream_->size() == 0 &&
incoming.getRcode() == Rcode::NOERROR()) {
......@@ -517,13 +513,12 @@ public:
}
if (done) {
std::cerr << "[XX] Done, returning to server" << std::endl;
server_->resume(result == UDPQuery::SUCCESS);
delete this;
}
} else if (retries_--) {
dlog("Resending query");
// We timed out, but we have some retries, so send again
dlog("Timeout, resending query");
send();
} else {
// out of retries, give up for now
......
......@@ -31,6 +31,7 @@
#include <exceptions/exceptions.h>
#include <dns/tests/unittest_util.h>
#include <dns/rcode.h>
#include <dns/buffer.h>
#include <dns/message.h>
......@@ -451,7 +452,8 @@ protected:
size_t length = 0)
{}
void resume(const bool) { // in our test this shouldn't be called
void resume(const bool) {
// should never be called in our tests
}
DNSServer* clone() {
......@@ -661,7 +663,7 @@ TEST_F(ASIOLinkTest, recursiveSetupV6) {
// a routine that can do this with variable address family, address, and
// port, and with the various callbacks defined in such a way as to ensure
// full code coverage including error cases.
TEST_F(ASIOLinkTest, recursiveSend) {
TEST_F(ASIOLinkTest, forwarderSend) {
setDNSService(true, false);
// Note: We use the test prot plus one to ensure we aren't binding
......@@ -750,6 +752,56 @@ TEST_F(ASIOLinkTest, recursiveTimeout) {
EXPECT_EQ(3, num);
}
// as mentioned above, we need a more better framework for this,
// in addition to that, this sends out queries into the world
// (which we should catch somehow and fake replies for)
// for the skeleton code, it shouldn't be too much of a problem
TEST_F(ASIOLinkTest, recursiveSendOk) {
setDNSService(true, false);
bool done;
MockServerStop server(*io_service_, &done);
vector<pair<string, uint16_t> > empty_vector;
RecursiveQuery rq(*dns_service_, empty_vector, 10000, 0);
Question q(Name("www.isc.org"), RRClass::IN(), RRType::A());
OutputBufferPtr buffer(new OutputBuffer(0));
MessagePtr answer(new Message(Message::RENDER));
rq.sendQuery(q, answer, buffer, &server);
io_service_->run();
// Check that the answer we got matches the one we wanted
EXPECT_EQ(Rcode::NOERROR(), answer->getRcode());
ASSERT_EQ(1, answer->getRRCount(Message::SECTION_ANSWER));
RRsetPtr a = *answer->beginSection(Message::SECTION_ANSWER);
EXPECT_EQ(q.getName(), a->getName());
EXPECT_EQ(q.getType(), a->getType());
EXPECT_EQ(q.getClass(), a->getClass());
EXPECT_EQ(1, a->getRdataCount());
}
// see comments at previous test
TEST_F(ASIOLinkTest, recursiveSendNXDOMAIN) {
setDNSService(true, false);
bool done;
MockServerStop server(*io_service_, &done);
vector<pair<string, uint16_t> > empty_vector;
RecursiveQuery rq(*dns_service_, empty_vector, 10000, 0);
Question q(Name("wwwdoesnotexist.isc.org"), RRClass::IN(), RRType::A());
OutputBufferPtr buffer(new OutputBuffer(0));
MessagePtr answer(new Message(Message::RENDER));
rq.sendQuery(q, answer, buffer, &server);
io_service_->run();
// Check that the answer we got matches the one we wanted
EXPECT_EQ(Rcode::NXDOMAIN(), answer->getRcode());
EXPECT_EQ(0, answer->getRRCount(Message::SECTION_ANSWER));
}
// This fixture is for testing IntervalTimer. Some callback functors are
// registered as callback function of the timer to test if they are called
// or not.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment