|
@@ -133,7 +133,7 @@ protected:
|
|
"20120715220826 12345 com. FAKE"))
|
|
"20120715220826 12345 com. FAKE"))
|
|
{}
|
|
{}
|
|
|
|
|
|
- // A wraper for RdataEncoder::encode() with buffer overrun check.
|
|
|
|
|
|
+ // A wrapper for RdataEncoder::encode() with buffer overrun check.
|
|
void encodeWrapper(size_t data_len);
|
|
void encodeWrapper(size_t data_len);
|
|
|
|
|
|
// Some commonly used RDATA
|
|
// Some commonly used RDATA
|
|
@@ -161,15 +161,28 @@ public:
|
|
// in the wire format. It then compares the wire data with the one
|
|
// in the wire format. It then compares the wire data with the one
|
|
// generated by the normal libdns++ interface to see the encoding/decoding
|
|
// generated by the normal libdns++ interface to see the encoding/decoding
|
|
// works as intended.
|
|
// works as intended.
|
|
|
|
+ // By default it encodes the given RDATAs from the scratch; if old_data
|
|
|
|
+ // is non NULL, the test case assumes it points to previously encoded data
|
|
|
|
+ // and the given RDATAs are to be merged with it. old_rdata/rrsig_count
|
|
|
|
+ // will be set to the number of RDATAs and RRSIGs encoded in old_data.
|
|
|
|
+ // These "count" variables must not be set to non 0 unless old_data is
|
|
|
|
+ // non NULL, but it's not checked in this methods; it's the caller's
|
|
|
|
+ // responsibility to ensure that. rdata_list and rrsig_list should contain
|
|
|
|
+ // all RDATAs and RRSIGs included those stored in old_data.
|
|
void checkEncode(RRClass rrclass, RRType rrtype,
|
|
void checkEncode(RRClass rrclass, RRType rrtype,
|
|
const vector<ConstRdataPtr>& rdata_list,
|
|
const vector<ConstRdataPtr>& rdata_list,
|
|
size_t expected_varlen_fields,
|
|
size_t expected_varlen_fields,
|
|
const vector<ConstRdataPtr>& rrsig_list =
|
|
const vector<ConstRdataPtr>& rrsig_list =
|
|
- vector<ConstRdataPtr>());
|
|
|
|
|
|
+ vector<ConstRdataPtr>(),
|
|
|
|
+ const void* old_data = NULL,
|
|
|
|
+ size_t old_rdata_count = 0,
|
|
|
|
+ size_t old_rrsig_count = 0);
|
|
|
|
|
|
void addRdataCommon(const vector<ConstRdataPtr>& rrsigs);
|
|
void addRdataCommon(const vector<ConstRdataPtr>& rrsigs);
|
|
void addRdataMultiCommon(const vector<ConstRdataPtr>& rrsigs,
|
|
void addRdataMultiCommon(const vector<ConstRdataPtr>& rrsigs,
|
|
bool duplicate = false);
|
|
bool duplicate = false);
|
|
|
|
+ void mergeRdataCommon(const vector<ConstRdataPtr>& old_rrsigs,
|
|
|
|
+ const vector<ConstRdataPtr>& rrsigs);
|
|
};
|
|
};
|
|
|
|
|
|
// Used across more classes and scopes. But it's just uninteresting
|
|
// Used across more classes and scopes. But it's just uninteresting
|
|
@@ -275,11 +288,12 @@ public:
|
|
size_t rdata_count,
|
|
size_t rdata_count,
|
|
size_t rrsig_count,
|
|
size_t rrsig_count,
|
|
size_t expected_varlen_fields,
|
|
size_t expected_varlen_fields,
|
|
- // Warning: this test actualy might change the
|
|
|
|
- // encoded_data !
|
|
|
|
- vector<uint8_t>& encoded_data, size_t,
|
|
|
|
|
|
+ const vector<uint8_t>& encoded_data_orig, size_t,
|
|
MessageRenderer& renderer)
|
|
MessageRenderer& renderer)
|
|
{
|
|
{
|
|
|
|
+ // Make a manual copy, which we're going to modify.
|
|
|
|
+ vector<uint8_t> encoded_data = encoded_data_orig;
|
|
|
|
+
|
|
// If this type of RDATA is expected to contain variable-length fields,
|
|
// If this type of RDATA is expected to contain variable-length fields,
|
|
// we brute force the encoded data, exploiting our knowledge of actual
|
|
// we brute force the encoded data, exploiting our knowledge of actual
|
|
// encoding, then adjust the encoded data excluding the list of length
|
|
// encoding, then adjust the encoded data excluding the list of length
|
|
@@ -546,7 +560,9 @@ RdataEncodeDecodeTest<DecoderStyle>::
|
|
checkEncode(RRClass rrclass, RRType rrtype,
|
|
checkEncode(RRClass rrclass, RRType rrtype,
|
|
const vector<ConstRdataPtr>& rdata_list,
|
|
const vector<ConstRdataPtr>& rdata_list,
|
|
size_t expected_varlen_fields,
|
|
size_t expected_varlen_fields,
|
|
- const vector<ConstRdataPtr>& rrsig_list)
|
|
|
|
|
|
+ const vector<ConstRdataPtr>& rrsig_list,
|
|
|
|
+ const void* old_data, size_t old_rdata_count,
|
|
|
|
+ size_t old_rrsig_count)
|
|
{
|
|
{
|
|
// These two names will be rendered before and after the test RDATA,
|
|
// These two names will be rendered before and after the test RDATA,
|
|
// to check in case the RDATA contain a domain name whether it's
|
|
// to check in case the RDATA contain a domain name whether it's
|
|
@@ -586,13 +602,25 @@ checkEncode(RRClass rrclass, RRType rrtype,
|
|
// 1st dummy name
|
|
// 1st dummy name
|
|
actual_renderer_.writeName(dummy_name);
|
|
actual_renderer_.writeName(dummy_name);
|
|
|
|
|
|
- // Create encoded data
|
|
|
|
- encoder_.start(rrclass, rrtype);
|
|
|
|
|
|
+ // Create encoded data. If old_xxx_count > 0, that part should be in
|
|
|
|
+ // old_data, so should be excluded from addRdata/addSIGRdata.
|
|
|
|
+ if (old_data) {
|
|
|
|
+ encoder_.start(rrclass, rrtype, old_data, old_rdata_count,
|
|
|
|
+ old_rrsig_count);
|
|
|
|
+ } else {
|
|
|
|
+ encoder_.start(rrclass, rrtype);
|
|
|
|
+ }
|
|
|
|
+ size_t count = 0;
|
|
BOOST_FOREACH(const ConstRdataPtr& rdata, rdata_list) {
|
|
BOOST_FOREACH(const ConstRdataPtr& rdata, rdata_list) {
|
|
- encoder_.addRdata(*rdata);
|
|
|
|
|
|
+ if (++count > old_rdata_count) {
|
|
|
|
+ encoder_.addRdata(*rdata);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ count = 0;
|
|
BOOST_FOREACH(const ConstRdataPtr& rdata, rrsig_list) {
|
|
BOOST_FOREACH(const ConstRdataPtr& rdata, rrsig_list) {
|
|
- encoder_.addSIGRdata(*rdata);
|
|
|
|
|
|
+ if (++count > old_rrsig_count) {
|
|
|
|
+ encoder_.addSIGRdata(*rdata);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
const size_t storage_len = encoder_.getStorageLength();
|
|
const size_t storage_len = encoder_.getStorageLength();
|
|
encodeWrapper(storage_len);
|
|
encodeWrapper(storage_len);
|
|
@@ -824,6 +852,64 @@ TEST_F(RdataSerializationTest, badAddRdata) {
|
|
isc::BadValue);
|
|
isc::BadValue);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+template<class DecoderStyle>
|
|
|
|
+void
|
|
|
|
+RdataEncodeDecodeTest<DecoderStyle>::
|
|
|
|
+mergeRdataCommon(const vector<ConstRdataPtr>& old_rrsigs,
|
|
|
|
+ const vector<ConstRdataPtr>& rrsigs)
|
|
|
|
+{
|
|
|
|
+ // Test with fixed-length old RDATA
|
|
|
|
+ rdata_list_.clear();
|
|
|
|
+ rdata_list_.push_back(a_rdata_);
|
|
|
|
+ checkEncode(RRClass::IN(), RRType::A(), rdata_list_, 0, old_rrsigs);
|
|
|
|
+ vector<uint8_t> old_encoded_data = encoded_data_;
|
|
|
|
+
|
|
|
|
+ ConstRdataPtr a_rdata2 = createRdata(RRType::A(), RRClass::IN(),
|
|
|
|
+ "192.0.2.54");
|
|
|
|
+ rdata_list_.push_back(a_rdata2);
|
|
|
|
+ vector<ConstRdataPtr> rrsigs_all = old_rrsigs;
|
|
|
|
+ rrsigs_all.insert(rrsigs_all.end(), rrsigs.begin(), rrsigs.end());
|
|
|
|
+ checkEncode(RRClass::IN(), RRType::A(), rdata_list_, 0, rrsigs_all,
|
|
|
|
+ &old_encoded_data[0], 1, old_rrsigs.size());
|
|
|
|
+
|
|
|
|
+ // Test with variable-length old RDATA
|
|
|
|
+ rdata_list_.clear();
|
|
|
|
+ rrsigs_all.clear();
|
|
|
|
+ ConstRdataPtr txt_rdata1 = createRdata(RRType::TXT(), RRClass::IN(),
|
|
|
|
+ "foo bar baz");
|
|
|
|
+ rdata_list_.push_back(txt_rdata1);
|
|
|
|
+ checkEncode(RRClass::IN(), RRType::TXT(), rdata_list_, 1, old_rrsigs);
|
|
|
|
+ old_encoded_data = encoded_data_;
|
|
|
|
+
|
|
|
|
+ ConstRdataPtr txt_rdata2 = createRdata(RRType::TXT(), RRClass::IN(),
|
|
|
|
+ "another text data");
|
|
|
|
+ rdata_list_.push_back(txt_rdata2);
|
|
|
|
+ rrsigs_all.insert(rrsigs_all.end(), rrsigs.begin(), rrsigs.end());
|
|
|
|
+ checkEncode(RRClass::IN(), RRType::TXT(), rdata_list_, 1, rrsigs_all,
|
|
|
|
+ &old_encoded_data[0], 1, old_rrsigs.size());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TYPED_TEST(RdataEncodeDecodeTest, mergeRdata) {
|
|
|
|
+ vector<ConstRdataPtr> old_rrsigs;
|
|
|
|
+ vector<ConstRdataPtr> rrsigs;
|
|
|
|
+
|
|
|
|
+ // Test without RRSIGs, either for old or new.
|
|
|
|
+ this->mergeRdataCommon(old_rrsigs, rrsigs);
|
|
|
|
+
|
|
|
|
+ // Test without RRSIG for old and with RRSIG for new.
|
|
|
|
+ rrsigs.push_back(this->rrsig_rdata_);
|
|
|
|
+ this->mergeRdataCommon(old_rrsigs, rrsigs);
|
|
|
|
+
|
|
|
|
+#if 0
|
|
|
|
+ // Tests with two RRSIGs
|
|
|
|
+ rrsigs.push_back(this->rrsig_rdata_);
|
|
|
|
+ rrsigs.push_back(createRdata(RRType::RRSIG(), RRClass::IN(),
|
|
|
|
+ "A 5 2 3600 20120814220826 "
|
|
|
|
+ "20120715220826 54321 com. FAKE"));
|
|
|
|
+ this->addRdataMultiCommon(rrsigs);
|
|
|
|
+#endif
|
|
|
|
+}
|
|
|
|
+
|
|
void
|
|
void
|
|
checkSigData(const ConstRdataPtr& decoded, bool* called, const void* encoded,
|
|
checkSigData(const ConstRdataPtr& decoded, bool* called, const void* encoded,
|
|
size_t length)
|
|
size_t length)
|