OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <resolv.h> | 5 #include <resolv.h> |
6 | 6 |
7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
8 #include "net/dns/dns_config_service_posix.h" | 8 #include "net/dns/dns_config_service_posix.h" |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 ASSERT_TRUE(internal::ConvertResStateToDnsConfig(res, &config)); | 115 ASSERT_TRUE(internal::ConvertResStateToDnsConfig(res, &config)); |
116 CloseResState(&res); | 116 CloseResState(&res); |
117 EXPECT_TRUE(config.IsValid()); | 117 EXPECT_TRUE(config.IsValid()); |
118 | 118 |
119 DnsConfig expected_config; | 119 DnsConfig expected_config; |
120 EXPECT_FALSE(expected_config.EqualsIgnoreHosts(config)); | 120 EXPECT_FALSE(expected_config.EqualsIgnoreHosts(config)); |
121 InitializeExpectedConfig(&expected_config); | 121 InitializeExpectedConfig(&expected_config); |
122 EXPECT_TRUE(expected_config.EqualsIgnoreHosts(config)); | 122 EXPECT_TRUE(expected_config.EqualsIgnoreHosts(config)); |
123 } | 123 } |
124 | 124 |
| 125 TEST(DnsConfigServicePosixTest, RejectEmptyNameserver) { |
| 126 struct __res_state res = {}; |
| 127 res.options = RES_INIT; |
| 128 const char kDnsrch[] = "chromium.org"; |
| 129 memcpy(res.defdname, kDnsrch, sizeof(kDnsrch)); |
| 130 res.dnsrch[0] = res.defdname; |
| 131 |
| 132 struct sockaddr_in sa = {}; |
| 133 sa.sin_family = AF_INET; |
| 134 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT); |
| 135 sa.sin_addr.s_addr = INADDR_ANY; |
| 136 res.nsaddr_list[0] = sa; |
| 137 sa.sin_addr.s_addr = 0xCAFE1337; |
| 138 res.nsaddr_list[1] = sa; |
| 139 res.nscount = 2; |
| 140 |
| 141 DnsConfig config; |
| 142 EXPECT_FALSE(internal::ConvertResStateToDnsConfig(res, &config)); |
| 143 |
| 144 sa.sin_addr.s_addr = 0xDEADBEEF; |
| 145 res.nsaddr_list[0] = sa; |
| 146 EXPECT_TRUE(internal::ConvertResStateToDnsConfig(res, &config)); |
| 147 } |
| 148 |
125 } // namespace | 149 } // namespace |
126 } // namespace net | 150 } // namespace net |
OLD | NEW |