]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/tests/unit/dns_test.cc
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
20 * Copyright (C) 2016 ScyllaDB.
25 #include <seastar/core/do_with.hh>
26 #include <seastar/testing/test_case.hh>
27 #include <seastar/core/sstring.hh>
28 #include <seastar/core/reactor.hh>
29 #include <seastar/core/do_with.hh>
30 #include <seastar/core/future-util.hh>
31 #include <seastar/net/dns.hh>
32 #include <seastar/net/inet_address.hh>
34 using namespace seastar
;
35 using namespace seastar::net
;
37 static const inet_address google_addr
= inet_address("216.58.201.164");
38 static const sstring google_name
= "www.google.com";
40 static future
<> test_resolve(dns_resolver::options opts
) {
41 auto d
= ::make_lw_shared
<dns_resolver
>(std::move(opts
));
42 return d
->get_host_by_name(google_name
, inet_address::family::INET
).then([d
](hostent e
) {
43 //BOOST_REQUIRE(std::count(e.addr_list.begin(), e.addr_list.end(), google_addr));
44 return d
->get_host_by_addr(e
.addr_list
.front()).then([d
, a
= e
.addr_list
.front()](hostent e
) {
45 return d
->get_host_by_name(e
.names
.front(), inet_address::family::INET
).then([a
](hostent e
) {
46 BOOST_REQUIRE(std::count(e
.addr_list
.begin(), e
.addr_list
.end(), a
));
54 static future
<> test_bad_name(dns_resolver::options opts
) {
55 auto d
= ::make_lw_shared
<dns_resolver
>(std::move(opts
));
56 return d
->get_host_by_name("apa.ninja.gnu", inet_address::family::INET
).then_wrapped([d
](future
<hostent
> f
) {
59 BOOST_FAIL("should not succeed");
68 SEASTAR_TEST_CASE(test_resolve_udp
) {
69 return test_resolve(dns_resolver::options());
72 SEASTAR_TEST_CASE(test_bad_name_udp
) {
73 return test_bad_name(dns_resolver::options());
76 SEASTAR_TEST_CASE(test_timeout_udp
) {
77 dns_resolver::options opts
;
78 opts
.servers
= std::vector
<inet_address
>({ inet_address("1.2.3.4") }); // not a server
79 opts
.udp_port
= 29953; // not a dns port
80 opts
.timeout
= std::chrono::milliseconds(500);
82 auto d
= ::make_lw_shared
<dns_resolver
>(engine().net(), opts
);
83 return d
->get_host_by_name(google_name
, inet_address::family::INET
).then_wrapped([d
](future
<hostent
> f
) {
86 BOOST_FAIL("should not succeed");
95 // Currently failing, disable until fixed (#521)
97 SEASTAR_TEST_CASE(test_resolve_tcp
) {
98 dns_resolver::options opts
;
99 opts
.use_tcp_query
= true;
100 return test_resolve(opts
);
104 SEASTAR_TEST_CASE(test_bad_name_tcp
) {
105 dns_resolver::options opts
;
106 opts
.use_tcp_query
= true;
107 return test_bad_name(opts
);
110 static const sstring imaps_service
= "imaps";
111 static const sstring gmail_domain
= "gmail.com";
113 static future
<> test_srv() {
114 auto d
= ::make_lw_shared
<dns_resolver
>();
115 return d
->get_srv_records(dns_resolver::srv_proto::tcp
,
117 gmail_domain
).then([d
](dns_resolver::srv_records records
) {
118 BOOST_REQUIRE(!records
.empty());
119 for (auto& record
: records
) {
120 // record.target should end with "gmail.com"
121 BOOST_REQUIRE_GT(record
.target
.size(), gmail_domain
.size());
122 BOOST_REQUIRE_EQUAL(record
.target
.compare(record
.target
.size() - gmail_domain
.size(),
132 SEASTAR_TEST_CASE(test_srv_tcp
) {