Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: net/base/dnsrr_resolver_unittest.cc

Issue 3029035: net: add DnsRRResovler to fetch arbitary DNS resource types. (Closed)
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/dnsrr_resolver.h"
6
7 #include "base/callback.h"
8 #include "base/condition_variable.h"
9 #include "base/lock.h"
10 #include "net/base/dns_util.h"
11 #include "net/base/net_errors.h"
12 #include "net/base/test_completion_callback.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace net {
16
17 class DnsRRResolverTest : public testing::Test {
18 };
19
20 #if defined(OS_LINUX)
21
22 class Rendezvous : public CallbackRunner<Tuple1<int> > {
23 public:
24 Rendezvous()
25 : have_result_(false),
26 cv_(&lock_) {
27 }
28
29 int WaitForResult() {
30 lock_.Acquire();
31 while (!have_result_)
32 cv_.Wait();
33 lock_.Release();
34 return result_;
35 }
36
37 virtual void RunWithParams(const Tuple1<int>& params) {
38 lock_.Acquire();
39 result_ = params.a;
40 have_result_ = true;
41 lock_.Release();
42 cv_.Broadcast();
43 }
44
45 private:
46 bool have_result_;
47 int result_;
48 Lock lock_;
49 ConditionVariable cv_;
50 };
51
52 // This test is disabled because it depends on the external network to pass.
53 // However, it may be useful when chaging the code.
54 #if 0
55 TEST_F(DnsRRResolverTest, NetworkResolve) {
56 DnsRRResolver::Response response;
57 Rendezvous callback;
58 ASSERT_TRUE(DnsRRResolver::Resolve(
59 "agl._pka.imperialviolet.org", kDNS_TXT, 0, &callback, &response));
60 ASSERT_EQ(OK, callback.WaitForResult());
61 ASSERT_EQ(1u, response.rrdatas.size());
62 ASSERT_EQ(1u, response.signatures.size());
63 ASSERT_STREQ("]v=pka1;fpr=2AF0032B48E856CE06157A1AD43C670DE04AAA74;"
64 "uri=http://www.imperialviolet.org/key.asc",
65 response.rrdatas[0].c_str());
66 }
67 #endif
68
69 static const uint8 kExamplePacket[] = {
70 0xce, 0xfe, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x06, 0x00, 0x01, 0x03,
Mike Belshe 2010/08/02 14:18:28 Holy smokes! Since you managed to generate this s
71 0x61, 0x67, 0x6c, 0x04, 0x5f, 0x70, 0x6b, 0x61, 0x0e, 0x69, 0x6d, 0x70, 0x65,
72 0x72, 0x69, 0x61, 0x6c, 0x76, 0x69, 0x6f, 0x6c, 0x65, 0x74, 0x03, 0x6f, 0x72,
73 0x67, 0x00, 0x00, 0x10, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x10, 0x00, 0x01, 0x00,
74 0x00, 0x01, 0x2c, 0x00, 0x5e, 0x5d, 0x76, 0x3d, 0x70, 0x6b, 0x61, 0x31, 0x3b,
75 0x66, 0x70, 0x72, 0x3d, 0x32, 0x41, 0x46, 0x30, 0x30, 0x33, 0x32, 0x42, 0x34,
76 0x38, 0x45, 0x38, 0x35, 0x36, 0x43, 0x45, 0x30, 0x36, 0x31, 0x35, 0x37, 0x41,
77 0x31, 0x41, 0x44, 0x34, 0x33, 0x43, 0x36, 0x37, 0x30, 0x44, 0x45, 0x30, 0x34,
78 0x41, 0x41, 0x41, 0x37, 0x34, 0x3b, 0x75, 0x72, 0x69, 0x3d, 0x68, 0x74, 0x74,
79 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x6d, 0x70, 0x65, 0x72,
80 0x69, 0x61, 0x6c, 0x76, 0x69, 0x6f, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x67,
81 0x2f, 0x6b, 0x65, 0x79, 0x2e, 0x61, 0x73, 0x63, 0xc0, 0x0c, 0x00, 0x2e, 0x00,
82 0x01, 0x00, 0x00, 0x01, 0x2c, 0x00, 0xc6, 0x00, 0x10, 0x05, 0x04, 0x00, 0x01,
83 0x51, 0x80, 0x4c, 0x74, 0x2f, 0x1a, 0x4c, 0x4c, 0x9c, 0xeb, 0x45, 0xc9, 0x0e,
84 0x69, 0x6d, 0x70, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x76, 0x69, 0x6f, 0x6c, 0x65,
85 0x74, 0x03, 0x6f, 0x72, 0x67, 0x00, 0x3b, 0x6d, 0x3d, 0xbb, 0xae, 0x1b, 0x07,
86 0x8d, 0xa9, 0xb0, 0xa7, 0xa5, 0x7a, 0x84, 0x24, 0x34, 0x29, 0x43, 0x36, 0x3f,
87 0x5a, 0x48, 0x3b, 0x79, 0xa3, 0x16, 0xa4, 0x28, 0x5b, 0xd7, 0x03, 0xc6, 0x93,
88 0xba, 0x4e, 0x93, 0x4d, 0x18, 0x5c, 0x98, 0xc2, 0x0d, 0x57, 0xd2, 0x6b, 0x9a,
89 0x72, 0xbd, 0xe5, 0x8d, 0x10, 0x7b, 0x03, 0xe7, 0x19, 0x1e, 0x51, 0xe5, 0x7e,
90 0x49, 0x6b, 0xa3, 0xa8, 0xf1, 0xd3, 0x1b, 0xff, 0x40, 0x26, 0x82, 0x65, 0xd0,
91 0x74, 0x8e, 0xcf, 0xc9, 0x71, 0xea, 0x91, 0x57, 0x7e, 0x50, 0x61, 0x4d, 0x4b,
92 0x77, 0x05, 0x6a, 0xd8, 0x3f, 0x12, 0x87, 0x50, 0xc2, 0x35, 0x13, 0xab, 0x01,
93 0x78, 0xd2, 0x3a, 0x55, 0xa2, 0x89, 0xc8, 0x87, 0xe2, 0x7b, 0xec, 0x51, 0x7c,
94 0xc0, 0x24, 0xb5, 0xa3, 0x33, 0x78, 0x98, 0x28, 0x8e, 0x9b, 0x6b, 0x88, 0x13,
95 0x25, 0xfa, 0x1d, 0xdc, 0xf1, 0xf0, 0xa6, 0x8d, 0x2a, 0xbb, 0xbc, 0xb0, 0xc7,
96 0x97, 0x98, 0x8e, 0xef, 0xd9, 0x12, 0x24, 0xee, 0x38, 0x50, 0xdb, 0xd3, 0x59,
97 0xcc, 0x30, 0x54, 0x4c, 0x38, 0x94, 0x24, 0xbc, 0x75, 0xa5, 0xc0, 0xc4, 0x00,
98 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x15, 0x02, 0x62, 0x30, 0x03,
99 0x6f, 0x72, 0x67, 0x0b, 0x61, 0x66, 0x69, 0x6c, 0x69, 0x61, 0x73, 0x2d, 0x6e,
100 0x73, 0x74, 0xc0, 0xc4, 0xc0, 0xc4, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
101 0x3a, 0x00, 0x19, 0x02, 0x63, 0x30, 0x03, 0x6f, 0x72, 0x67, 0x0b, 0x61, 0x66,
102 0x69, 0x6c, 0x69, 0x61, 0x73, 0x2d, 0x6e, 0x73, 0x74, 0x04, 0x69, 0x6e, 0x66,
103 0x6f, 0x00, 0xc0, 0xc4, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3a, 0x00,
104 0x05, 0x02, 0x61, 0x30, 0xc1, 0x99, 0xc0, 0xc4, 0x00, 0x02, 0x00, 0x01, 0x00,
105 0x00, 0x00, 0x3a, 0x00, 0x05, 0x02, 0x62, 0x32, 0xc1, 0x78, 0xc0, 0xc4, 0x00,
106 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x05, 0x02, 0x64, 0x30, 0xc1,
107 0x78, 0xc0, 0xc4, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x05,
108 0x02, 0x61, 0x32, 0xc1, 0x99, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x80,
109 0x00, 0x00, 0x00,
110 };
111
112 TEST_F(DnsRRResolverTest, ParseExample) {
113 DnsRRResolver::Response response;
114 ASSERT_TRUE(response.ParseFromResponse(kExamplePacket,
115 sizeof(kExamplePacket), kDNS_TXT));
116 ASSERT_EQ(1u, response.rrdatas.size());
117 ASSERT_EQ(1u, response.signatures.size());
118 ASSERT_STREQ("agl._pka.imperialviolet.org", response.name.c_str());
119 ASSERT_STREQ("]v=pka1;fpr=2AF0032B48E856CE06157A1AD43C670DE04AAA74;"
120 "uri=http://www.imperialviolet.org/key.asc",
121 response.rrdatas[0].c_str());
122 ASSERT_FALSE(response.dnssec);
123 }
124
125 TEST_F(DnsRRResolverTest, FuzzTruncation) {
126 DnsRRResolver::Response response;
127
128 for (unsigned len = sizeof(kExamplePacket); len <= sizeof(kExamplePacket);
129 len--) {
130 response.ParseFromResponse(kExamplePacket, len, kDNS_TXT);
131 }
132 }
133
134 TEST_F(DnsRRResolverTest, FuzzCorruption) {
135 DnsRRResolver::Response response;
136 uint8 copy[sizeof(kExamplePacket)];
137
138
139 for (unsigned bit_to_corrupt = 0; bit_to_corrupt < sizeof(kExamplePacket) * 8;
140 bit_to_corrupt++) {
141 unsigned byte = bit_to_corrupt >> 3;
142 unsigned bit = bit_to_corrupt & 7;
143
144 memcpy(copy, kExamplePacket, sizeof(copy));
145 copy[byte] ^= (1 << bit);
146
147 response.ParseFromResponse(copy, sizeof(copy), kDNS_TXT);
148 }
149 }
150
151 #endif // OS_LINUX
152
153 } // namespace net
OLDNEW
« net/base/dnsrr_resolver.cc ('K') | « net/base/dnsrr_resolver.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698