sqlite3_unittest.cc 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. // Copyright (C) 2010 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 <stdint.h>
  15. #include <algorithm>
  16. #include <string>
  17. #include <vector>
  18. #include <sqlite3.h>
  19. #include <gtest/gtest.h>
  20. #include <dns/name.h>
  21. #include <dns/message.h>
  22. #include <dns/rdata.h>
  23. #include <dns/rrclass.h>
  24. #include <dns/rrtype.h>
  25. #include <dns/rdataclass.h>
  26. #include <dns/rrsetlist.h>
  27. #include <cc/data.h>
  28. #include <datasrc/query.h>
  29. #include <datasrc/data_source.h>
  30. #include <datasrc/sqlite3_datasrc.h>
  31. using namespace std;
  32. using namespace isc::dns;
  33. using namespace isc::dns::rdata;
  34. using namespace isc::datasrc;
  35. using namespace isc::data;
  36. namespace {
  37. ConstElementPtr SQLITE_DBFILE_EXAMPLE = Element::fromJSON(
  38. "{ \"database_file\": \"" TEST_DATA_DIR "/test.sqlite3\"}");
  39. ConstElementPtr SQLITE_DBFILE_EXAMPLE2 = Element::fromJSON(
  40. "{ \"database_file\": \"" TEST_DATA_DIR "/example2.com.sqlite3\"}");
  41. ConstElementPtr SQLITE_DBFILE_EXAMPLE_ROOT = Element::fromJSON(
  42. "{ \"database_file\": \"" TEST_DATA_DIR "/test-root.sqlite3\"}");
  43. ConstElementPtr SQLITE_DBFILE_BROKENDB = Element::fromJSON(
  44. "{ \"database_file\": \"" TEST_DATA_DIR "/brokendb.sqlite3\"}");
  45. ConstElementPtr SQLITE_DBFILE_MEMORY = Element::fromJSON(
  46. "{ \"database_file\": \":memory:\"}");
  47. ConstElementPtr SQLITE_DBFILE_NEWSCHEMA = Element::fromJSON(
  48. "{ \"database_file\": \"" TEST_DATA_DIR "/newschema.sqlite3\"}");
  49. ConstElementPtr SQLITE_DBFILE_OLDSCHEMA = Element::fromJSON(
  50. "{ \"database_file\": \"" TEST_DATA_DIR "/oldschema.sqlite3\"}");
  51. // The following file must be non existent and must be non"creatable";
  52. // the sqlite3 library will try to create a new DB file if it doesn't exist,
  53. // so to test a failure case the create operation should also fail.
  54. // The "nodir", a non existent directory, is inserted for this purpose.
  55. ConstElementPtr SQLITE_DBFILE_NOTEXIST = Element::fromJSON(
  56. "{ \"database_file\": \"" TEST_DATA_DIR "/nodir/notexist\"}");
  57. const string sigdata_common(" 20100322084538 20100220084538 "
  58. "33495 example.com. FAKEFAKEFAKEFAKE");
  59. const string dnskey1_data(" AwEAAcOUBllYc1hf7ND9uDy+Yz1BF3sI0m4q"
  60. "NGV7WcTD0WEiuV7IjXgHE36fCmS9QsUxSSOV"
  61. "o1I/FMxI2PJVqTYHkXFBS7AzLGsQYMU7UjBZ"
  62. "SotBJ6Imt5pXMu+lEDNy8TOUzG3xm7g0qcbW"
  63. "YF6qCEfvZoBtAqi5Rk7Mlrqs8agxYyMx");
  64. const string dnskey2_data(" AwEAAe5WFbxdCPq2jZrZhlMj7oJdff3W7syJ"
  65. "tbvzg62tRx0gkoCDoBI9DPjlOQG0UAbj+xUV"
  66. "4HQZJStJaZ+fHU5AwVNT+bBZdtV+NujSikhd"
  67. "THb4FYLg2b3Cx9NyJvAVukHp/91HnWuG4T36"
  68. "CzAFrfPwsHIrBz9BsaIQ21VRkcmj7DswfI/i"
  69. "DGd8j6bqiODyNZYQ+ZrLmF0KIJ2yPN3iO6Zq"
  70. "23TaOrVTjB7d1a/h31ODfiHAxFHrkY3t3D5J"
  71. "R9Nsl/7fdRmSznwtcSDgLXBoFEYmw6p86Acv"
  72. "RyoYNcL1SXjaKVLG5jyU3UR+LcGZT5t/0xGf"
  73. "oIK/aKwENrsjcKZZj660b1M=");
  74. const string nsec3_signature("gNIVj4T8t51fEU6kOPpvK7HOGBFZGbalN5ZK"
  75. "mInyrww6UWZsUNdw07ge6/U6HfG+/s61RZ/L"
  76. "is2M6yUWHyXbNbj/QqwqgadG5dhxTArfuR02"
  77. "xP600x0fWX8LXzW4yLMdKVxGbzYT+vvGz71o"
  78. "8gHSY5vYTtothcZQa4BMKhmGQEk=");
  79. const Name zone_name("example.com");
  80. const Name nomatch_name("example.org");
  81. const Name child_name("sql1.example.com");
  82. const Name www_name("www.example.com");
  83. const Name www_upper_name("WWW.EXAMPLE.COM");
  84. typedef enum {
  85. NORMAL,
  86. EXACT,
  87. ADDRESS,
  88. REFERRAL
  89. } FindMode;
  90. class Sqlite3DataSourceTest : public ::testing::Test {
  91. protected:
  92. Sqlite3DataSourceTest() : rrclass(RRClass::IN()),
  93. rrclass_notmatch(RRClass::CH()),
  94. rrtype(RRType::A()), rrttl(RRTTL(3600)),
  95. find_flags(0), rrset_matched(0), rrset_count(0)
  96. {
  97. data_source.init(SQLITE_DBFILE_EXAMPLE);
  98. common_a_data.push_back("192.0.2.1");
  99. common_sig_data.push_back("A 5 3 3600" + sigdata_common);
  100. common_aaaa_data.push_back("2001:db8::1234");
  101. common_aaaa_sig_data.push_back("AAAA 5 3 3600" + sigdata_common);
  102. www_nsec_data.push_back("example.com. A RRSIG NSEC");
  103. www_nsec_sig_data.push_back("NSEC 5 3 7200" + sigdata_common);
  104. mix_a_data.push_back("192.0.2.1");
  105. mix_a_data.push_back("192.0.2.2");
  106. mix_aaaa_data.push_back("2001:db8::1");
  107. mix_aaaa_data.push_back("2001:db8::2");
  108. apex_soa_data.push_back("master.example.com. admin.example.com. "
  109. "1234 3600 1800 2419200 7200");
  110. apex_soa_sig_data.push_back("SOA 5 2 3600" + sigdata_common);
  111. apex_ns_data.push_back("dns01.example.com.");
  112. apex_ns_data.push_back("dns02.example.com.");
  113. apex_ns_data.push_back("dns03.example.com.");
  114. apex_ns_sig_data.push_back("NS 5 2 3600" + sigdata_common);
  115. apex_mx_data.push_back("10 mail.example.com.");
  116. apex_mx_data.push_back("20 mail.subzone.example.com.");
  117. apex_mx_sig_data.push_back("MX 5 2 3600" + sigdata_common);
  118. apex_nsec_data.push_back("cname-ext.example.com. "
  119. "NS SOA MX RRSIG NSEC DNSKEY");
  120. apex_nsec_sig_data.push_back("NSEC 5 2 7200" + sigdata_common);
  121. apex_dnskey_data.push_back("256 3 5" + dnskey1_data);
  122. apex_dnskey_data.push_back("257 3 5" + dnskey2_data);
  123. // this one is special (using different key):
  124. apex_dnskey_sig_data.push_back("DNSKEY 5 2 3600 20100322084538 "
  125. "20100220084538 4456 example.com. "
  126. "FAKEFAKEFAKEFAKE");
  127. apex_dnskey_sig_data.push_back("DNSKEY 5 2 3600" + sigdata_common);
  128. wild_a_data.push_back("192.0.2.255");
  129. dname_data.push_back("sql1.example.com.");
  130. dname_sig_data.push_back("DNAME 5 3 3600" + sigdata_common);
  131. cname_data.push_back("cnametest.example.org.");
  132. cname_sig_data.push_back("CNAME 5 3 3600" + sigdata_common);
  133. cname_nsec_data.push_back("mail.example.com. CNAME RRSIG NSEC");
  134. cname_nsec_sig_data.push_back("NSEC 5 3 7200" + sigdata_common);
  135. delegation_ns_data.push_back("ns1.subzone.example.com.");
  136. delegation_ns_data.push_back("ns2.subzone.example.com.");
  137. delegation_ds_data.push_back("40633 5 1 "
  138. "3E56C0EA92CF529E005A4B62979533350492 "
  139. "F105");
  140. delegation_ds_data.push_back("40633 5 2 "
  141. "AA8D4BD330C68BFB4D785894DDCF6B689CE9"
  142. "873C4A3801F57A5AA3FE17925B8C");
  143. delegation_ds_sig_data.push_back("DS 5 3 3600" + sigdata_common);
  144. child_ds_data.push_back("33313 5 1 "
  145. "FDD7A2C11AA7F55D50FBF9B7EDDA2322C541A8DE");
  146. child_ds_data.push_back("33313 5 2 "
  147. "0B99B7006F496D135B01AB17EDB469B4BE9E"
  148. "1973884DEA757BC4E3015A8C3AB3");
  149. child_ds_sig_data.push_back("DS 5 3 3600" + sigdata_common);
  150. delegation_nsec_data.push_back("*.wild.example.com. NS DS RRSIG NSEC");
  151. delegation_nsec_sig_data.push_back("NSEC 5 3 7200" + sigdata_common);
  152. child_a_data.push_back("192.0.2.100");
  153. child_sig_data.push_back("A 5 4 3600 20100322084536 "
  154. "20100220084536 12447 sql1.example.com. "
  155. "FAKEFAKEFAKEFAKE");
  156. nsec3_data.push_back("1 0 10 FEEDABEE 4KLSVDE8KH8G95VU68R7AHBE1CPQN38J");
  157. nsec3_sig_data.push_back("NSEC3 5 4 7200 20100410172647 "
  158. "20100311172647 63192 sql2.example.com. "
  159. + nsec3_signature);
  160. }
  161. Sqlite3DataSrc data_source;
  162. // we allow these to be modified in the test
  163. RRClass rrclass;
  164. RRClass rrclass_notmatch;
  165. RRType rrtype;
  166. RRTTL rrttl;
  167. RRsetList result_sets;
  168. uint32_t find_flags;
  169. unsigned rrset_matched;
  170. unsigned rrset_count;
  171. vector<RRType> types;
  172. vector<RRTTL> ttls;
  173. vector<const vector<string>* > answers;
  174. vector<const vector<string>* > signatures;
  175. vector<RRType> expected_types;
  176. vector<string> common_a_data;
  177. vector<string> common_sig_data;
  178. vector<string> common_aaaa_data;
  179. vector<string> common_aaaa_sig_data;
  180. vector<string> www_nsec_data;
  181. vector<string> www_nsec_sig_data;
  182. vector<string> mix_a_data;
  183. vector<string> mix_aaaa_data;
  184. vector<string> apex_soa_data;
  185. vector<string> apex_soa_sig_data;
  186. vector<string> apex_ns_data;
  187. vector<string> apex_ns_sig_data;
  188. vector<string> apex_mx_data;
  189. vector<string> apex_mx_sig_data;
  190. vector<string> apex_nsec_data;
  191. vector<string> apex_nsec_sig_data;
  192. vector<string> apex_dnskey_data;
  193. vector<string> apex_dnskey_sig_data;
  194. vector<string> wild_a_data;
  195. vector<string> dname_data;
  196. vector<string> dname_sig_data;
  197. vector<string> cname_data;
  198. vector<string> cname_sig_data;
  199. vector<string> cname_nsec_data;
  200. vector<string> cname_nsec_sig_data;
  201. vector<string> delegation_ns_data;
  202. vector<string> delegation_ns_sig_data;
  203. vector<string> delegation_ds_data;
  204. vector<string> delegation_ds_sig_data;
  205. vector<string> child_ds_data;
  206. vector<string> child_ds_sig_data;
  207. vector<string> delegation_nsec_data;
  208. vector<string> delegation_nsec_sig_data;
  209. vector<string> child_a_data;
  210. vector<string> child_sig_data;
  211. vector<string> nsec3_data;
  212. vector<string> nsec3_sig_data;
  213. void findReferralRRsetCommon(const Name& qname, const RRClass& qclass);
  214. void findAddressRRsetCommon(const RRClass& qclass);
  215. };
  216. void
  217. checkRRset(RRsetPtr rrset, const Name& expected_name,
  218. const RRClass& expected_class, const RRType& expected_type,
  219. const RRTTL& expected_rrttl, const vector<string>& expected_data,
  220. const vector<string>* expected_sig_data)
  221. {
  222. EXPECT_EQ(expected_name, rrset->getName());
  223. EXPECT_EQ(expected_class, rrset->getClass());
  224. EXPECT_EQ(expected_type, rrset->getType());
  225. EXPECT_EQ(expected_rrttl, rrset->getTTL());
  226. RdataIteratorPtr rdata_iterator = rrset->getRdataIterator();
  227. vector<string>::const_iterator data_it = expected_data.begin();
  228. for (; data_it != expected_data.end(); ++data_it) {
  229. EXPECT_FALSE(rdata_iterator->isLast());
  230. if (rdata_iterator->isLast()) {
  231. // buggy case, should stop here
  232. break;
  233. }
  234. // We use text-based comparison so that we can easily identify which
  235. // data causes the error. RDATA::compare() is the most strict
  236. // comparison method, but in this case text-based comparison should
  237. // be okay because we generate the text data from Rdata objects
  238. // rather than hand-write the expected text.
  239. EXPECT_EQ(createRdata(expected_type, expected_class,
  240. *data_it)->toText(),
  241. rdata_iterator->getCurrent().toText());
  242. rdata_iterator->next();
  243. }
  244. if (expected_sig_data != NULL) {
  245. RRsetPtr sig_rrset = rrset->getRRsig();
  246. EXPECT_FALSE(sig_rrset == NULL);
  247. if (sig_rrset != NULL) { // check this to avoid possible bug.
  248. // Note: we assume the TTL for RRSIG is the same as that of the
  249. // RRSIG target.
  250. checkRRset(sig_rrset, expected_name, expected_class,
  251. RRType::RRSIG(), expected_rrttl, *expected_sig_data,
  252. NULL);
  253. }
  254. } else {
  255. EXPECT_TRUE(NULL == rrset->getRRsig());
  256. }
  257. EXPECT_TRUE(rdata_iterator->isLast());
  258. }
  259. void
  260. checkFind(FindMode mode, const Sqlite3DataSrc& data_source,
  261. const Name& expected_name, const Name* zone_name,
  262. const RRClass& qclass, const RRClass& expected_class,
  263. const RRType& expected_type, const vector<RRTTL>& expected_ttls,
  264. const uint32_t expected_flags, const vector<RRType>& expected_types,
  265. const vector<const vector<string>* >& expected_answers,
  266. const vector<const vector<string>* >& expected_signatures)
  267. {
  268. RRsetList result_sets;
  269. uint32_t find_flags;
  270. unsigned int rrset_matched = 0;
  271. unsigned int rrset_count = 0;
  272. switch (mode) {
  273. case NORMAL:
  274. EXPECT_EQ(DataSrc::SUCCESS,
  275. data_source.findRRset(expected_name, qclass,
  276. expected_type, result_sets, find_flags,
  277. zone_name));
  278. break;
  279. case EXACT:
  280. EXPECT_EQ(DataSrc::SUCCESS,
  281. data_source.findExactRRset(expected_name, qclass,
  282. expected_type, result_sets,
  283. find_flags, zone_name));
  284. break;
  285. case ADDRESS:
  286. EXPECT_EQ(DataSrc::SUCCESS,
  287. data_source.findAddrs(expected_name, qclass, result_sets,
  288. find_flags, zone_name));
  289. break;
  290. case REFERRAL:
  291. EXPECT_EQ(DataSrc::SUCCESS,
  292. data_source.findReferral(expected_name, qclass, result_sets,
  293. find_flags, zone_name));
  294. break;
  295. }
  296. EXPECT_EQ(expected_flags, find_flags);
  297. RRsetList::iterator it = result_sets.begin();
  298. for (; it != result_sets.end(); ++it) {
  299. vector<RRType>::const_iterator found_type =
  300. find(expected_types.begin(), expected_types.end(),
  301. (*it)->getType());
  302. // there should be a match
  303. EXPECT_TRUE(found_type != expected_types.end());
  304. if (found_type != expected_types.end()) {
  305. unsigned int index = distance(expected_types.begin(), found_type);
  306. checkRRset(*it, expected_name, expected_class, (*it)->getType(),
  307. expected_ttls[index], *expected_answers[index],
  308. expected_signatures[index]);
  309. ++rrset_matched;
  310. }
  311. ++rrset_count;
  312. }
  313. EXPECT_EQ(expected_types.size(), rrset_count);
  314. EXPECT_EQ(expected_types.size(), rrset_matched);
  315. }
  316. void
  317. checkFind(FindMode mode, const Sqlite3DataSrc& data_source,
  318. const Name& expected_name, const Name* zone_name,
  319. const RRClass& qclass, const RRClass& expected_class,
  320. const RRType& expected_type, const RRTTL& expected_rrttl,
  321. const uint32_t expected_flags,
  322. const vector<string>& expected_data,
  323. const vector<string>* expected_sig_data)
  324. {
  325. vector<RRType> types;
  326. vector<RRTTL> ttls;
  327. vector<const vector<string>* > answers;
  328. vector<const vector<string>* > signatures;
  329. types.push_back(expected_type);
  330. ttls.push_back(expected_rrttl);
  331. answers.push_back(&expected_data);
  332. signatures.push_back(expected_sig_data);
  333. checkFind(mode, data_source, expected_name, zone_name, qclass,
  334. expected_class, expected_type, ttls, expected_flags, types,
  335. answers, signatures);
  336. }
  337. TEST_F(Sqlite3DataSourceTest, close) {
  338. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  339. }
  340. TEST_F(Sqlite3DataSourceTest, reOpen) {
  341. // Replace the data with a totally different zone. This should succeed,
  342. // and shouldn't match any names in the previously managed domains.
  343. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  344. EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE2));
  345. DataSrcMatch match(www_name, rrclass);
  346. data_source.findClosestEnclosure(match);
  347. EXPECT_EQ(static_cast<void*>(NULL), match.getEnclosingZone());
  348. EXPECT_EQ(static_cast<void*>(NULL), match.getDataSource());
  349. }
  350. TEST_F(Sqlite3DataSourceTest, openFail) {
  351. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  352. EXPECT_THROW(data_source.init(SQLITE_DBFILE_NOTEXIST), Sqlite3Error);
  353. }
  354. TEST_F(Sqlite3DataSourceTest, doubleOpen) {
  355. // An attempt of duplicate open should trigger an exception.
  356. EXPECT_THROW(data_source.init(SQLITE_DBFILE_EXAMPLE), DataSourceError);
  357. }
  358. TEST_F(Sqlite3DataSourceTest, doubleClose) {
  359. // An attempt of duplicate close should trigger an exception.
  360. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  361. EXPECT_THROW(data_source.close(), DataSourceError);
  362. }
  363. TEST_F(Sqlite3DataSourceTest, openBrokenDB) {
  364. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  365. // The database exists but is broken. An exception will be thrown
  366. // in the middle of the initialization.
  367. EXPECT_THROW(data_source.init(SQLITE_DBFILE_BROKENDB), Sqlite3Error);
  368. // Confirming the strong exception guarantee: the data source must be
  369. // in the closed state.
  370. EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE));
  371. }
  372. // Different schema versions, see sqlite3_accessor_unittest.
  373. TEST_F(Sqlite3DataSourceTest, differentSchemaVersions) {
  374. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  375. EXPECT_THROW(data_source.init(SQLITE_DBFILE_NEWSCHEMA),
  376. IncompatibleDbVersion);
  377. EXPECT_THROW(data_source.init(SQLITE_DBFILE_OLDSCHEMA),
  378. IncompatibleDbVersion);
  379. // Don't bother to test the new_minor case; we should retire this stuff
  380. // before it really happens.
  381. }
  382. // This test only confirms that on-the-fly schema creation works.
  383. TEST_F(Sqlite3DataSourceTest, memoryDB) {
  384. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  385. EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_MEMORY));
  386. }
  387. TEST_F(Sqlite3DataSourceTest, findClosestEnclosure) {
  388. DataSrcMatch match(www_name, rrclass);
  389. data_source.findClosestEnclosure(match);
  390. EXPECT_EQ(zone_name, *match.getEnclosingZone());
  391. EXPECT_EQ(&data_source, match.getDataSource());
  392. }
  393. TEST_F(Sqlite3DataSourceTest, findClosestEnclosureMatchRoot) {
  394. EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
  395. EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE_ROOT));
  396. DataSrcMatch match(Name("org."), rrclass);
  397. data_source.findClosestEnclosure(match);
  398. EXPECT_EQ(Name("."), *match.getEnclosingZone());
  399. EXPECT_EQ(&data_source, match.getDataSource());
  400. }
  401. TEST_F(Sqlite3DataSourceTest, findClosestEnclosureAtDelegation) {
  402. // The search name exists both in the parent and child zones, but
  403. // child has a better match.
  404. DataSrcMatch match(child_name, rrclass);
  405. data_source.findClosestEnclosure(match);
  406. EXPECT_EQ(child_name, *match.getEnclosingZone());
  407. EXPECT_EQ(&data_source, match.getDataSource());
  408. }
  409. TEST_F(Sqlite3DataSourceTest, findClosestEnclosureNoMatch) {
  410. DataSrcMatch match(nomatch_name, rrclass);
  411. data_source.findClosestEnclosure(match);
  412. EXPECT_EQ(static_cast<void*>(NULL), match.getEnclosingZone());
  413. EXPECT_EQ(static_cast<void*>(NULL), match.getDataSource());
  414. }
  415. TEST_F(Sqlite3DataSourceTest, findClosestClassMismatch) {
  416. DataSrcMatch match(nomatch_name, rrclass);
  417. data_source.findClosestEnclosure(match);
  418. EXPECT_EQ(static_cast<void*>(NULL), match.getEnclosingZone());
  419. EXPECT_EQ(static_cast<void*>(NULL), match.getDataSource());
  420. }
  421. // If the query class is ANY, the result should be the same as the case where
  422. // the class exactly matches.
  423. TEST_F(Sqlite3DataSourceTest, findClosestClassAny) {
  424. DataSrcMatch match(www_name, RRClass::ANY());
  425. data_source.findClosestEnclosure(match);
  426. EXPECT_EQ(zone_name, *match.getEnclosingZone());
  427. EXPECT_EQ(&data_source, match.getDataSource());
  428. }
  429. TEST_F(Sqlite3DataSourceTest, findRRsetNormal) {
  430. // Without specifying the zone name, and then with the zone name
  431. checkFind(NORMAL, data_source, www_name, NULL, rrclass, rrclass, rrtype,
  432. rrttl, 0, common_a_data, &common_sig_data);
  433. checkFind(NORMAL, data_source, www_name, &zone_name, rrclass, rrclass,
  434. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  435. // With a zone name that doesn't match
  436. EXPECT_EQ(DataSrc::SUCCESS,
  437. data_source.findRRset(www_name, rrclass, rrtype,
  438. result_sets, find_flags, &nomatch_name));
  439. EXPECT_EQ(DataSrc::NO_SUCH_ZONE, find_flags);
  440. EXPECT_TRUE(result_sets.begin() == result_sets.end()); // should be empty
  441. }
  442. TEST_F(Sqlite3DataSourceTest, findRRsetClassMismatch) {
  443. EXPECT_EQ(DataSrc::ERROR,
  444. data_source.findRRset(www_name, rrclass_notmatch, rrtype,
  445. result_sets, find_flags, NULL));
  446. }
  447. TEST_F(Sqlite3DataSourceTest, findRRsetClassAny) {
  448. checkFind(NORMAL, data_source, www_name, NULL, RRClass::ANY(), rrclass,
  449. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  450. }
  451. TEST_F(Sqlite3DataSourceTest, findRRsetClassClassAny) {
  452. checkFind(NORMAL, data_source, www_name, NULL, RRClass::ANY(), rrclass,
  453. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  454. }
  455. TEST_F(Sqlite3DataSourceTest, findRRsetNormalANY) {
  456. types.push_back(RRType::A());
  457. types.push_back(RRType::NSEC());
  458. ttls.push_back(RRTTL(3600));
  459. ttls.push_back(RRTTL(7200));
  460. answers.push_back(&common_a_data);
  461. answers.push_back(&www_nsec_data);
  462. signatures.push_back(&common_sig_data);
  463. signatures.push_back(&www_nsec_sig_data);
  464. rrtype = RRType::ANY();
  465. checkFind(NORMAL, data_source, www_name, NULL, rrclass, rrclass, rrtype,
  466. ttls, 0, types, answers, signatures);
  467. checkFind(NORMAL, data_source, www_name, &zone_name, rrclass, rrclass,
  468. rrtype, ttls, 0, types, answers, signatures);
  469. }
  470. // Case insensitive lookup
  471. TEST_F(Sqlite3DataSourceTest, findRRsetNormalCase) {
  472. checkFind(NORMAL, data_source, www_upper_name, NULL, rrclass, rrclass,
  473. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  474. checkFind(NORMAL, data_source, www_upper_name, &zone_name, rrclass, rrclass,
  475. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  476. EXPECT_EQ(DataSrc::SUCCESS,
  477. data_source.findRRset(www_upper_name, rrclass, rrtype,
  478. result_sets, find_flags, &nomatch_name));
  479. EXPECT_EQ(DataSrc::NO_SUCH_ZONE, find_flags);
  480. EXPECT_TRUE(result_sets.begin() == result_sets.end()); // should be empty
  481. }
  482. TEST_F(Sqlite3DataSourceTest, findRRsetApexNS) {
  483. rrtype = RRType::NS();
  484. checkFind(NORMAL, data_source, zone_name, NULL, rrclass, rrclass, rrtype,
  485. rrttl, DataSrc::REFERRAL, apex_ns_data, &apex_ns_sig_data);
  486. checkFind(NORMAL, data_source, zone_name, &zone_name, rrclass, rrclass,
  487. rrtype, rrttl, DataSrc::REFERRAL, apex_ns_data,
  488. &apex_ns_sig_data);
  489. EXPECT_EQ(DataSrc::SUCCESS,
  490. data_source.findRRset(zone_name, rrclass, rrtype,
  491. result_sets, find_flags, &nomatch_name));
  492. EXPECT_EQ(DataSrc::NO_SUCH_ZONE, find_flags);
  493. EXPECT_TRUE(result_sets.begin() == result_sets.end()); // should be empty
  494. }
  495. TEST_F(Sqlite3DataSourceTest, findRRsetApexANY) {
  496. types.push_back(RRType::SOA());
  497. types.push_back(RRType::NS());
  498. types.push_back(RRType::MX());
  499. types.push_back(RRType::NSEC());
  500. types.push_back(RRType::DNSKEY());
  501. ttls.push_back(rrttl); // SOA TTL
  502. ttls.push_back(rrttl); // NS TTL
  503. ttls.push_back(rrttl); // MX TTL
  504. ttls.push_back(RRTTL(7200)); // NSEC TTL
  505. ttls.push_back(rrttl); // DNSKEY TTL
  506. answers.push_back(&apex_soa_data);
  507. answers.push_back(&apex_ns_data);
  508. answers.push_back(&apex_mx_data);
  509. answers.push_back(&apex_nsec_data);
  510. answers.push_back(&apex_dnskey_data);
  511. signatures.push_back(&apex_soa_sig_data);
  512. signatures.push_back(&apex_ns_sig_data);
  513. signatures.push_back(&apex_mx_sig_data);
  514. signatures.push_back(&apex_nsec_sig_data);
  515. signatures.push_back(&apex_dnskey_sig_data);
  516. rrtype = RRType::ANY();
  517. // there is an NS at the zone apex, so the REFERRAL flag should
  518. // be set, but will ordinarily be ignored by the caller
  519. checkFind(NORMAL, data_source, zone_name, NULL, rrclass, rrclass, rrtype,
  520. ttls, DataSrc::REFERRAL, types, answers, signatures);
  521. checkFind(NORMAL, data_source, zone_name, &zone_name, rrclass, rrclass,
  522. rrtype, ttls, DataSrc::REFERRAL, types, answers, signatures);
  523. }
  524. TEST_F(Sqlite3DataSourceTest, findRRsetMixedANY) {
  525. // ANY query for mixed order RRs
  526. const Name qname("mix.example.com");
  527. types.push_back(RRType::A());
  528. types.push_back(RRType::AAAA());
  529. ttls.push_back(rrttl);
  530. ttls.push_back(rrttl);
  531. answers.push_back(&mix_a_data);
  532. answers.push_back(&mix_aaaa_data);
  533. signatures.push_back(NULL);
  534. signatures.push_back(NULL);
  535. rrtype = RRType::ANY();
  536. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  537. rrtype, ttls, 0, types, answers, signatures);
  538. }
  539. TEST_F(Sqlite3DataSourceTest, findRRsetApexNXRRSET) {
  540. rrtype = RRType::AAAA();
  541. EXPECT_EQ(DataSrc::SUCCESS,
  542. data_source.findRRset(zone_name, rrclass, rrtype,
  543. result_sets, find_flags, &zone_name));
  544. // there's an NS RRset at the apex name, so the REFERRAL flag should be
  545. // set, too.
  546. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND | DataSrc::REFERRAL, find_flags);
  547. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  548. // Same test, without specifying the zone name
  549. EXPECT_EQ(DataSrc::SUCCESS,
  550. data_source.findRRset(zone_name, rrclass, rrtype,
  551. result_sets, find_flags, NULL));
  552. // there's an NS RRset at the apex name, so the REFERRAL flag should be
  553. // set, too.
  554. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND | DataSrc::REFERRAL, find_flags);
  555. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  556. }
  557. // Matching a wildcard node. There's nothing special for the data source API
  558. // point of view, but perform minimal tests anyway.
  559. TEST_F(Sqlite3DataSourceTest, findRRsetWildcard) {
  560. const Name qname("*.wild.example.com");
  561. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  562. rrtype, rrttl, 0, wild_a_data, &common_sig_data);
  563. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  564. rrtype, rrttl, 0, wild_a_data, &common_sig_data);
  565. }
  566. TEST_F(Sqlite3DataSourceTest, findRRsetEmptyNode) {
  567. // foo.bar.example.com exists, but bar.example.com doesn't have any data.
  568. const Name qname("bar.example.com");
  569. EXPECT_EQ(DataSrc::SUCCESS,
  570. data_source.findRRset(qname, rrclass, rrtype,
  571. result_sets, find_flags, NULL));
  572. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND, find_flags);
  573. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  574. EXPECT_EQ(DataSrc::SUCCESS,
  575. data_source.findRRset(qname, rrclass, rrtype,
  576. result_sets, find_flags, &zone_name));
  577. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND, find_flags);
  578. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  579. }
  580. // There's nothing special about DNAME lookup for the data source API
  581. // point of view, but perform minimal tests anyway.
  582. TEST_F(Sqlite3DataSourceTest, findRRsetDNAME) {
  583. const Name qname("dname.example.com");
  584. rrtype = RRType::DNAME();
  585. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  586. rrtype, rrttl, 0, dname_data, &dname_sig_data);
  587. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  588. rrtype, rrttl, 0, dname_data, &dname_sig_data);
  589. }
  590. TEST_F(Sqlite3DataSourceTest, findRRsetCNAME) {
  591. const Name qname("foo.example.com");
  592. // This qname only has the CNAME (+ sigs). CNAME query is not different
  593. // from ordinary queries.
  594. rrtype = RRType::CNAME();
  595. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  596. rrtype, rrttl, 0, cname_data, &cname_sig_data);
  597. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  598. rrtype, rrttl, 0, cname_data, &cname_sig_data);
  599. // queries for (ordinary) different RR types that match the CNAME.
  600. // CNAME_FOUND flag is set, and the CNAME RR is returned instead of A
  601. rrtype = RRType::A();
  602. types.push_back(RRType::CNAME());
  603. ttls.push_back(rrttl);
  604. answers.push_back(&cname_data);
  605. signatures.push_back(&cname_sig_data);
  606. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  607. rrtype, ttls, DataSrc::CNAME_FOUND, types, answers, signatures);
  608. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  609. rrtype, ttls, DataSrc::CNAME_FOUND, types, answers, signatures);
  610. // NSEC query that match the CNAME.
  611. // CNAME_FOUND flag is NOT set, and the NSEC RR is returned instead of
  612. // CNAME.
  613. rrtype = RRType::NSEC();
  614. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  615. rrtype, RRTTL(7200), 0, cname_nsec_data, &cname_nsec_sig_data);
  616. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  617. rrtype, RRTTL(7200), 0, cname_nsec_data, &cname_nsec_sig_data);
  618. }
  619. TEST_F(Sqlite3DataSourceTest, findRRsetDelegation) {
  620. const Name qname("www.subzone.example.com");
  621. // query for a name under a zone cut. From the data source API point
  622. // of view this is no different than "NXDOMAIN".
  623. EXPECT_EQ(DataSrc::SUCCESS,
  624. data_source.findRRset(qname, rrclass, rrtype,
  625. result_sets, find_flags, NULL));
  626. EXPECT_EQ(DataSrc::NAME_NOT_FOUND, find_flags);
  627. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  628. }
  629. TEST_F(Sqlite3DataSourceTest, findRRsetDelegationAtZoneCut) {
  630. const Name qname("subzone.example.com");
  631. // query for a name *at* a zone cut. It matches the NS RRset for the
  632. // delegation.
  633. // For non-NS ordinary queries, "no type" should be set too, and no RRset is
  634. // returned.
  635. EXPECT_EQ(DataSrc::SUCCESS,
  636. data_source.findRRset(qname, rrclass, rrtype,
  637. result_sets, find_flags, NULL));
  638. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND | DataSrc::REFERRAL, find_flags);
  639. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  640. EXPECT_EQ(DataSrc::SUCCESS,
  641. data_source.findRRset(qname, rrclass, rrtype,
  642. result_sets, find_flags, &zone_name));
  643. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND | DataSrc::REFERRAL, find_flags);
  644. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  645. // For NS query, RRset is returned with the REFERRAL flag. No RRSIG should
  646. // be provided.
  647. rrtype = RRType::NS();
  648. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  649. rrtype, rrttl, DataSrc::REFERRAL, delegation_ns_data, NULL);
  650. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  651. rrtype, rrttl, DataSrc::REFERRAL, delegation_ns_data, NULL);
  652. // For ANY query. At the backend data source level, it returns all
  653. // existent records with their RRSIGs, setting the referral flag.
  654. rrtype = RRType::ANY();
  655. types.push_back(RRType::NS());
  656. types.push_back(RRType::NSEC());
  657. types.push_back(RRType::DS());
  658. ttls.push_back(rrttl);
  659. ttls.push_back(RRTTL(7200));
  660. ttls.push_back(rrttl);
  661. answers.push_back(&delegation_ns_data);
  662. answers.push_back(&delegation_nsec_data);
  663. answers.push_back(&delegation_ds_data);
  664. signatures.push_back(NULL);
  665. signatures.push_back(&delegation_nsec_sig_data);
  666. signatures.push_back(&delegation_ds_sig_data);
  667. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  668. rrtype, ttls, DataSrc::REFERRAL, types, answers,
  669. signatures);
  670. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  671. rrtype, ttls, DataSrc::REFERRAL, types, answers,
  672. signatures);
  673. // For NSEC query. At the backend data source level, it returns NSEC+
  674. // RRSIG with the referral flag.
  675. rrtype = RRType::NSEC();
  676. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  677. rrtype, RRTTL(7200), DataSrc::REFERRAL, delegation_nsec_data,
  678. &delegation_nsec_sig_data);
  679. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  680. rrtype, RRTTL(7200), DataSrc::REFERRAL, delegation_nsec_data,
  681. &delegation_nsec_sig_data);
  682. }
  683. TEST_F(Sqlite3DataSourceTest, findRRsetInChildZone) {
  684. const Name qname("www.sql1.example.com");
  685. const Name child_zone_name("sql1.example.com");
  686. // If we don't specify the zone, the data source should identify the
  687. // best matching zone.
  688. checkFind(NORMAL, data_source, qname, NULL, rrclass, rrclass,
  689. rrtype, rrttl, 0, child_a_data, &child_sig_data);
  690. // If we specify the parent zone, it's treated as NXDOMAIN because it's
  691. // under a zone cut.
  692. EXPECT_EQ(DataSrc::SUCCESS,
  693. data_source.findRRset(qname, rrclass, rrtype,
  694. result_sets, find_flags, &zone_name));
  695. EXPECT_EQ(DataSrc::NAME_NOT_FOUND, find_flags);
  696. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  697. // If we specify the child zone, it should be the same as the first case.
  698. checkFind(NORMAL, data_source, qname, &child_zone_name, rrclass, rrclass,
  699. rrtype, rrttl, 0, child_a_data, &child_sig_data);
  700. }
  701. TEST_F(Sqlite3DataSourceTest, findExactRRset) {
  702. // Normal case. No different than findRRset.
  703. checkFind(EXACT, data_source, www_name, &zone_name, rrclass, rrclass,
  704. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  705. }
  706. TEST_F(Sqlite3DataSourceTest, findExactRRsetClassMismatch) {
  707. EXPECT_EQ(DataSrc::ERROR,
  708. data_source.findExactRRset(www_name, rrclass_notmatch, rrtype,
  709. result_sets, find_flags, NULL));
  710. }
  711. TEST_F(Sqlite3DataSourceTest, findExactRRsetClassAny) {
  712. checkFind(EXACT, data_source, www_name, &zone_name, RRClass::ANY(), rrclass,
  713. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  714. }
  715. TEST_F(Sqlite3DataSourceTest, findRRsetNSEC3) {
  716. // Simple NSEC3 tests (more should be added)
  717. string hashstr("1BB7SO0452U1QHL98UISNDD9218GELR5");
  718. const Name nsec3_zonename("sql2.example.com");
  719. EXPECT_EQ(DataSrc::SUCCESS,
  720. data_source.findCoveringNSEC3(nsec3_zonename,
  721. hashstr, result_sets));
  722. RRsetList::iterator it = result_sets.begin();
  723. checkRRset(*it, Name(hashstr).concatenate(nsec3_zonename), rrclass,
  724. RRType::NSEC3(), RRTTL(7200), nsec3_data, &nsec3_sig_data);
  725. ++it;
  726. EXPECT_TRUE(it == result_sets.end());
  727. }
  728. TEST_F(Sqlite3DataSourceTest, findExactRRsetCNAME) {
  729. const Name qname("foo.example.com");
  730. // This qname only has the CNAME (+ sigs). In this case it should be
  731. // no different than findRRset for CNAME query.
  732. rrtype = RRType::CNAME();
  733. checkFind(NORMAL, data_source, qname, &zone_name, rrclass, rrclass,
  734. rrtype, rrttl, 0, cname_data, &cname_sig_data);
  735. // queries for (ordinary) different RR types that match the CNAME.
  736. // "type not found" set, but CNAME and its sig are returned (awkward,
  737. // but that's how it currently works).
  738. rrtype = RRType::A();
  739. types.push_back(RRType::CNAME());
  740. ttls.push_back(rrttl);
  741. answers.push_back(&cname_data);
  742. signatures.push_back(&cname_sig_data);
  743. checkFind(EXACT, data_source, qname, &zone_name, rrclass, rrclass,
  744. rrtype, ttls, DataSrc::TYPE_NOT_FOUND, types, answers,
  745. signatures);
  746. }
  747. void
  748. Sqlite3DataSourceTest::findReferralRRsetCommon(const Name& qname,
  749. const RRClass& qclass)
  750. {
  751. types.push_back(RRType::NS());
  752. types.push_back(RRType::DS());
  753. ttls.push_back(rrttl);
  754. ttls.push_back(rrttl);
  755. answers.push_back(&apex_ns_data);
  756. answers.push_back(&child_ds_data);
  757. signatures.push_back(NULL);
  758. signatures.push_back(&child_ds_sig_data);
  759. // Note: zone_name matters here because we need to perform the search
  760. // in the parent zone.
  761. checkFind(REFERRAL, data_source, qname, &zone_name, qclass, rrclass,
  762. rrtype, ttls, DataSrc::REFERRAL, types, answers, signatures);
  763. }
  764. TEST_F(Sqlite3DataSourceTest, findReferralRRset) {
  765. // A referral lookup searches for NS, DS, or DNAME, or their sigs.
  766. const Name qname("sql1.example.com");
  767. findReferralRRsetCommon(qname, rrclass);
  768. }
  769. TEST_F(Sqlite3DataSourceTest, findReferralRRsetClassMismatch) {
  770. EXPECT_EQ(DataSrc::ERROR,
  771. data_source.findReferral(www_name, rrclass_notmatch, result_sets,
  772. find_flags, NULL));
  773. }
  774. TEST_F(Sqlite3DataSourceTest, findReferralRRsetClassAny) {
  775. const Name qname("sql1.example.com");
  776. findReferralRRsetCommon(qname, RRClass::ANY());
  777. }
  778. TEST_F(Sqlite3DataSourceTest, findReferralRRsetDNAME) {
  779. // same as above. the DNAME case.
  780. const Name qname("dname.example.com");
  781. checkFind(REFERRAL, data_source, qname, &zone_name, rrclass, rrclass,
  782. RRType::DNAME(), rrttl, 0, dname_data, &dname_sig_data);
  783. }
  784. TEST_F(Sqlite3DataSourceTest, findReferralRRsetFail) {
  785. // qname has not "referral" records. the result should be "empty".
  786. EXPECT_EQ(DataSrc::SUCCESS,
  787. data_source.findReferral(www_name, rrclass,
  788. result_sets, find_flags, &zone_name));
  789. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND, find_flags);
  790. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  791. }
  792. void
  793. Sqlite3DataSourceTest::findAddressRRsetCommon(const RRClass& qclass) {
  794. // A referral lookup searches for A or AAAA, or their sigs.
  795. // A-only case
  796. checkFind(ADDRESS, data_source, www_name, &zone_name, qclass, rrclass,
  797. rrtype, rrttl, 0, common_a_data, &common_sig_data);
  798. // AAAA-only case
  799. checkFind(ADDRESS, data_source, Name("ip6.example.com"), &zone_name,
  800. qclass, rrclass, RRType::AAAA(), rrttl, 0, common_aaaa_data,
  801. &common_aaaa_sig_data);
  802. // Dual-stack
  803. types.push_back(RRType::A());
  804. ttls.push_back(rrttl);
  805. answers.push_back(&common_a_data);
  806. signatures.push_back(&common_sig_data);
  807. types.push_back(RRType::AAAA());
  808. ttls.push_back(rrttl);
  809. answers.push_back(&common_aaaa_data);
  810. signatures.push_back(&common_aaaa_sig_data);
  811. checkFind(ADDRESS, data_source, Name("ip46.example.com"), &zone_name,
  812. rrclass, rrclass, rrtype, ttls, 0, types, answers, signatures);
  813. // The qname doesn't have no address records.
  814. EXPECT_EQ(DataSrc::SUCCESS,
  815. data_source.findAddrs(Name("text.example.com"), qclass,
  816. result_sets, find_flags, &zone_name));
  817. EXPECT_EQ(DataSrc::TYPE_NOT_FOUND, find_flags);
  818. EXPECT_TRUE(result_sets.begin() == result_sets.end());
  819. }
  820. TEST_F(Sqlite3DataSourceTest, findAddressRRset) {
  821. findAddressRRsetCommon(rrclass);
  822. }
  823. TEST_F(Sqlite3DataSourceTest, findAddressRRsetClassMismatch) {
  824. EXPECT_EQ(DataSrc::ERROR, data_source.findAddrs(www_name, rrclass_notmatch,
  825. result_sets, find_flags,
  826. NULL));
  827. }
  828. TEST_F(Sqlite3DataSourceTest, findAddressRRsetClassAny) {
  829. findAddressRRsetCommon(RRClass::ANY());
  830. }
  831. }