Commit 9c05f6fa authored by JINMEI Tatuya's avatar JINMEI Tatuya

added more tests for auth server:

- load and lookup a test data source
- lookup for a broken data source entry, and confirm it will result in
  SERVFAIL
- in the auth server code, only catch isc::Exceptions.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1374 e5f2f494-b856-4b98-b285-d166d9295462
parent 25dde25a
......@@ -217,8 +217,13 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
try {
Query query(message, dnssec_ok);
impl_->data_sources_.doQuery(query);
} catch(...) {
message.setRcode(Rcode::SERVFAIL());
} catch (const Exception& ex) {
if (verbose_mode) {
cerr << "Internal error, returning SERVFAIL: " << ex.what() << endl;
}
makeErrorMessage(message, response_renderer, Rcode::SERVFAIL(),
verbose_mode);
return (true);
}
response_renderer.setLengthLimit(udp_buffer ? remote_bufsize : 65535);
......
......@@ -23,6 +23,8 @@
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <cc/data.h>
#include <auth/auth_srv.h>
#include <dns/tests/unittest_util.h>
......@@ -30,8 +32,11 @@
using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
using namespace isc::data;
namespace {
const char* CONFIG_TESTDB = "{\"database_file\": \"testdata/example.sqlite3\"}";
class AuthSrvTest : public ::testing::Test {
protected:
AuthSrvTest() : request_message(Message::RENDER),
......@@ -89,13 +94,13 @@ headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
EXPECT_EQ(qid, message.getQid());
EXPECT_EQ(rcode, message.getRcode());
EXPECT_EQ(opcodeval, message.getOpcode().getCode());
EXPECT_EQ((flags & QR_FLAG) == 1, message.getHeaderFlag(MessageFlag::QR()));
EXPECT_EQ((flags & AA_FLAG) == 1, message.getHeaderFlag(MessageFlag::AA()));
EXPECT_EQ((flags & TC_FLAG) == 1, message.getHeaderFlag(MessageFlag::TC()));
EXPECT_EQ((flags & RA_FLAG) == 1, message.getHeaderFlag(MessageFlag::RA()));
EXPECT_EQ((flags & RD_FLAG) == 1, message.getHeaderFlag(MessageFlag::RD()));
EXPECT_EQ((flags & AD_FLAG) == 1, message.getHeaderFlag(MessageFlag::AD()));
EXPECT_EQ((flags & CD_FLAG) == 1, message.getHeaderFlag(MessageFlag::CD()));
EXPECT_EQ((flags & QR_FLAG) != 0, message.getHeaderFlag(MessageFlag::QR()));
EXPECT_EQ((flags & AA_FLAG) != 0, message.getHeaderFlag(MessageFlag::AA()));
EXPECT_EQ((flags & TC_FLAG) != 0, message.getHeaderFlag(MessageFlag::TC()));
EXPECT_EQ((flags & RA_FLAG) != 0, message.getHeaderFlag(MessageFlag::RA()));
EXPECT_EQ((flags & RD_FLAG) != 0, message.getHeaderFlag(MessageFlag::RD()));
EXPECT_EQ((flags & AD_FLAG) != 0, message.getHeaderFlag(MessageFlag::AD()));
EXPECT_EQ((flags & CD_FLAG) != 0, message.getHeaderFlag(MessageFlag::CD()));
EXPECT_EQ(qdcount, message.getRRCount(Section::QUESTION()));
EXPECT_EQ(ancount, message.getRRCount(Section::ANSWER()));
......@@ -212,4 +217,43 @@ TEST_F(AuthSrvTest, ednsBadVers) {
EXPECT_FALSE(parse_message.isDNSSECSupported());
}
void
updateConfig(AuthSrv* server, const char* const dbfile) {
const ElementPtr config_answer =
server->updateConfig(Element::createFromString(dbfile));
EXPECT_EQ(Element::map, config_answer->getType());
EXPECT_TRUE(config_answer->contains("result"));
const ElementPtr result = config_answer->get("result");
EXPECT_EQ(Element::list, result->getType());
EXPECT_EQ(0, result->get(0)->intValue());
}
// Install a Sqlite3 data source with testing data.
TEST_F(AuthSrvTest, updateConfig) {
updateConfig(&server, CONFIG_TESTDB);
// query for existent data in the installed data source. The resulting
// response should have the AA flag on, and have an RR in each answer
// and authority section.
createDataFromFile("testdata/examplequery_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
headerCheck(parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
QR_FLAG | AA_FLAG, 1, 1, 1, 0);
}
TEST_F(AuthSrvTest, datasourceFail) {
updateConfig(&server, CONFIG_TESTDB);
// This query will hit a corrupted entry of the data source (the zoneload
// tool and the data source itself naively accept it). This will result
// in a SERVFAIL response, and the answer and authority sections should
// be empty.
createDataFromFile("testdata/badExampleQuery_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
headerCheck(parse_message, default_qid, Rcode::SERVFAIL(), opcode.getCode(),
QR_FLAG, 1, 0, 0, 0);
}
}
###
### This data file was auto-generated from badExampleQuery_fromWire.spec
###
# Header Section
# ID=4149 QR=Query Opcode=QUERY(0) Rcode=NOERROR(0)
1035 0000
# QDCNT=1, ANCNT=0, NSCNT=0, ARCNT=0
0001 0000 0000 0000
# Question Section
# QNAME=broken.example.com QTYPE=AAAA(28) QCLASS=IN(1)
0662726f6b656e076578616d706c6503636f6d00 001c 0001
#
# A simple QUERY message for the example.com zone that would hit a broken
# record of the data source.
#
[header]
# use default
[question]
name: broken.example.com
rrtype: AAAA
$TTL 3600
@ SOA ns.example.com. admin.example.com. 1234 3600 1800 2419200 7200
NS ns.example.com.
ns.example.com. A 192.0.2.1
;; bogus RDATA for CNAME RR, but the loadzone tool accepts it. looking up this
;; record will trigger an exception.
broken.example.com. CNAME 0123456789012345678901234567890123456789012345678901234567890123456789.example.com.
###
### This data file was auto-generated from examplequery_fromWire.spec
###
# Header Section
# ID=4149 QR=Query Opcode=QUERY(0) Rcode=NOERROR(0)
1035 0000
# QDCNT=1, ANCNT=0, NSCNT=0, ARCNT=0
0001 0000 0000 0000
# Question Section
# QNAME=ns.example.com QTYPE=A(1) QCLASS=IN(1)
026e73076578616d706c6503636f6d00 0001 0001
#
# A simple QUERY message for the example.com zone
#
[header]
# use default
[question]
# use default
name: ns.example.com
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