| 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" | |
| 18 | 17 |
| 19 namespace net { | 18 namespace net { |
| 20 | 19 |
| 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 |
| 21 // A utility function for tests that given an array of IP literals, | 37 // A utility function for tests that given an array of IP literals, |
| 22 // converts it to an IPAddressList. | 38 // converts it to an IPAddressList. |
| 23 bool ConvertStringsToIPAddressList( | 39 bool ConvertStringsToIPAddressList( |
| 24 const char* const ip_strings[], size_t size, IPAddressList* address_list); | 40 const char* const ip_strings[], size_t size, IPAddressList* address_list); |
| 25 | 41 |
| 26 // A utility function for tests that creates an IPEndPoint whose IP is | 42 // A utility function for tests that creates an IPEndPoint whose IP is |
| 27 // |ip_string| and whose port is |port| and stores it in |endpoint|. | 43 // |ip_string| and whose port is |port| and stores it in |endpoint|. |
| 28 bool CreateDnsAddress(const char* ip_string, uint16 port, IPEndPoint* endpoint); | 44 bool CreateDnsAddress(const char* ip_string, uint16 port, IPEndPoint* endpoint); |
| 29 | 45 |
| 30 static const char kDnsIp[] = "192.168.1.1"; | 46 static const char kDnsIp[] = "192.168.1.1"; |
| 31 static const uint16 kDnsPort = 53; | 47 static const uint16 kDnsPort = 53; |
| 32 | 48 |
| 33 //----------------------------------------------------------------------------- | 49 //----------------------------------------------------------------------------- |
| 34 // Query/response set for www.google.com, ID is fixed to 0. | 50 // Query/response set for www.google.com, ID is fixed to 0. |
| 35 static const char kT0HostName[] = "www.google.com"; | 51 static const char kT0HostName[] = "www.google.com"; |
| 36 static const uint16 kT0Qtype = dns_protocol::kTypeA; | 52 static const uint16 kT0Qtype = kDNS_A; |
| 37 static const char kT0DnsName[] = { | 53 static const char kT0DnsName[] = { |
| 38 0x03, 'w', 'w', 'w', | 54 0x03, 'w', 'w', 'w', |
| 39 0x06, 'g', 'o', 'o', 'g', 'l', 'e', | 55 0x06, 'g', 'o', 'o', 'g', 'l', 'e', |
| 40 0x03, 'c', 'o', 'm', | 56 0x03, 'c', 'o', 'm', |
| 41 0x00 | 57 0x00 |
| 42 }; | 58 }; |
| 43 static const uint8 kT0QueryDatagram[] = { | 59 static const uint8 kT0QueryDatagram[] = { |
| 44 // query for www.google.com, type A. | 60 // query for www.google.com, type A. |
| 45 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 61 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 46 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, | 62 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 0x4a, 0x7d, 0xe2, 0xb2 | 85 0x4a, 0x7d, 0xe2, 0xb2 |
| 70 }; | 86 }; |
| 71 static const char* const kT0IpAddresses[] = { | 87 static const char* const kT0IpAddresses[] = { |
| 72 "74.125.226.179", "74.125.226.180", "74.125.226.176", | 88 "74.125.226.179", "74.125.226.180", "74.125.226.176", |
| 73 "74.125.226.177", "74.125.226.178" | 89 "74.125.226.177", "74.125.226.178" |
| 74 }; | 90 }; |
| 75 | 91 |
| 76 //----------------------------------------------------------------------------- | 92 //----------------------------------------------------------------------------- |
| 77 // Query/response set for codereview.chromium.org, ID is fixed to 1. | 93 // Query/response set for codereview.chromium.org, ID is fixed to 1. |
| 78 static const char kT1HostName[] = "codereview.chromium.org"; | 94 static const char kT1HostName[] = "codereview.chromium.org"; |
| 79 static const uint16 kT1Qtype = dns_protocol::kTypeA; | 95 static const uint16 kT1Qtype = kDNS_A; |
| 80 static const char kT1DnsName[] = { | 96 static const char kT1DnsName[] = { |
| 81 0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', | 97 0x12, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', |
| 82 0x08, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', | 98 0x10, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', |
| 83 0x03, 'o', 'r', 'g', | 99 0x03, 'o', 'r', 'g', |
| 84 0x00 | 100 0x00 |
| 85 }; | 101 }; |
| 86 static const uint8 kT1QueryDatagram[] = { | 102 static const uint8 kT1QueryDatagram[] = { |
| 87 // query for codereview.chromium.org, type A. | 103 // query for codereview.chromium.org, type A. |
| 88 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 104 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 89 0x00, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, 0x64, | 105 0x00, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, 0x64, |
| 90 0x65, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 0x08, | 106 0x65, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 0x08, |
| 91 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x69, 0x75, 0x6d, | 107 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x69, 0x75, 0x6d, |
| 92 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, | 108 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 0x35, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, | 123 0x35, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, |
| 108 0x0b, 0x00, 0x04, 0x40, 0xe9, 0xa9, 0x79 | 124 0x0b, 0x00, 0x04, 0x40, 0xe9, 0xa9, 0x79 |
| 109 }; | 125 }; |
| 110 static const char* const kT1IpAddresses[] = { | 126 static const char* const kT1IpAddresses[] = { |
| 111 "64.233.169.121" | 127 "64.233.169.121" |
| 112 }; | 128 }; |
| 113 | 129 |
| 114 //----------------------------------------------------------------------------- | 130 //----------------------------------------------------------------------------- |
| 115 // Query/response set for www.ccs.neu.edu, ID is fixed to 2. | 131 // Query/response set for www.ccs.neu.edu, ID is fixed to 2. |
| 116 static const char kT2HostName[] = "www.ccs.neu.edu"; | 132 static const char kT2HostName[] = "www.ccs.neu.edu"; |
| 117 static const uint16 kT2Qtype = dns_protocol::kTypeA; | 133 static const uint16 kT2Qtype = kDNS_A; |
| 118 static const char kT2DnsName[] = { | 134 static const char kT2DnsName[] = { |
| 119 0x03, 'w', 'w', 'w', | 135 0x03, 'w', 'w', 'w', |
| 120 0x03, 'c', 'c', 's', | 136 0x03, 'c', 'c', 'c', |
| 121 0x03, 'n', 'e', 'u', | 137 0x03, 'n', 'e', 'u', |
| 122 0x03, 'e', 'd', 'u', | 138 0x03, 'e', 'd', 'u', |
| 123 0x00 | 139 0x00 |
| 124 }; | 140 }; |
| 125 static const uint8 kT2QueryDatagram[] = { | 141 static const uint8 kT2QueryDatagram[] = { |
| 126 // query for www.ccs.neu.edu, type A. | 142 // query for www.ccs.neu.edu, type A. |
| 127 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 143 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 128 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, | 144 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| 129 0x03, 0x63, 0x63, 0x73, 0x03, 0x6e, 0x65, 0x75, | 145 0x03, 0x63, 0x63, 0x73, 0x03, 0x6e, 0x65, 0x75, |
| 130 0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01, 0x00, | 146 0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01, 0x00, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 143 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, | 159 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, |
| 144 0x00, 0x04, 0x81, 0x0a, 0x74, 0x51 | 160 0x00, 0x04, 0x81, 0x0a, 0x74, 0x51 |
| 145 }; | 161 }; |
| 146 static const char* const kT2IpAddresses[] = { | 162 static const char* const kT2IpAddresses[] = { |
| 147 "129.10.116.81" | 163 "129.10.116.81" |
| 148 }; | 164 }; |
| 149 | 165 |
| 150 //----------------------------------------------------------------------------- | 166 //----------------------------------------------------------------------------- |
| 151 // Query/response set for www.google.az, ID is fixed to 3. | 167 // Query/response set for www.google.az, ID is fixed to 3. |
| 152 static const char kT3HostName[] = "www.google.az"; | 168 static const char kT3HostName[] = "www.google.az"; |
| 153 static const uint16 kT3Qtype = dns_protocol::kTypeA; | 169 static const uint16 kT3Qtype = kDNS_A; |
| 154 static const char kT3DnsName[] = { | 170 static const char kT3DnsName[] = { |
| 155 0x03, 'w', 'w', 'w', | 171 0x03, 'w', 'w', 'w', |
| 156 0x06, 'g', 'o', 'o', 'g', 'l', 'e', | 172 0x06, 'g', 'o', 'o', 'g', 'l', 'e', |
| 157 0x02, 'a', 'z', | 173 0x02, 'a', 'z', |
| 158 0x00 | 174 0x00 |
| 159 }; | 175 }; |
| 160 static const uint8 kT3QueryDatagram[] = { | 176 static const uint8 kT3QueryDatagram[] = { |
| 161 // query for www.google.az, type A. | 177 // query for www.google.az, type A. |
| 162 0x00, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, | 178 0x00, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 163 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, | 179 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 190 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1 | 206 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1 |
| 191 }; | 207 }; |
| 192 static const char* const kT3IpAddresses[] = { | 208 static const char* const kT3IpAddresses[] = { |
| 193 "74.125.226.178", "74.125.226.179", "74.125.226.180", | 209 "74.125.226.178", "74.125.226.179", "74.125.226.180", |
| 194 "74.125.226.176", "74.125.226.177" | 210 "74.125.226.176", "74.125.226.177" |
| 195 }; | 211 }; |
| 196 | 212 |
| 197 } // namespace net | 213 } // namespace net |
| 198 | 214 |
| 199 #endif // NET_DNS_DNS_TEST_UTIL_H_ | 215 #endif // NET_DNS_DNS_TEST_UTIL_H_ |
| OLD | NEW |