You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

139 lines
5.0 KiB

  1. #define BOOST_TEST_DYN_LINK
  2. #include <boost/test/unit_test.hpp>
  3. #include "test-syncres_cc.hh"
  4. BOOST_AUTO_TEST_SUITE(syncres_cc10)
  5. BOOST_AUTO_TEST_CASE(test_outgoing_v4_only)
  6. {
  7. std::unique_ptr<SyncRes> sr;
  8. initSR(sr);
  9. SyncRes::s_doIPv6 = false;
  10. primeHints();
  11. bool v6Hit = false;
  12. bool v4Hit = false;
  13. int queries = 0;
  14. const DNSName target("powerdns.com.");
  15. sr->setAsyncCallback([target, &v4Hit, &v6Hit, &queries](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional<Netmask>& srcmask, boost::optional<const ResolveContext&> context, LWResult* res, bool* chained) {
  16. queries++;
  17. if (isRootServer(ip)) {
  18. setLWResult(res, 0, false, false, true);
  19. v4Hit |= ip.isIPv4();
  20. v6Hit |= ip.isIPv6();
  21. if (domain == DNSName("powerdns.com.")) {
  22. addRecordToLW(res, domain, QType::NS, "ns1.powerdns.com.", DNSResourceRecord::AUTHORITY, 172800);
  23. addRecordToLW(res, "ns1.powerdns.com.", QType::AAAA, "2001:DB8:1::53", DNSResourceRecord::ADDITIONAL, 3600);
  24. addRecordToLW(res, "ns1.powerdns.com.", QType::A, "192.0.2.1", DNSResourceRecord::ADDITIONAL, 3600);
  25. }
  26. return 1;
  27. }
  28. else if (ip == ComboAddress("192.0.2.1:53")) {
  29. setLWResult(res, 0, true, false, false);
  30. v4Hit |= true;
  31. if (domain == DNSName("powerdns.com.")) {
  32. addRecordToLW(res, domain, QType::A, "192.0.2.2");
  33. }
  34. return 1;
  35. }
  36. else if (ip == ComboAddress("[2001:DB8:1::53]:53")) {
  37. setLWResult(res, 0, true, false, false);
  38. v6Hit |= true;
  39. if (domain == DNSName("powerdns.com.")) {
  40. addRecordToLW(res, domain, QType::A, "192.0.2.2");
  41. }
  42. return 1;
  43. }
  44. return 0;
  45. });
  46. vector<DNSRecord> ret;
  47. int rcode;
  48. rcode = sr->beginResolve(target, QType(QType::A), QClass::IN, ret);
  49. BOOST_REQUIRE_EQUAL(queries, 2);
  50. BOOST_REQUIRE_EQUAL(v4Hit, true);
  51. BOOST_REQUIRE_EQUAL(v6Hit, false);
  52. BOOST_CHECK_EQUAL(rcode, RCode::NoError);
  53. BOOST_CHECK_EQUAL(ret.size(), 1U);
  54. }
  55. BOOST_AUTO_TEST_CASE(test_outgoing_v4_only_no_A_in_delegation)
  56. {
  57. // The name is not resolvable, as there's no A glue for an in-bailiwick NS
  58. std::unique_ptr<SyncRes> sr;
  59. initSR(sr);
  60. SyncRes::s_doIPv6 = false;
  61. primeHints();
  62. int queries = 0;
  63. const DNSName target("powerdns.com.");
  64. sr->setAsyncCallback([target, &queries](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional<Netmask>& srcmask, boost::optional<const ResolveContext&> context, LWResult* res, bool* chained) {
  65. queries++;
  66. if (isRootServer(ip)) {
  67. setLWResult(res, 0, false, false, true);
  68. if (domain == DNSName("powerdns.com.")) {
  69. addRecordToLW(res, domain, QType::NS, "ns1.powerdns.com.", DNSResourceRecord::AUTHORITY, 172800);
  70. addRecordToLW(res, "ns1.powerdns.com.", QType::AAAA, "2001:DB8:1::53", DNSResourceRecord::ADDITIONAL, 3600);
  71. }
  72. return 1;
  73. }
  74. else if (ip == ComboAddress("[2001:DB8:1::53]:53")) {
  75. setLWResult(res, 0, true, false, false);
  76. if (domain == DNSName("powerdns.com.")) {
  77. addRecordToLW(res, domain, QType::A, "192.0.2.2");
  78. }
  79. return 1;
  80. }
  81. return 0;
  82. });
  83. vector<DNSRecord> ret;
  84. int rcode;
  85. rcode = sr->beginResolve(target, QType(QType::A), QClass::IN, ret);
  86. BOOST_REQUIRE_EQUAL(queries, 14); // We keep trying all parent nameservers, this is wrong!
  87. BOOST_CHECK_EQUAL(rcode, RCode::ServFail);
  88. BOOST_CHECK_EQUAL(ret.size(), 0U);
  89. }
  90. BOOST_AUTO_TEST_CASE(test_outgoing_v6_only_no_AAAA_in_delegation)
  91. {
  92. std::unique_ptr<SyncRes> sr;
  93. initSR(sr);
  94. SyncRes::s_doIPv4 = false;
  95. SyncRes::s_doIPv6 = true;
  96. primeHints();
  97. int queries = 0;
  98. const DNSName target("powerdns.com.");
  99. sr->setAsyncCallback([target, &queries](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional<Netmask>& srcmask, boost::optional<const ResolveContext&> context, LWResult* res, bool* chained) {
  100. queries++;
  101. if (isRootServer(ip)) {
  102. setLWResult(res, 0, false, false, true);
  103. if (domain == DNSName("powerdns.com.")) {
  104. addRecordToLW(res, domain, QType::NS, "ns1.powerdns.com.", DNSResourceRecord::AUTHORITY, 172800);
  105. addRecordToLW(res, "ns1.powerdns.com.", QType::A, "192.0.2.1", DNSResourceRecord::ADDITIONAL, 3600);
  106. }
  107. return 1;
  108. }
  109. else if (ip == ComboAddress("192.0.2.1:53")) {
  110. setLWResult(res, 0, true, false, false);
  111. if (domain == DNSName("powerdns.com.")) {
  112. addRecordToLW(res, domain, QType::A, "192.0.2.2");
  113. }
  114. return 1;
  115. }
  116. return 0;
  117. });
  118. vector<DNSRecord> ret;
  119. int rcode;
  120. rcode = sr->beginResolve(target, QType(QType::A), QClass::IN, ret);
  121. BOOST_REQUIRE_EQUAL(queries, 14); // The recursor tries all parent nameservers... this needs to be fixed
  122. BOOST_CHECK_EQUAL(rcode, RCode::ServFail);
  123. BOOST_CHECK_EQUAL(ret.size(), 0U);
  124. }
  125. BOOST_AUTO_TEST_SUITE_END()