1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for generic
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <util/buffer.h>
#include <dns/exceptions.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <gtest/gtest.h>
#include <dns/tests/unittest_util.h>
#include <dns/tests/rdata_unittest.h>
using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
using namespace isc::util;
using namespace isc::dns::rdata;
// minfo text
const char* const minfo_txt = "rmailbox.example.com. emailbox.example.com.";
const char* const minfo_txt2 = "root.example.com. emailbox.example.com.";
const char* const too_long_label = "01234567890123456789012345678901234567"
"89012345678901234567890123";
namespace {
class Rdata_MINFO_Test : public RdataTest {
public:
Rdata_MINFO_Test():
rdata_minfo(string(minfo_txt)), rdata_minfo2(string(minfo_txt2)) {}
const generic::MINFO rdata_minfo;
const generic::MINFO rdata_minfo2;
};
TEST_F(Rdata_MINFO_Test, createFromText) {
EXPECT_EQ(Name("rmailbox.example.com."), rdata_minfo.getRmailbox());
EXPECT_EQ(Name("emailbox.example.com."), rdata_minfo.getEmailbox());
EXPECT_EQ(Name("root.example.com."), rdata_minfo2.getRmailbox());
EXPECT_EQ(Name("emailbox.example.com."), rdata_minfo2.getEmailbox());
}
TEST_F(Rdata_MINFO_Test, badText) {
// incomplete text
EXPECT_THROW(generic::MINFO("root.example.com."),
InvalidRdataText);
// number of fields (must be 2) is incorrect
EXPECT_THROW(generic::MINFO("root.example.com emailbox.example.com. "
"example.com."),
InvalidRdataText);
// bad rmailbox name
EXPECT_THROW(generic::MINFO("root.example.com. emailbox.example.com." +
string(too_long_label)),
TooLongLabel);
// bad emailbox name
EXPECT_THROW(generic::MINFO("root.example.com." +
string(too_long_label) + " emailbox.example.com."),
TooLongLabel);
}
TEST_F(Rdata_MINFO_Test, createFromWire) {
// uncompressed names
EXPECT_EQ(0, rdata_minfo.compare(
*rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire1.wire")));
// compressed names
EXPECT_EQ(0, rdata_minfo.compare(
*rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire2.wire", 15)));
// RDLENGTH is too short
EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire3.wire"),
InvalidRdataLength);
// RDLENGTH is too long
EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire4.wire"),
InvalidRdataLength);
// bogus rmailbox name, the error should be detected in the name
// constructor
EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire5.wire"),
DNSMessageFORMERR);
// bogus emailbox name, the error should be detected in the name
// constructor
EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire6.wire"),
DNSMessageFORMERR);
}
TEST_F(Rdata_MINFO_Test, assignment) {
generic::MINFO copy((string(minfo_txt2)));
copy = rdata_minfo;
EXPECT_EQ(0, copy.compare(rdata_minfo));
// Check if the copied data is valid even after the original is deleted
generic::MINFO* copy2 = new generic::MINFO(rdata_minfo);
generic::MINFO copy3((string(minfo_txt2)));
copy3 = *copy2;
delete copy2;
EXPECT_EQ(0, copy3.compare(rdata_minfo));
// Self assignment
copy = copy;
EXPECT_EQ(0, copy.compare(rdata_minfo));
}
TEST_F(Rdata_MINFO_Test, toWireBuffer) {
rdata_minfo.toWire(obuffer);
vector<unsigned char> data;
UnitTestUtil::readWireData("rdata_minfo_toWireUncompressed1.wire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(obuffer.getData()),
obuffer.getLength(), &data[0], data.size());
obuffer.clear();
rdata_minfo2.toWire(obuffer);
vector<unsigned char> data2;
UnitTestUtil::readWireData("rdata_minfo_toWireUncompressed2.wire", data2);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(obuffer.getData()),
obuffer.getLength(), &data2[0], data2.size());
}
TEST_F(Rdata_MINFO_Test, toWireRenderer) {
rdata_minfo.toWire(renderer);
vector<unsigned char> data;
UnitTestUtil::readWireData("rdata_minfo_toWire1.wire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(renderer.getData()),
renderer.getLength(), &data[0], data.size());
renderer.clear();
rdata_minfo2.toWire(renderer);
vector<unsigned char> data2;
UnitTestUtil::readWireData("rdata_minfo_toWire2.wire", data2);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(renderer.getData()),
renderer.getLength(), &data2[0], data2.size());
}
TEST_F(Rdata_MINFO_Test, toText) {
EXPECT_EQ(minfo_txt, rdata_minfo.toText());
EXPECT_EQ(minfo_txt2, rdata_minfo2.toText());
}
TEST_F(Rdata_MINFO_Test, compare) {
// check reflexivity
EXPECT_EQ(0, rdata_minfo.compare(rdata_minfo));
// names must be compared in case-insensitive manner
EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("RMAILBOX.example.com. "
"emailbox.EXAMPLE.com.")));
// another MINFO whose rmailbox name is larger than that of rdata_minfo.
const generic::MINFO large1_minfo("zzzzzzzz.example.com. "
"emailbox.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large1_minfo));
EXPECT_LT(0, large1_minfo.compare(rdata_minfo));
// another MINFO whose emailbox name is larger than that of rdata_minfo.
const generic::MINFO large2_minfo("rmailbox.example.com. "
"zzzzzzzzzzz.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large2_minfo));
EXPECT_LT(0, large2_minfo.compare(rdata_minfo));
// comparison attempt between incompatible RR types should be rejected
EXPECT_THROW(rdata_minfo.compare(*RdataTest::rdata_nomatch), bad_cast);
}
}
|