database_unittest.cc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <gtest/gtest.h>
  15. #include <dns/name.h>
  16. #include <dns/rrttl.h>
  17. #include <dns/rrset.h>
  18. #include <exceptions/exceptions.h>
  19. #include <datasrc/database.h>
  20. #include <datasrc/zone.h>
  21. #include <datasrc/data_source.h>
  22. #include <testutils/dnsmessage_test.h>
  23. #include <map>
  24. using namespace isc::datasrc;
  25. using namespace std;
  26. using namespace boost;
  27. using isc::dns::Name;
  28. namespace {
  29. /*
  30. * A virtual database database that pretends it contains single zone --
  31. * example.org.
  32. */
  33. class MockAccessor : public DatabaseAccessor {
  34. public:
  35. MockAccessor() : search_running_(false),
  36. database_name_("mock_database")
  37. {
  38. fillData();
  39. }
  40. virtual std::pair<bool, int> getZone(const Name& name) const {
  41. if (name == Name("example.org")) {
  42. return (std::pair<bool, int>(true, 42));
  43. } else {
  44. return (std::pair<bool, int>(false, 0));
  45. }
  46. }
  47. virtual void searchForRecords(int zone_id, const std::string& name) {
  48. search_running_ = true;
  49. // 'hardcoded' name to trigger exceptions (for testing
  50. // the error handling of find() (the other on is below in
  51. // if the name is "exceptiononsearch" it'll raise an exception here
  52. if (name == "dsexception.in.search.") {
  53. isc_throw(DataSourceError, "datasource exception on search");
  54. } else if (name == "iscexception.in.search.") {
  55. isc_throw(isc::Exception, "isc exception on search");
  56. } else if (name == "basicexception.in.search.") {
  57. throw std::exception();
  58. }
  59. searched_name_ = name;
  60. // we're not aiming for efficiency in this test, simply
  61. // copy the relevant vector from records
  62. cur_record = 0;
  63. if (zone_id == 42) {
  64. if (records.count(name) > 0) {
  65. cur_name = records.find(name)->second;
  66. } else {
  67. cur_name.clear();
  68. }
  69. } else {
  70. cur_name.clear();
  71. }
  72. };
  73. virtual bool getNextRecord(std::string columns[], size_t column_count) {
  74. if (searched_name_ == "dsexception.in.getnext.") {
  75. isc_throw(DataSourceError, "datasource exception on getnextrecord");
  76. } else if (searched_name_ == "iscexception.in.getnext.") {
  77. isc_throw(isc::Exception, "isc exception on getnextrecord");
  78. } else if (searched_name_ == "basicexception.in.getnext.") {
  79. throw std::exception();
  80. }
  81. if (column_count != DatabaseAccessor::COLUMN_COUNT) {
  82. isc_throw(DataSourceError, "Wrong column count in getNextRecord");
  83. }
  84. if (cur_record < cur_name.size()) {
  85. for (size_t i = 0; i < column_count; ++i) {
  86. columns[i] = cur_name[cur_record][i];
  87. }
  88. cur_record++;
  89. return (true);
  90. } else {
  91. resetSearch();
  92. return (false);
  93. }
  94. };
  95. virtual void resetSearch() {
  96. search_running_ = false;
  97. };
  98. bool searchRunning() const {
  99. return (search_running_);
  100. }
  101. virtual const std::string& getDBName() const {
  102. return (database_name_);
  103. }
  104. private:
  105. std::map<std::string, std::vector< std::vector<std::string> > > records;
  106. // used as internal index for getNextRecord()
  107. size_t cur_record;
  108. // used as temporary storage after searchForRecord() and during
  109. // getNextRecord() calls, as well as during the building of the
  110. // fake data
  111. std::vector< std::vector<std::string> > cur_name;
  112. // This boolean is used to make sure find() calls resetSearch
  113. // when it encounters an error
  114. bool search_running_;
  115. // We store the name passed to searchForRecords, so we can
  116. // hardcode some exceptions into getNextRecord
  117. std::string searched_name_;
  118. const std::string database_name_;
  119. // Adds one record to the current name in the database
  120. // The actual data will not be added to 'records' until
  121. // addCurName() is called
  122. void addRecord(const std::string& name,
  123. const std::string& type,
  124. const std::string& sigtype,
  125. const std::string& rdata) {
  126. std::vector<std::string> columns;
  127. columns.push_back(name);
  128. columns.push_back(type);
  129. columns.push_back(sigtype);
  130. columns.push_back(rdata);
  131. cur_name.push_back(columns);
  132. }
  133. // Adds all records we just built with calls to addRecords
  134. // to the actual fake database. This will clear cur_name,
  135. // so we can immediately start adding new records.
  136. void addCurName(const std::string& name) {
  137. ASSERT_EQ(0, records.count(name));
  138. records[name] = cur_name;
  139. cur_name.clear();
  140. }
  141. // Fills the database with zone data.
  142. // This method constructs a number of resource records (with addRecord),
  143. // which will all be added for one domain name to the fake database
  144. // (with addCurName). So for instance the first set of calls create
  145. // data for the name 'www.example.org', which will consist of one A RRset
  146. // of one record, and one AAAA RRset of two records.
  147. // The order in which they are added is the order in which getNextRecord()
  148. // will return them (so we can test whether find() etc. support data that
  149. // might not come in 'normal' order)
  150. // It shall immediately fail if you try to add the same name twice.
  151. void fillData() {
  152. // some plain data
  153. addRecord("A", "3600", "", "192.0.2.1");
  154. addRecord("AAAA", "3600", "", "2001:db8::1");
  155. addRecord("AAAA", "3600", "", "2001:db8::2");
  156. addCurName("www.example.org.");
  157. addRecord("A", "3600", "", "192.0.2.1");
  158. addRecord("AAAA", "3600", "", "2001:db8::1");
  159. addRecord("A", "3600", "", "192.0.2.2");
  160. addCurName("www2.example.org.");
  161. addRecord("CNAME", "3600", "", "www.example.org.");
  162. addCurName("cname.example.org.");
  163. // some DNSSEC-'signed' data
  164. addRecord("A", "3600", "", "192.0.2.1");
  165. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  166. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  167. addRecord("AAAA", "3600", "", "2001:db8::1");
  168. addRecord("AAAA", "3600", "", "2001:db8::2");
  169. addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  170. addCurName("signed1.example.org.");
  171. addRecord("CNAME", "3600", "", "www.example.org.");
  172. addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  173. addCurName("signedcname1.example.org.");
  174. // special case might fail; sig is for cname, which isn't there (should be ignored)
  175. // (ignoring of 'normal' other type is done above by www.)
  176. addRecord("A", "3600", "", "192.0.2.1");
  177. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  178. addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  179. addCurName("acnamesig1.example.org.");
  180. // let's pretend we have a database that is not careful
  181. // about the order in which it returns data
  182. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  183. addRecord("AAAA", "3600", "", "2001:db8::2");
  184. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  185. addRecord("A", "3600", "", "192.0.2.1");
  186. addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  187. addRecord("AAAA", "3600", "", "2001:db8::1");
  188. addCurName("signed2.example.org.");
  189. addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  190. addRecord("CNAME", "3600", "", "www.example.org.");
  191. addCurName("signedcname2.example.org.");
  192. addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  193. addRecord("A", "3600", "", "192.0.2.1");
  194. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  195. addCurName("acnamesig2.example.org.");
  196. addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  197. addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  198. addRecord("A", "3600", "", "192.0.2.1");
  199. addCurName("acnamesig3.example.org.");
  200. addRecord("A", "3600", "", "192.0.2.1");
  201. addRecord("A", "360", "", "192.0.2.2");
  202. addCurName("ttldiff1.example.org.");
  203. addRecord("A", "360", "", "192.0.2.1");
  204. addRecord("A", "3600", "", "192.0.2.2");
  205. addCurName("ttldiff2.example.org.");
  206. // also add some intentionally bad data
  207. addRecord("A", "3600", "", "192.0.2.1");
  208. addRecord("CNAME", "3600", "", "www.example.org.");
  209. addCurName("badcname1.example.org.");
  210. addRecord("CNAME", "3600", "", "www.example.org.");
  211. addRecord("A", "3600", "", "192.0.2.1");
  212. addCurName("badcname2.example.org.");
  213. addRecord("CNAME", "3600", "", "www.example.org.");
  214. addRecord("CNAME", "3600", "", "www.example2.org.");
  215. addCurName("badcname3.example.org.");
  216. addRecord("A", "3600", "", "bad");
  217. addCurName("badrdata.example.org.");
  218. addRecord("BAD_TYPE", "3600", "", "192.0.2.1");
  219. addCurName("badtype.example.org.");
  220. addRecord("A", "badttl", "", "192.0.2.1");
  221. addCurName("badttl.example.org.");
  222. addRecord("A", "badttl", "", "192.0.2.1");
  223. addRecord("RRSIG", "3600", "", "A 5 3 3600 somebaddata 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  224. addCurName("badsig.example.org.");
  225. addRecord("A", "3600", "", "192.0.2.1");
  226. addRecord("RRSIG", "3600", "TXT", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  227. addCurName("badsigtype.example.org.");
  228. // Data for testing delegation (with NS and DNAME)
  229. addRecord("A", "3600", "", "192.0.2.1");
  230. addRecord("NS", "3600", "", "ns.example.com.");
  231. addRecord("NS", "3600", "", "ns.delegation.example.org.");
  232. addCurName("delegation.example.org.");
  233. addRecord("A", "3600", "", "192.0.2.1");
  234. addCurName("ns.delegation.example.org.");
  235. addRecord("A", "3600", "", "192.0.2.1");
  236. addRecord("DNAME", "3600", "", "dname.example.com.");
  237. addCurName("dname.example.org.");
  238. addRecord("A", "3600", "", "192.0.2.1");
  239. addCurName("below.dname.example.org.");
  240. // Now double DNAME, to test failure mode
  241. addRecord("DNAME", "3600", "", "dname1.example.com.");
  242. addRecord("DNAME", "3600", "", "dname2.example.com.");
  243. addCurName("baddname.example.org.");
  244. }
  245. };
  246. class DatabaseClientTest : public ::testing::Test {
  247. public:
  248. DatabaseClientTest() {
  249. createClient();
  250. }
  251. /*
  252. * We initialize the client from a function, so we can call it multiple
  253. * times per test.
  254. */
  255. void createClient() {
  256. current_database_ = new MockAccessor();
  257. client_.reset(new DatabaseClient(shared_ptr<DatabaseAccessor>(
  258. current_database_)));
  259. }
  260. // Will be deleted by client_, just keep the current value for comparison.
  261. MockAccessor* current_database_;
  262. shared_ptr<DatabaseClient> client_;
  263. const std::string database_name_;
  264. /**
  265. * Check the zone finder is a valid one and references the zone ID and
  266. * database available here.
  267. */
  268. void checkZoneFinder(const DataSourceClient::FindResult& zone) {
  269. ASSERT_NE(ZoneFinderPtr(), zone.zone_finder) << "No zone finder";
  270. shared_ptr<DatabaseClient::Finder> finder(
  271. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  272. ASSERT_NE(shared_ptr<DatabaseClient::Finder>(), finder) <<
  273. "Wrong type of finder";
  274. EXPECT_EQ(42, finder->zone_id());
  275. EXPECT_EQ(current_database_, &finder->database());
  276. }
  277. };
  278. TEST_F(DatabaseClientTest, zoneNotFound) {
  279. DataSourceClient::FindResult zone(client_->findZone(Name("example.com")));
  280. EXPECT_EQ(result::NOTFOUND, zone.code);
  281. }
  282. TEST_F(DatabaseClientTest, exactZone) {
  283. DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
  284. EXPECT_EQ(result::SUCCESS, zone.code);
  285. checkZoneFinder(zone);
  286. }
  287. TEST_F(DatabaseClientTest, superZone) {
  288. DataSourceClient::FindResult zone(client_->findZone(Name(
  289. "sub.example.org")));
  290. EXPECT_EQ(result::PARTIALMATCH, zone.code);
  291. checkZoneFinder(zone);
  292. }
  293. TEST_F(DatabaseClientTest, noAccessorException) {
  294. EXPECT_THROW(DatabaseClient(shared_ptr<DatabaseAccessor>()),
  295. isc::InvalidParameter);
  296. }
  297. namespace {
  298. // checks if the given rrset matches the
  299. // given name, class, type and rdatas
  300. void
  301. checkRRset(isc::dns::ConstRRsetPtr rrset,
  302. const isc::dns::Name& name,
  303. const isc::dns::RRClass& rrclass,
  304. const isc::dns::RRType& rrtype,
  305. const isc::dns::RRTTL& rrttl,
  306. const std::vector<std::string>& rdatas) {
  307. isc::dns::RRsetPtr expected_rrset(
  308. new isc::dns::RRset(name, rrclass, rrtype, rrttl));
  309. for (unsigned int i = 0; i < rdatas.size(); ++i) {
  310. expected_rrset->addRdata(
  311. isc::dns::rdata::createRdata(rrtype, rrclass,
  312. rdatas[i]));
  313. }
  314. isc::testutils::rrsetCheck(expected_rrset, rrset);
  315. }
  316. void
  317. doFindTest(shared_ptr<DatabaseClient::Finder> finder,
  318. const isc::dns::Name& name,
  319. const isc::dns::RRType& type,
  320. const isc::dns::RRType& expected_type,
  321. const isc::dns::RRTTL expected_ttl,
  322. ZoneFinder::Result expected_result,
  323. const std::vector<std::string>& expected_rdatas,
  324. const std::vector<std::string>& expected_sig_rdatas,
  325. const isc::dns::Name& expected_name = isc::dns::Name::ROOT_NAME())
  326. {
  327. SCOPED_TRACE("doFindTest " + name.toText() + " " + type.toText());
  328. ZoneFinder::FindResult result =
  329. finder->find(name, type, NULL, ZoneFinder::FIND_DEFAULT);
  330. ASSERT_EQ(expected_result, result.code) << name << " " << type;
  331. if (expected_rdatas.size() > 0) {
  332. checkRRset(result.rrset, expected_name != Name(".") ? expected_name :
  333. name, finder->getClass(), expected_type, expected_ttl,
  334. expected_rdatas);
  335. if (expected_sig_rdatas.size() > 0) {
  336. checkRRset(result.rrset->getRRsig(), name,
  337. finder->getClass(), isc::dns::RRType::RRSIG(),
  338. expected_ttl, expected_sig_rdatas);
  339. } else {
  340. EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset->getRRsig());
  341. }
  342. } else {
  343. EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset);
  344. }
  345. }
  346. } // end anonymous namespace
  347. TEST_F(DatabaseClientTest, find) {
  348. DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
  349. ASSERT_EQ(result::SUCCESS, zone.code);
  350. shared_ptr<DatabaseClient::Finder> finder(
  351. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  352. EXPECT_EQ(42, finder->zone_id());
  353. EXPECT_FALSE(current_database_->searchRunning());
  354. std::vector<std::string> expected_rdatas;
  355. std::vector<std::string> expected_sig_rdatas;
  356. expected_rdatas.clear();
  357. expected_sig_rdatas.clear();
  358. expected_rdatas.push_back("192.0.2.1");
  359. doFindTest(finder, isc::dns::Name("www.example.org."),
  360. isc::dns::RRType::A(), isc::dns::RRType::A(),
  361. isc::dns::RRTTL(3600),
  362. ZoneFinder::SUCCESS,
  363. expected_rdatas, expected_sig_rdatas);
  364. EXPECT_FALSE(current_database_->searchRunning());
  365. expected_rdatas.clear();
  366. expected_sig_rdatas.clear();
  367. expected_rdatas.push_back("192.0.2.1");
  368. expected_rdatas.push_back("192.0.2.2");
  369. doFindTest(finder, isc::dns::Name("www2.example.org."),
  370. isc::dns::RRType::A(), isc::dns::RRType::A(),
  371. isc::dns::RRTTL(3600),
  372. ZoneFinder::SUCCESS,
  373. expected_rdatas, expected_sig_rdatas);
  374. EXPECT_FALSE(current_database_->searchRunning());
  375. expected_rdatas.clear();
  376. expected_sig_rdatas.clear();
  377. expected_rdatas.push_back("2001:db8::1");
  378. expected_rdatas.push_back("2001:db8::2");
  379. doFindTest(finder, isc::dns::Name("www.example.org."),
  380. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  381. isc::dns::RRTTL(3600),
  382. ZoneFinder::SUCCESS,
  383. expected_rdatas, expected_sig_rdatas);
  384. EXPECT_FALSE(current_database_->searchRunning());
  385. expected_rdatas.clear();
  386. expected_sig_rdatas.clear();
  387. doFindTest(finder, isc::dns::Name("www.example.org."),
  388. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
  389. isc::dns::RRTTL(3600),
  390. ZoneFinder::NXRRSET,
  391. expected_rdatas, expected_sig_rdatas);
  392. EXPECT_FALSE(current_database_->searchRunning());
  393. expected_rdatas.clear();
  394. expected_sig_rdatas.clear();
  395. expected_rdatas.push_back("www.example.org.");
  396. doFindTest(finder, isc::dns::Name("cname.example.org."),
  397. isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
  398. isc::dns::RRTTL(3600),
  399. ZoneFinder::CNAME,
  400. expected_rdatas, expected_sig_rdatas);
  401. EXPECT_FALSE(current_database_->searchRunning());
  402. expected_rdatas.clear();
  403. expected_sig_rdatas.clear();
  404. expected_rdatas.push_back("www.example.org.");
  405. doFindTest(finder, isc::dns::Name("cname.example.org."),
  406. isc::dns::RRType::CNAME(), isc::dns::RRType::CNAME(),
  407. isc::dns::RRTTL(3600),
  408. ZoneFinder::SUCCESS,
  409. expected_rdatas, expected_sig_rdatas);
  410. EXPECT_FALSE(current_database_->searchRunning());
  411. expected_rdatas.clear();
  412. expected_sig_rdatas.clear();
  413. doFindTest(finder, isc::dns::Name("doesnotexist.example.org."),
  414. isc::dns::RRType::A(), isc::dns::RRType::A(),
  415. isc::dns::RRTTL(3600),
  416. ZoneFinder::NXDOMAIN,
  417. expected_rdatas, expected_sig_rdatas);
  418. EXPECT_FALSE(current_database_->searchRunning());
  419. expected_rdatas.clear();
  420. expected_sig_rdatas.clear();
  421. expected_rdatas.push_back("192.0.2.1");
  422. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  423. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  424. doFindTest(finder, isc::dns::Name("signed1.example.org."),
  425. isc::dns::RRType::A(), isc::dns::RRType::A(),
  426. isc::dns::RRTTL(3600),
  427. ZoneFinder::SUCCESS,
  428. expected_rdatas, expected_sig_rdatas);
  429. EXPECT_FALSE(current_database_->searchRunning());
  430. expected_rdatas.clear();
  431. expected_sig_rdatas.clear();
  432. expected_rdatas.push_back("2001:db8::1");
  433. expected_rdatas.push_back("2001:db8::2");
  434. expected_sig_rdatas.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  435. doFindTest(finder, isc::dns::Name("signed1.example.org."),
  436. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  437. isc::dns::RRTTL(3600),
  438. ZoneFinder::SUCCESS,
  439. expected_rdatas, expected_sig_rdatas);
  440. EXPECT_FALSE(current_database_->searchRunning());
  441. expected_rdatas.clear();
  442. expected_sig_rdatas.clear();
  443. doFindTest(finder, isc::dns::Name("signed1.example.org."),
  444. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
  445. isc::dns::RRTTL(3600),
  446. ZoneFinder::NXRRSET,
  447. expected_rdatas, expected_sig_rdatas);
  448. EXPECT_FALSE(current_database_->searchRunning());
  449. expected_rdatas.clear();
  450. expected_sig_rdatas.clear();
  451. expected_rdatas.push_back("www.example.org.");
  452. expected_sig_rdatas.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  453. doFindTest(finder, isc::dns::Name("signedcname1.example.org."),
  454. isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
  455. isc::dns::RRTTL(3600),
  456. ZoneFinder::CNAME,
  457. expected_rdatas, expected_sig_rdatas);
  458. EXPECT_FALSE(current_database_->searchRunning());
  459. expected_rdatas.clear();
  460. expected_sig_rdatas.clear();
  461. expected_rdatas.push_back("192.0.2.1");
  462. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  463. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  464. doFindTest(finder, isc::dns::Name("signed2.example.org."),
  465. isc::dns::RRType::A(), isc::dns::RRType::A(),
  466. isc::dns::RRTTL(3600),
  467. ZoneFinder::SUCCESS,
  468. expected_rdatas, expected_sig_rdatas);
  469. EXPECT_FALSE(current_database_->searchRunning());
  470. expected_rdatas.clear();
  471. expected_sig_rdatas.clear();
  472. expected_rdatas.push_back("2001:db8::2");
  473. expected_rdatas.push_back("2001:db8::1");
  474. expected_sig_rdatas.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  475. doFindTest(finder, isc::dns::Name("signed2.example.org."),
  476. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  477. isc::dns::RRTTL(3600),
  478. ZoneFinder::SUCCESS,
  479. expected_rdatas, expected_sig_rdatas);
  480. EXPECT_FALSE(current_database_->searchRunning());
  481. expected_rdatas.clear();
  482. expected_sig_rdatas.clear();
  483. doFindTest(finder, isc::dns::Name("signed2.example.org."),
  484. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
  485. isc::dns::RRTTL(3600),
  486. ZoneFinder::NXRRSET,
  487. expected_rdatas, expected_sig_rdatas);
  488. EXPECT_FALSE(current_database_->searchRunning());
  489. expected_rdatas.clear();
  490. expected_sig_rdatas.clear();
  491. expected_rdatas.push_back("www.example.org.");
  492. expected_sig_rdatas.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  493. doFindTest(finder, isc::dns::Name("signedcname2.example.org."),
  494. isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
  495. isc::dns::RRTTL(3600),
  496. ZoneFinder::CNAME,
  497. expected_rdatas, expected_sig_rdatas);
  498. EXPECT_FALSE(current_database_->searchRunning());
  499. expected_rdatas.clear();
  500. expected_sig_rdatas.clear();
  501. expected_rdatas.push_back("192.0.2.1");
  502. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  503. doFindTest(finder, isc::dns::Name("acnamesig1.example.org."),
  504. isc::dns::RRType::A(), isc::dns::RRType::A(),
  505. isc::dns::RRTTL(3600),
  506. ZoneFinder::SUCCESS,
  507. expected_rdatas, expected_sig_rdatas);
  508. EXPECT_FALSE(current_database_->searchRunning());
  509. expected_rdatas.clear();
  510. expected_sig_rdatas.clear();
  511. expected_rdatas.push_back("192.0.2.1");
  512. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  513. doFindTest(finder, isc::dns::Name("acnamesig2.example.org."),
  514. isc::dns::RRType::A(), isc::dns::RRType::A(),
  515. isc::dns::RRTTL(3600),
  516. ZoneFinder::SUCCESS,
  517. expected_rdatas, expected_sig_rdatas);
  518. EXPECT_FALSE(current_database_->searchRunning());
  519. expected_rdatas.clear();
  520. expected_sig_rdatas.clear();
  521. expected_rdatas.push_back("192.0.2.1");
  522. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  523. doFindTest(finder, isc::dns::Name("acnamesig3.example.org."),
  524. isc::dns::RRType::A(), isc::dns::RRType::A(),
  525. isc::dns::RRTTL(3600),
  526. ZoneFinder::SUCCESS,
  527. expected_rdatas, expected_sig_rdatas);
  528. EXPECT_FALSE(current_database_->searchRunning());
  529. expected_rdatas.clear();
  530. expected_sig_rdatas.clear();
  531. expected_rdatas.push_back("192.0.2.1");
  532. expected_rdatas.push_back("192.0.2.2");
  533. doFindTest(finder, isc::dns::Name("ttldiff1.example.org."),
  534. isc::dns::RRType::A(), isc::dns::RRType::A(),
  535. isc::dns::RRTTL(360),
  536. ZoneFinder::SUCCESS,
  537. expected_rdatas, expected_sig_rdatas);
  538. EXPECT_FALSE(current_database_->searchRunning());
  539. expected_rdatas.clear();
  540. expected_sig_rdatas.clear();
  541. expected_rdatas.push_back("192.0.2.1");
  542. expected_rdatas.push_back("192.0.2.2");
  543. doFindTest(finder, isc::dns::Name("ttldiff2.example.org."),
  544. isc::dns::RRType::A(), isc::dns::RRType::A(),
  545. isc::dns::RRTTL(360),
  546. ZoneFinder::SUCCESS,
  547. expected_rdatas, expected_sig_rdatas);
  548. EXPECT_FALSE(current_database_->searchRunning());
  549. EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
  550. isc::dns::RRType::A(),
  551. NULL, ZoneFinder::FIND_DEFAULT),
  552. DataSourceError);
  553. EXPECT_FALSE(current_database_->searchRunning());
  554. EXPECT_THROW(finder->find(isc::dns::Name("badcname2.example.org."),
  555. isc::dns::RRType::A(),
  556. NULL, ZoneFinder::FIND_DEFAULT),
  557. DataSourceError);
  558. EXPECT_FALSE(current_database_->searchRunning());
  559. EXPECT_THROW(finder->find(isc::dns::Name("badcname3.example.org."),
  560. isc::dns::RRType::A(),
  561. NULL, ZoneFinder::FIND_DEFAULT),
  562. DataSourceError);
  563. EXPECT_FALSE(current_database_->searchRunning());
  564. EXPECT_THROW(finder->find(isc::dns::Name("badrdata.example.org."),
  565. isc::dns::RRType::A(),
  566. NULL, ZoneFinder::FIND_DEFAULT),
  567. DataSourceError);
  568. EXPECT_FALSE(current_database_->searchRunning());
  569. EXPECT_THROW(finder->find(isc::dns::Name("badtype.example.org."),
  570. isc::dns::RRType::A(),
  571. NULL, ZoneFinder::FIND_DEFAULT),
  572. DataSourceError);
  573. EXPECT_FALSE(current_database_->searchRunning());
  574. EXPECT_THROW(finder->find(isc::dns::Name("badttl.example.org."),
  575. isc::dns::RRType::A(),
  576. NULL, ZoneFinder::FIND_DEFAULT),
  577. DataSourceError);
  578. EXPECT_FALSE(current_database_->searchRunning());
  579. EXPECT_THROW(finder->find(isc::dns::Name("badsig.example.org."),
  580. isc::dns::RRType::A(),
  581. NULL, ZoneFinder::FIND_DEFAULT),
  582. DataSourceError);
  583. EXPECT_FALSE(current_database_->searchRunning());
  584. // Trigger the hardcoded exceptions and see if find() has cleaned up
  585. EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.search."),
  586. isc::dns::RRType::A(),
  587. NULL, ZoneFinder::FIND_DEFAULT),
  588. DataSourceError);
  589. EXPECT_FALSE(current_database_->searchRunning());
  590. EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.search."),
  591. isc::dns::RRType::A(),
  592. NULL, ZoneFinder::FIND_DEFAULT),
  593. DataSourceError);
  594. EXPECT_FALSE(current_database_->searchRunning());
  595. EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.search."),
  596. isc::dns::RRType::A(),
  597. NULL, ZoneFinder::FIND_DEFAULT),
  598. std::exception);
  599. EXPECT_FALSE(current_database_->searchRunning());
  600. EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.getnext."),
  601. isc::dns::RRType::A(),
  602. NULL, ZoneFinder::FIND_DEFAULT),
  603. DataSourceError);
  604. EXPECT_FALSE(current_database_->searchRunning());
  605. EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.getnext."),
  606. isc::dns::RRType::A(),
  607. NULL, ZoneFinder::FIND_DEFAULT),
  608. DataSourceError);
  609. EXPECT_FALSE(current_database_->searchRunning());
  610. EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.getnext."),
  611. isc::dns::RRType::A(),
  612. NULL, ZoneFinder::FIND_DEFAULT),
  613. std::exception);
  614. EXPECT_FALSE(current_database_->searchRunning());
  615. // This RRSIG has the wrong sigtype field, which should be
  616. // an error if we decide to keep using that field
  617. // Right now the field is ignored, so it does not error
  618. expected_rdatas.clear();
  619. expected_sig_rdatas.clear();
  620. expected_rdatas.push_back("192.0.2.1");
  621. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  622. doFindTest(finder, isc::dns::Name("badsigtype.example.org."),
  623. isc::dns::RRType::A(), isc::dns::RRType::A(),
  624. isc::dns::RRTTL(3600),
  625. ZoneFinder::SUCCESS,
  626. expected_rdatas, expected_sig_rdatas);
  627. EXPECT_FALSE(current_database_->searchRunning());
  628. // Check when we ask for something below delegation point, we get the NS
  629. // (Both when the RRset there exists and doesn't)
  630. expected_rdatas.clear();
  631. expected_sig_rdatas.clear();
  632. expected_rdatas.push_back("ns.example.com.");
  633. expected_rdatas.push_back("ns.delegation.example.org.");
  634. doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
  635. isc::dns::RRType::A(), isc::dns::RRType::NS(),
  636. isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas,
  637. expected_sig_rdatas, isc::dns::Name("delegation.example.org."));
  638. EXPECT_FALSE(current_database_->searchRunning());
  639. doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
  640. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  641. isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas,
  642. expected_sig_rdatas, isc::dns::Name("delegation.example.org."));
  643. EXPECT_FALSE(current_database_->searchRunning());
  644. // Even when we check directly at the delegation point, we should get
  645. // the NS (both when the RRset does and doesn't exist in data)
  646. doFindTest(finder, isc::dns::Name("delegation.example.org."),
  647. isc::dns::RRType::A(), isc::dns::RRType::NS(),
  648. isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas,
  649. expected_sig_rdatas);
  650. EXPECT_FALSE(current_database_->searchRunning());
  651. doFindTest(finder, isc::dns::Name("delegation.example.org."),
  652. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  653. isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas,
  654. expected_sig_rdatas);
  655. EXPECT_FALSE(current_database_->searchRunning());
  656. // Now test delegation. If it is below the delegation point, we should get
  657. // the DNAME (the one with data under DNAME is invalid zone, but we test
  658. // the behaviour anyway just to make sure)
  659. expected_rdatas.clear();
  660. expected_rdatas.push_back("dname.example.com.");
  661. doFindTest(finder, isc::dns::Name("below.dname.example.org."),
  662. isc::dns::RRType::A(), isc::dns::RRType::DNAME(),
  663. isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas,
  664. expected_sig_rdatas, isc::dns::Name("dname.example.org."));
  665. EXPECT_FALSE(current_database_->searchRunning());
  666. doFindTest(finder, isc::dns::Name("below.dname.example.org."),
  667. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  668. isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas,
  669. expected_sig_rdatas, isc::dns::Name("dname.example.org."));
  670. EXPECT_FALSE(current_database_->searchRunning());
  671. // But we don't delegate at DNAME point
  672. expected_rdatas.clear();
  673. expected_rdatas.push_back("192.0.2.1");
  674. doFindTest(finder, isc::dns::Name("dname.example.org."),
  675. isc::dns::RRType::A(), isc::dns::RRType::A(),
  676. isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas,
  677. expected_sig_rdatas);
  678. EXPECT_FALSE(current_database_->searchRunning());
  679. expected_rdatas.clear();
  680. doFindTest(finder, isc::dns::Name("dname.example.org."),
  681. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  682. isc::dns::RRTTL(3600), ZoneFinder::NXRRSET, expected_rdatas,
  683. expected_sig_rdatas);
  684. EXPECT_FALSE(current_database_->searchRunning());
  685. // This is broken dname, it contains two targets
  686. EXPECT_THROW(finder->find(isc::dns::Name("below.baddname.example.org."),
  687. isc::dns::RRType::A(), NULL,
  688. ZoneFinder::FIND_DEFAULT),
  689. DataSourceError);
  690. }
  691. }