| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DNS_DNS_TEST_UTIL_H_ | 5 #ifndef NET_DNS_DNS_TEST_UTIL_H_ |
| 6 #define NET_DNS_DNS_TEST_UTIL_H_ | 6 #define NET_DNS_DNS_TEST_UTIL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "net/base/dns_util.h" | 13 #include "net/base/dns_util.h" |
| 14 #include "net/base/host_resolver.h" | 14 #include "net/base/host_resolver.h" |
| 15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "net/dns/dns_protocol.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 // DNS related classes make use of PRNG for various tasks. This class is | |
| 21 // used as a PRNG for unit testing those tasks. It takes a deque of | |
| 22 // integers |numbers| which should be returned by calls to GetNext. | |
| 23 class TestPrng { | |
| 24 public: | |
| 25 explicit TestPrng(const std::deque<int>& numbers); | |
| 26 ~TestPrng(); | |
| 27 | |
| 28 // Pops and returns the next number from |numbers_| deque. | |
| 29 int GetNext(int min, int max); | |
| 30 | |
| 31 private: | |
| 32 std::deque<int> numbers_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(TestPrng); | |
| 35 }; | |
| 36 | |
| 37 // A utility function for tests that given an array of IP literals, | 21 // A utility function for tests that given an array of IP literals, |
| 38 // converts it to an IPAddressList. | 22 // converts it to an IPAddressList. |
| 39 bool ConvertStringsToIPAddressList( | 23 bool ConvertStringsToIPAddressList( |
| 40 const char* const ip_strings[], size_t size, IPAddressList* address_list); | 24 const char* const ip_strings[], size_t size, IPAddressList* address_list); |
| 41 | 25 |
| 42 // A utility function for tests that creates an IPEndPoint whose IP is | 26 // A utility function for tests that creates an IPEndPoint whose IP is |
| 43 // |ip_string| and whose port is |port| and stores it in |endpoint|. | 27 // |ip_string| and whose port is |port| and stores it in |endpoint|. |
| 44 bool CreateDnsAddress(const char* ip_string, uint16 port, IPEndPoint* endpoint); | 28 bool CreateDnsAddress(const char* ip_string, uint16 port, IPEndPoint* endpoint); |
| 45 | 29 |
| 46 static const char kDnsIp[] = "192.168.1.1"; | 30 static const char kDnsIp[] = "192.168.1.1"; |
| 47 static const uint16 kDnsPort = 53; | 31 static const uint16 kDnsPort = 53; |
| 48 | 32 |
| 49 //----------------------------------------------------------------------------- | 33 //----------------------------------------------------------------------------- |
| 50 // Query/response set for www.google.com, ID is fixed to 0. | 34 // Query/response set for www.google.com, ID is fixed to 0. |
| 51 static const char kT0HostName[] = "www.google.com"; | 35 static const char kT0HostName[] = "www.google.com"; |
| 52 static const uint16 kT0Qtype = kDNS_A; | 36 static const uint16 kT0Qtype = dns_protocol::kTypeA; |
| 53 static const char kT0DnsName[] = { | 37 static const char kT0DnsName[] = { |
| 54 0x03, 'w', 'w', 'w', | 38 0x03, 'w', 'w', 'w', |
| 55 0x06, 'g', 'o', 'o', 'g', 'l', 'e', | 39 0x06, 'g', 'o', 'o', 'g', 'l', 'e', |
| 56 0x03, 'c', 'o', 'm', | 40 0x03, 'c', 'o', 'm', |
| 57 0x00 | 41 0x00 |
| 58 }; | 42 }; |
| 59 static const uint8 kT0QueryDatagram[] = { | 43 static const uint8 kT0QueryDatagram[] = { |
| 60 // query for www.google.com, type A. | 44 // query for www.google.com, type A. |
| 61 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 45 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 62 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, | 46 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 85 0x4a, 0x7d, 0xe2, 0xb2 | 69 0x4a, 0x7d, 0xe2, 0xb2 |
| 86 }; | 70 }; |
| 87 static const char* const kT0IpAddresses[] = { | 71 static const char* const kT0IpAddresses[] = { |
| 88 "74.125.226.179", "74.125.226.180", "74.125.226.176", | 72 "74.125.226.179", "74.125.226.180", "74.125.226.176", |
| 89 "74.125.226.177", "74.125.226.178" | 73 "74.125.226.177", "74.125.226.178" |
| 90 }; | 74 }; |
| 91 | 75 |
| 92 //----------------------------------------------------------------------------- | 76 //----------------------------------------------------------------------------- |
| 93 // Query/response set for codereview.chromium.org, ID is fixed to 1. | 77 // Query/response set for codereview.chromium.org, ID is fixed to 1. |
| 94 static const char kT1HostName[] = "codereview.chromium.org"; | 78 static const char kT1HostName[] = "codereview.chromium.org"; |
| 95 static const uint16 kT1Qtype = kDNS_A; | 79 static const uint16 kT1Qtype = dns_protocol::kTypeA; |
| 96 static const char kT1DnsName[] = { | 80 static const char kT1DnsName[] = { |
| 97 0x12, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', | 81 0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', |
| 98 0x10, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', | 82 0x08, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', |
| 99 0x03, 'o', 'r', 'g', | 83 0x03, 'o', 'r', 'g', |
| 100 0x00 | 84 0x00 |
| 101 }; | 85 }; |
| 102 static const uint8 kT1QueryDatagram[] = { | 86 static const uint8 kT1QueryDatagram[] = { |
| 103 // query for codereview.chromium.org, type A. | 87 // query for codereview.chromium.org, type A. |
| 104 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 88 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 105 0x00, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, 0x64, | 89 0x00, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, 0x64, |
| 106 0x65, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 0x08, | 90 0x65, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 0x08, |
| 107 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x69, 0x75, 0x6d, | 91 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x69, 0x75, 0x6d, |
| 108 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, | 92 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 0x35, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, | 107 0x35, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, |
| 124 0x0b, 0x00, 0x04, 0x40, 0xe9, 0xa9, 0x79 | 108 0x0b, 0x00, 0x04, 0x40, 0xe9, 0xa9, 0x79 |
| 125 }; | 109 }; |
| 126 static const char* const kT1IpAddresses[] = { | 110 static const char* const kT1IpAddresses[] = { |
| 127 "64.233.169.121" | 111 "64.233.169.121" |
| 128 }; | 112 }; |
| 129 | 113 |
| 130 //----------------------------------------------------------------------------- | 114 //----------------------------------------------------------------------------- |
| 131 // Query/response set for www.ccs.neu.edu, ID is fixed to 2. | 115 // Query/response set for www.ccs.neu.edu, ID is fixed to 2. |
| 132 static const char kT2HostName[] = "www.ccs.neu.edu"; | 116 static const char kT2HostName[] = "www.ccs.neu.edu"; |
| 133 static const uint16 kT2Qtype = kDNS_A; | 117 static const uint16 kT2Qtype = dns_protocol::kTypeA; |
| 134 static const char kT2DnsName[] = { | 118 static const char kT2DnsName[] = { |
| 135 0x03, 'w', 'w', 'w', | 119 0x03, 'w', 'w', 'w', |
| 136 0x03, 'c', 'c', 'c', | 120 0x03, 'c', 'c', 's', |
| 137 0x03, 'n', 'e', 'u', | 121 0x03, 'n', 'e', 'u', |
| 138 0x03, 'e', 'd', 'u', | 122 0x03, 'e', 'd', 'u', |
| 139 0x00 | 123 0x00 |
| 140 }; | 124 }; |
| 141 static const uint8 kT2QueryDatagram[] = { | 125 static const uint8 kT2QueryDatagram[] = { |
| 142 // query for www.ccs.neu.edu, type A. | 126 // query for www.ccs.neu.edu, type A. |
| 143 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 127 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 144 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, | 128 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| 145 0x03, 0x63, 0x63, 0x73, 0x03, 0x6e, 0x65, 0x75, | 129 0x03, 0x63, 0x63, 0x73, 0x03, 0x6e, 0x65, 0x75, |
| 146 0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01, 0x00, | 130 0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01, 0x00, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 159 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, | 143 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, |
| 160 0x00, 0x04, 0x81, 0x0a, 0x74, 0x51 | 144 0x00, 0x04, 0x81, 0x0a, 0x74, 0x51 |
| 161 }; | 145 }; |
| 162 static const char* const kT2IpAddresses[] = { | 146 static const char* const kT2IpAddresses[] = { |
| 163 "129.10.116.81" | 147 "129.10.116.81" |
| 164 }; | 148 }; |
| 165 | 149 |
| 166 //----------------------------------------------------------------------------- | 150 //----------------------------------------------------------------------------- |
| 167 // Query/response set for www.google.az, ID is fixed to 3. | 151 // Query/response set for www.google.az, ID is fixed to 3. |
| 168 static const char kT3HostName[] = "www.google.az"; | 152 static const char kT3HostName[] = "www.google.az"; |
| 169 static const uint16 kT3Qtype = kDNS_A; | 153 static const uint16 kT3Qtype = dns_protocol::kTypeA; |
| 170 static const char kT3DnsName[] = { | 154 static const char kT3DnsName[] = { |
| 171 0x03, 'w', 'w', 'w', | 155 0x03, 'w', 'w', 'w', |
| 172 0x06, 'g', 'o', 'o', 'g', 'l', 'e', | 156 0x06, 'g', 'o', 'o', 'g', 'l', 'e', |
| 173 0x02, 'a', 'z', | 157 0x02, 'a', 'z', |
| 174 0x00 | 158 0x00 |
| 175 }; | 159 }; |
| 176 static const uint8 kT3QueryDatagram[] = { | 160 static const uint8 kT3QueryDatagram[] = { |
| 177 // query for www.google.az, type A. | 161 // query for www.google.az, type A. |
| 178 0x00, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 162 0x00, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 179 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, | 163 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 206 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1 | 190 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1 |
| 207 }; | 191 }; |
| 208 static const char* const kT3IpAddresses[] = { | 192 static const char* const kT3IpAddresses[] = { |
| 209 "74.125.226.178", "74.125.226.179", "74.125.226.180", | 193 "74.125.226.178", "74.125.226.179", "74.125.226.180", |
| 210 "74.125.226.176", "74.125.226.177" | 194 "74.125.226.176", "74.125.226.177" |
| 211 }; | 195 }; |
| 212 | 196 |
| 213 } // namespace net | 197 } // namespace net |
| 214 | 198 |
| 215 #endif // NET_DNS_DNS_TEST_UTIL_H_ | 199 #endif // NET_DNS_DNS_TEST_UTIL_H_ |
| OLD | NEW |