Browse Source

more sqlite3 data source tests, covering the findAddrs() method.

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1165 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya 15 years ago
parent
commit
9f683adcff

+ 62 - 3
src/lib/auth/data_source_sqlite3_unittest.cc

@@ -89,6 +89,8 @@ protected:
 
 
         common_a_data.push_back("192.0.2.1");
         common_a_data.push_back("192.0.2.1");
         common_sig_data.push_back("A 5 3 3600" + sigdata_common);
         common_sig_data.push_back("A 5 3 3600" + sigdata_common);
+        common_aaaa_data.push_back("2001:db8::1234");
+        common_aaaa_sig_data.push_back("AAAA 5 3 3600" + sigdata_common);
 
 
         www_nsec_data.push_back("example.com. A RRSIG NSEC");
         www_nsec_data.push_back("example.com. A RRSIG NSEC");
         www_nsec_sig_data.push_back("NSEC 5 3 7200" + sigdata_common);
         www_nsec_sig_data.push_back("NSEC 5 3 7200" + sigdata_common);
@@ -157,6 +159,8 @@ protected:
     vector<RRType> expected_types;
     vector<RRType> expected_types;
     vector<string> common_a_data;
     vector<string> common_a_data;
     vector<string> common_sig_data;
     vector<string> common_sig_data;
+    vector<string> common_aaaa_data;
+    vector<string> common_aaaa_sig_data;
     vector<string> www_nsec_data;
     vector<string> www_nsec_data;
     vector<string> www_nsec_sig_data;
     vector<string> www_nsec_sig_data;
     vector<string> apex_soa_data;
     vector<string> apex_soa_data;
@@ -206,8 +210,15 @@ checkRRset(RRsetPtr rrset, const Name& expected_name,
             // buggy case, should stop here
             // buggy case, should stop here
             break;
             break;
         }
         }
-        EXPECT_EQ(0, (rdata_iterator->getCurrent()).compare(
-                      *createRdata(expected_type, expected_class, *data_it)));
+
+        // We use text-based comparison so that we can easily identify which
+        // data causes the error.  RDATA::compare() is the most strict
+        // comparison method, but in this case text-based comparison should
+        // be okay because we generate the text data from Rdata objects
+        // rather than hand-write the expected text.
+        EXPECT_EQ(createRdata(expected_type, expected_class,
+                              *data_it)->toText(),
+                  rdata_iterator->getCurrent().toText());
         rdata_iterator->next();
         rdata_iterator->next();
     }
     }
 
 
@@ -626,7 +637,7 @@ TEST_F(Sqlite3DataSourceTest, findExactRRsetCNAME) {
 }
 }
 
 
 #if 0 // this should work, but doesn't.  maybe the loadzone tool is broken?
 #if 0 // this should work, but doesn't.  maybe the loadzone tool is broken?
-TEST_F(Sqlite3DataSourceTest, findExactRRsetReferral) {
+TEST_F(Sqlite3DataSourceTest, findReferralRRset) {
     // A referral lookup searches for NS, DS, or DNAME, or their sigs.
     // A referral lookup searches for NS, DS, or DNAME, or their sigs.
     const Name qname("sql1.example.com");
     const Name qname("sql1.example.com");
 
 
@@ -645,4 +656,52 @@ TEST_F(Sqlite3DataSourceTest, findExactRRsetReferral) {
 }
 }
 #endif
 #endif
 
 
+TEST_F(Sqlite3DataSourceTest, findReferralRRsetDNAME) {
+    // same as above.  the DNAME case.
+    const Name qname("dname.example.com");
+    checkFind(REFERRAL, data_source, *query, qname, &zone_name, rrclass,
+              RRType::DNAME(), rrttl, 0, dname_data, &dname_sig_data);
+}
+
+TEST_F(Sqlite3DataSourceTest, findReferralRRsetFail) {
+    // qname has not "referral" records.  the result should be "empty".
+    EXPECT_EQ(DataSrc::SUCCESS,
+              data_source.findReferral(*query, www_name, rrclass,
+                                       result_sets, find_flags, &zone_name));
+    EXPECT_EQ(DataSrc::TYPE_NOT_FOUND, find_flags);
+    EXPECT_TRUE(result_sets.begin() == result_sets.end());
+}
+
+TEST_F(Sqlite3DataSourceTest, findAddressRRset) {
+    // A referral lookup searches for A or AAAA, or their sigs.
+
+    // A-only case
+    checkFind(ADDRESS, data_source, *query, www_name, &zone_name, rrclass,
+              rrtype, rrttl, 0, common_a_data, &common_sig_data);
+
+    // AAAA-only case
+    checkFind(ADDRESS, data_source, *query, Name("ip6.example.com"), &zone_name,
+              rrclass, RRType::AAAA(), rrttl, 0, common_aaaa_data,
+              &common_aaaa_sig_data);
+
+    // Dual-stack
+    types.push_back(RRType::A());
+    ttls.push_back(rrttl);
+    answers.push_back(&common_a_data);
+    signatures.push_back(&common_sig_data);
+    types.push_back(RRType::AAAA());
+    ttls.push_back(rrttl);
+    answers.push_back(&common_aaaa_data);
+    signatures.push_back(&common_aaaa_sig_data);
+    checkFind(ADDRESS, data_source, *query, Name("ip46.example.com"),
+              &zone_name, rrclass, rrtype, ttls, 0, types, answers, signatures);
+
+    // The qname doesn't have no address records.
+    EXPECT_EQ(DataSrc::SUCCESS,
+              data_source.findAddrs(*query, Name("text.example.com"), rrclass,
+                                    result_sets, find_flags, &zone_name));
+    EXPECT_EQ(DataSrc::TYPE_NOT_FOUND, find_flags);
+    EXPECT_TRUE(result_sets.begin() == result_sets.end());
+}
+
 }
 }

+ 19 - 4
src/lib/auth/testdata/example.com.signed

@@ -165,9 +165,24 @@ www.example.com.	3600	IN A	192.0.2.1
 					20100220084538 33495 example.com.
 					20100220084538 33495 example.com.
 					FAKEFAKEFAKEFAKE )
 					FAKEFAKEFAKEFAKE )
 
 
-;; This doesn't have an RRSIG.  It makes this zone "incomplete signed",
-;; but for the purpose of data source API testing it doesn't matter.
-nosig.example.com.	3600	IN A	192.0.2.1
-
 ;; Two labels + apex name for empty node test
 ;; Two labels + apex name for empty node test
 foo.bar.example.com.	3600	IN A	192.0.2.1
 foo.bar.example.com.	3600	IN A	192.0.2.1
+
+;; AAAA-only name
+ip6.example.com.	3600	IN AAAA	2001:db8::1234
+			3600	RRSIG	AAAA 5 3 3600 20100322084538 (
+					20100220084538 33495 example.com.
+					FAKEFAKEFAKEFAKE )
+
+;; Dual-stack host
+ip46.example.com.	3600	IN A	192.0.2.1
+			3600	RRSIG	A 5 3 3600 20100322084538 (
+					20100220084538 33495 example.com.
+					FAKEFAKEFAKEFAKE )
+			3600	IN AAAA	2001:db8::1234
+			3600	RRSIG	AAAA 5 3 3600 20100322084538 (
+					20100220084538 33495 example.com.
+					FAKEFAKEFAKEFAKE )
+
+;; not an address
+text.example.com.	3600	IN TXT	"No address is here"

BIN
src/lib/auth/testdata/test.sqlite3