test_datasrc.cc 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <cassert>
  16. #include <algorithm>
  17. #include <dns/tests/unittest_util.h>
  18. #include <datasrc/tests/test_datasrc.h>
  19. #include <datasrc/data_source.h>
  20. #include <dns/buffer.h>
  21. #include <dns/messagerenderer.h>
  22. #include <dns/name.h>
  23. #include <dns/rdata.h>
  24. #include <dns/rdataclass.h>
  25. #include <dns/rrclass.h>
  26. #include <dns/rrset.h>
  27. #include <dns/rrsetlist.h>
  28. #include <dns/rrtype.h>
  29. #include <dns/rrttl.h>
  30. #include <iostream>
  31. using isc::UnitTestUtil;
  32. using namespace std;
  33. using namespace isc::dns;
  34. using namespace isc::dns::rdata;
  35. namespace isc {
  36. namespace datasrc {
  37. namespace {
  38. // This is a mock data source for testing. It can contain multiple zones.
  39. // The content of each zone should be configured in the form of RRData{}.
  40. // Each RRData element is a tuple of char strings, representing
  41. // "name, RRtype, RDATA". For simplicity we use the same single TTL for
  42. // RRs (TEST_TTL) defined below.
  43. // Multiple RRs of the same pair of (name, RRtype) can be defined, but
  44. // they must not be interleaved with other types of pair. For example,
  45. // This is okay:
  46. // {"example.com", "AAAA", "2001:db8::1"},
  47. // {"example.com", "AAAA", "2001:db8::2"},
  48. // ...
  49. // but this is invalid:
  50. // {"example.com", "AAAA", "2001:db8::1"},
  51. // {"example.com", "A", "192.0.2.1"},
  52. // {"example.com", "AAAA", "2001:db8::2"},
  53. // ...
  54. // If an RRset is associated with an RRSIG, the RRSIG must immediately follow
  55. // the RRset to be signed. Multiple RRSIGs can follow the RRset. RRSIG
  56. // records will always be attached to the most recent non-RRSIG RRset;
  57. // consequently, the first RR listed must not be an RRSIG record.
  58. //
  59. // Names are sorted internally, and don't have to be sorted in the data.
  60. //
  61. // A zone is defined in the form of ZoneData{}, which contains:
  62. // zone name (character string)
  63. // RRclass (character string)
  64. // A pointer to in-zone RRs in the form of RRData{}
  65. // A pointer to glue RRs in the form of RRData{}
  66. // Glues can be omitted, in which case a convenient constant "empty_records"
  67. // can be specified.
  68. // For simplicity we use the same single TTL for all test RRs.
  69. const uint32_t TEST_TTL = 3600;
  70. struct RRData {
  71. const char* const name;
  72. const char* const rrtype;
  73. const char* const rdata;
  74. };
  75. struct ZoneData {
  76. const char* const zone_name;
  77. const char* const rrclass;
  78. const struct RRData* records;
  79. const struct RRData* glue_records;
  80. };
  81. //
  82. // zone data for example.com
  83. //
  84. const struct RRData example_com_records[] = {
  85. // example.com
  86. {"example.com", "NS", "dns01.example.com"},
  87. {"example.com", "NS", "dns02.example.com"},
  88. {"example.com", "NS", "dns03.example.com"},
  89. {"example.com", "RRSIG", "NS 5 2 3600 20100322084538 20100220084538 33495 example.com. ClcrfjkQZUY5L6ZlCkU3cJHzcrEGrofKSVeeoeZ+w6yeEowFNVXs2YBo3tom53DiCrdD9rs3feVSLGW5rjsz/O6lDuomgQG+EVSnWa7GTIPBXj1BmDXXp3XxeldYmhf4UzaN5BA+RUA5E8NChNKuNNof76j2S9tilfN/kvpy4fw="},
  90. {"example.com", "SOA", "master.example.com. admin.example.com. 1234 3600 1800 2419200 7200"},
  91. {"example.com", "RRSIG", "SOA 5 2 3600 20100322084538 20100220084538 33495 example.com. KUun66Qaw36osk2BJS6U1fAy3PPDkNo2QK4meGNbDBY8q8b+f2o+IXJ14YCvssGl1ORW0CcLnDRxssnk8V/Svmj5iFhO+8HC2hnVBdi2zewvdVtwRb+lWwKN7pkXXwuy6g1t9WCd/j5FCc/wgxqtZUTPb6XgZcnHrORDMOTqLs4="},
  92. {"example.com", "NSEC", "cname-ext.example.com. NS SOA MX RRSIG NSEC DNSKEY"},
  93. {"example.com", "RRSIG", "NSEC 5 2 7200 20100322084538 20100220084538 33495 example.com. KxuVaPPKNPJzr/q+cJPiNlkHVTQK0LVsgTbSqruXQc25lAd0wn5oKUtxL1bEAchHkfA8eLzcYCj2ZqqAv9OJubw53mfskTad7UHs4Uj2RTrIsNGMCiZGgOpvNb9JcWpQtoyXVT1uNse+Qsbeir0eyeYIufUynFU041jtNrlJMio="},
  94. {"example.com", "DNSKEY", "257 3 5 AwEAAe5WFbxdCPq2jZrZhlMj7oJdff3W7syJtbvzg62tRx0gkoCDoBI9DPjlOQG0UAbj+xUV4HQZJStJaZ+fHU5AwVNT+bBZdtV+NujSikhdTHb4FYLg2b3Cx9NyJvAVukHp/91HnWuG4T36CzAFrfPwsHIrBz9BsaIQ21VRkcmj7DswfI/iDGd8j6bqiODyNZYQ+ZrLmF0KIJ2yPN3iO6Zq23TaOrVTjB7d1a/h31ODfiHAxFHrkY3t3D5JR9Nsl/7fdRmSznwtcSDgLXBoFEYmw6p86AcvRyoYNcL1SXjaKVLG5jyU3UR+LcGZT5t/0xGfoIK/aKwENrsjcKZZj660b1M="},
  95. {"example.com", "DNSKEY", "256 3 5 AwEAAcOUBllYc1hf7ND9uDy+Yz1BF3sI0m4qNGV7WcTD0WEiuV7IjXgHE36fCmS9QsUxSSOVo1I/FMxI2PJVqTYHkXFBS7AzLGsQYMU7UjBZSotBJ6Imt5pXMu+lEDNy8TOUzG3xm7g0qcbWYF6qCEfvZoBtAqi5Rk7Mlrqs8agxYyMx"},
  96. {"example.com", "RRSIG", "DNSKEY 5 2 3600 20100416210049 20100317210049 4456 example.com. 37FC0rcwOZVarTMjft0BMbvv8hbJU7OHNsvO7R1q6OgsLTj7QGMX3sC42JGbwUrYI/OwnZblNcv1eim0g0jX5k+sVr2OJsEubngRjVqLo54qV8rBC14tLk9PGKxxjQG0IBJU866uHxzXYBO2a1r2g93/qyTtrT7iPLu/2Ce1WRKMBPK0yf4nW2usFU/PXesXFWpZ7HLGZL73/NWv8wcezBDuU0B2PlHLjSu7k6poq6JWDC02o5SYnEBwsJ5Chi+3/NZmzKTiNP7g0H4t6QhunkEXxL3z0617mwwQt00ypXsNunnPy4Ub5Kllk1SKJl8ZkEDKkJtSvuXJhcAZsLyMQw=="},
  97. {"example.com", "RRSIG", "DNSKEY 5 2 3600 20100416210049 20100317210049 33495 example.com. h3OM5r3roBsgnEQk9fcjTg5L7p3yDptDpVzDN/lgjqpaWxtlz5LsulBH3YzwYyXzT7pG7L0/qT6dcuRECc/rniECviWvmJMJZzEAMry0Of/pk/8ekuGTxABpqwAoCwM5as30sc0cfMJTS7umpJVDA4lRB2zoKGefWnJ3+pREDiY="},
  98. // dns01.example.com
  99. {"dns01.example.com", "A", "192.0.2.1"},
  100. {"dns01.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. NIawlZLk8WZAjNux7oQM2mslfW52OZFFkWt++7FHu2SU98XqEeKfCMnpgtWe5T8Nr9cS8df901iEOJoWQzGTEaHYUBtEhsSjBVn7mKp3fz6473a2xxy75SUKZ0rxjNXSZ8Q5rnFmkX0HTH2Sg51mtjH6aC2pfheQnA2t193BnSg="},
  101. {"dns01.example.com", "NSEC", "dns02.example.com. A RRSIG NSEC"},
  102. {"dns01.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. EkyeshmMNP9xiAz6mDFDIwksTdmkF9zsFzLuVKAgK6eUk7St6tp5PSvjA8nWol0vdvvz4LK85a4ffTFEiNRyvWeYP2vOhEkyDcrwuCd8Vc3jh/8Sm1Js+nX7hJStrZGFvp2TWPpt9nKH5p3MxXvTb/YVurnue0xSeFAE17O3+I0="},
  103. // dns02.example.com
  104. {"dns02.example.com", "A", "192.0.2.2"},
  105. {"dns02.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. XJtVMbUIRE0mk6Hn/Nx6k36jaxaBDPK2/IYB6vCQjJETz6gW4T6q/H/eY9/Lsw5iYPFhoBRDxT4XFj575t98kELXnJe1WhuMbRPlOhyOjxkLECaUne/sbFPOtbGFx9ohuojI0RgxxZiCFaO8wJuv6nfPuzmlLajWS6z9NZeOMIk="},
  106. {"dns02.example.com", "NSEC", "dns03.example.com. A RRSIG NSEC"},
  107. {"dns02.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. imBNTMB3sPU4kblcaAH6V7lCVt5xgtAybi3DA/SbLEulLaV2NE6vcoEn/AieaM4mOJicQnUDj/H+1hSEhzxU2tRM8zfVlvztxQWn6eh7ZR4mKfNDSvRUGU9ykhpwMyC7wjOt1j5bcSA/OTnLRAilslnJyOM4bSaxVEFo8YPjncY="},
  108. // dns03.example.com
  109. {"dns03.example.com", "A", "192.0.2.3"},
  110. {"dns03.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. Ubrcm1H+F6m8khle7P9zU8eO+Jtuj+1Vx1MM5KAkmZPJwQe9uTcoCpQa6DXOGG9kajDTnNN1Be1gkZuJDTZJG4SmJLXLbNY3RDnxpGmWta3qs/VgDq78/YM8ropt1/s7YKyrCfGE2ff+FUB0mLObiG01ZV2gu5HJzgE7SEWLEiI="},
  111. {"dns03.example.com", "NSEC", "foo.example.com. A RRSIG NSEC"},
  112. {"dns03.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. nn829Xw5CJFnPHwI9WHeT5epQv+odtCkHnjlPFGoPTLOyiks+041UmMqtq3uiSp4d2meMSe9UuDvoROT0L6NTtQQvVqiDhTn0irTFw1uw7fO8ZTG7eyu6Ypfz0+HvfbNvd4kMoD2OTgADRXPVsCTwK+PBOIIG9YTEQfl8pCqW5g="},
  113. // www.example.com
  114. {"www.example.com", "A", "192.0.2.1"},
  115. {"www.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. qyFyyV/mE8x4pdhudr5iycwhDsva31MzwO1kBR+bDKvzJg8mN8KxlPZrOlNNUhd3YRXQVwieMyxOTWRPXoxrNEDkNwimXkfe3rrHY7ibV9eNS4OIBUjb44VjCNr9CmQSzfuQ2yxO2r+YIuPYHRCjieD4xh6t9ay4IaCN/tDAJ+Q="},
  116. {"www.example.com", "NSEC", "example.com. A RRSIG NSEC"},
  117. {"www.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. ZLZlSVBa2oe4U+7SZASnypP2VkI5gg1/1cVGqYUvfYNIUkcVMWDgn7DZCfpmo+2vdlV/4VhAc+sjDd+X+e57XGnW8+lqZHvG6NMMhmSGmeATD3D+8lEJJGo0dxoN4rHJQyp/eT2S4nChz+D/ze+YRagYxGF7pXm9zcrw3kKZGTs="},
  118. // *.wild.example.com
  119. {"*.wild.example.com", "A", "192.0.2.2"},
  120. {"*.wild.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. FdO+UWONgtLKFxUzzygGunw67F9y8SzsP7yOLEYVJclRR8X3Ii62L0gtQHq2y0TcKsXttRsD6XY+tM5P/pgXlTNi7Bk4Fgb0PIDPjOsfT4DrS80kWn0YbinM/4/FA1j5ru5sTTboOY5UGhvDnoA9ogNuQQYb2/3wkoH0PrA2Q/0="},
  121. {"*.wild.example.com", "NSEC", "*.wild2.example.com. A RRSIG NSEC"},
  122. {"*.wild.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. OoGYslRj4xjZnBuzgOqsrvkDAHWycmQzbUxCRmgWnCbXiobJK7/ynONH3jm8G3vGlU0lwpHkhNs6cUK+6Nu8W49X3MT0Xksl/brroLcXYLi3vfxnYUNMMpXdeFl6WNNfoJRo90F/f/TWXAClRrDS29qiG3G1PEJZikIxZsZ0tyM="},
  123. // *.wild2.example.com
  124. {"*.wild2.example.com", "CNAME", "www.example.com"},
  125. {"*.wild2.example.com", "RRSIG", "CNAME 5 3 3600 20100410212307 20100311212307 33495 example.com. pGHtGdRBi4GKFSKszi6SsKvuBLDX8dFhZubU0tMojQ9SJuiFNF+WtxvdAYuUaoWP/9VLUaYmiw5u7JnzmR84DiXZPEs6DtD+UJdOZhaS7V7RTpE+tMOfVQBLpUnRWYtlTTmiBpFquzf3DdIxgUFhEPEuJJyp3LFRxJObCaq9 nvI="},
  126. {"*.wild2.example.com", "NSEC", "*.wild3.example.com. CNAME RRSIG NSEC"},
  127. {"*.wild2.example.com", "RRSIG", "NSEC 5 3 7200 20100410212307 20100311212307 33495 example.com. EuSzh6or8mbvwru2H7fyYeMpW6J8YZ528rabU38V/lMN0TdamghIuCneAvSNaZgwk2MSN1bWpZqB2kAipaM/ZI9/piLlTvVjjOQ8pjk0auwCEqT7Z7Qng3E92O9yVzO+WHT9QZn/fR6t60392In4IvcBGjZyjzQk8njIwbui xGA="},
  128. // *.wild3.example.com -- a wildcard record with a lame CNAME
  129. {"*.wild3.example.com", "CNAME", "spork.example.com"},
  130. {"*.wild3.example.com", "RRSIG", "CNAME 5 3 3600 20100410212307 20100311212307 33495 example.com. pGHtGdRBi4GKFSKszi6SsKvuBLDX8dFhZubU0tMojQ9SJuiFNF+WtxvdAYuUaoWP/9VLUaYmiw5u7JnzmR84DiXZPEs6DtD+UJdOZhaS7V7RTpE+tMOfVQBLpUnRWYtlTTmiBpFquzf3DdIxgUFhEPEuJJyp3LFRxJObCaq9 nvI="},
  131. {"*.wild3.example.com", "NSEC", "www.example.com. CNAME RRSIG NSEC"},
  132. {"*.wild3.example.com", "RRSIG", "NSEC 5 3 7200 20100410212307 20100311212307 33495 example.com. EuSzh6or8mbvwru2H7fyYeMpW6J8YZ528rabU38V/lMN0TdamghIuCneAvSNaZgwk2MSN1bWpZqB2kAipaM/ZI9/piLlTvVjjOQ8pjk0auwCEqT7Z7Qng3E92O9yVzO+WHT9QZn/fR6t60392In4IvcBGjZyjzQk8njIwbui xGA="},
  133. // foo.example.com
  134. {"foo.example.com", "CNAME", "cnametest.example.net"},
  135. {"foo.example.com", "RRSIG", "CNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. DSqkLnsh0gCeCPVW/Q8viy9GNP+KHmFGfWqyVG1S6koBtGN/VQQ16M4PHZ9Zssmf/JcDVJNIhAChHPE2WJiaPCNGTprsaUshf1Q2vMPVnkrJKgDY8SVRYMptmT8eaT0gGri4KhqRoFpMT5OYfesybwDgfhFSQQAh6ps3bIUsy4o="},
  136. {"foo.example.com", "NSEC", "mail.example.com. CNAME RRSIG NSEC"},
  137. {"foo.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. RTQwlSqui6StUYye1KCSOEr1d3irndWFqHBpwP7g7n+w8EDXJ8I7lYgwzHvlQt6BLAxe5fUDi7ct8M5hXvsm7FoWPZ5wXH+2/eJUCYxIw4vezKMkMwBP6M/YkJ2CMqY8DppYf60QaLDONQAr7AcK/naSyioeI5h6eaoVitUDMso="},
  138. // cname-int.example.com
  139. {"cname-int.example.com", "CNAME", "www.example.com."},
  140. {"cname-int.example.com", "RRSIG", "CNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. U1wjt0XY9xjTwvUmWSUcfLGMhCjfX2ylWfHrycy50x2oxcK9z94E1ejen9wDTIEBSGYgi6wpZ8RK0+02N1DWTGpDqNXd7aFRfDrWQJ/q/XJHDx0vlcmhkWhrT82LBfKxkrptOzchuSo/c0mpK+mpiIMc1VOwY+yuQ2ALfcD6EHw="},
  141. {"cname-int.example.com", "NSEC", "dname.example.com. CNAME RRSIG NSEC"},
  142. {"cname-int.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. rbV+gaxfrsoha59NOLF4EFyWQ+GuFCVK/8D77x1atan3HNlXBlZ1smgudKTaJ3CtlobIDt0MEdPxY1yn2Tskw/5mlP1PWf8oaP3BwGSQdn4gLI8+sMpNOPFEdXpxqxngm2F6/7fqniL1QuSAQBEdO+5UiCAgnncPmAsSJg3u1zg="},
  143. // cname-ext.example.com
  144. {"cname-ext.example.com", "CNAME", "www.sql1.example.com"},
  145. {"cname-ext.example.com", "RRSIG", "CNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. bGPIuZilyygvTThK4BrdECuaBcnZUgW/0d09iN2CrNjckchQl3dtbnMNirFsVs9hShDSldRNlQpiAVMpnPgXHhReNum7jmX6yqIH6s8GKIo91zr3VL/ramlezie5w4MilDHrxXLK2pb8IHmP+ZHivQ2EtdYQZgETWBWxr5FDfwk="},
  146. {"cname-ext.example.com", "NSEC", "cname-int.example.com. CNAME RRSIG NSEC"},
  147. {"cname-ext.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. inWsFwSDWG7TakjwbUTzTRpXz0WifelA5Kn3ABk6BVirIPmd+yQoNj2QZBDFAQwhnLPlNws2Oo4vgMsBMyx1Fv5eHgMUuCN3DUDaLlzlPtUb42CjOUa+jZBeTV/Hd7WZrirluASE1QFDprLdSSqoPPfAKvN3pORtW7y580dMOIM="},
  148. // dname.example.com
  149. {"dname.example.com", "DNAME", "sql1.example.com."},
  150. {"dname.example.com", "RRSIG", "DNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. ae8U47oaiwWdurkSyzcsCAF6DxBqjukizwF7K7U6lQVMtfoUE14oiAqfj1fjH8YLDOO/Hd1twrd/u0vgjnI1Gg32YTi7cYOzwE912SV1u2B/y0awaQKWPBwOW0aI7vxelt1vMUF81xosiQD04gOIdDBTqbHKcDxum87iWbhk4Ug="},
  151. {"dname.example.com", "NSEC", "dns01.example.com. DNAME RRSIG NSEC"},
  152. {"dname.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. c21Fff2D8vBrLzohBnUeflkaRdUAnUxAFGp+UQ0miACDCMOFBlCS9v9g/2+orOnKfd3l4vyz55C310t8JXgXb119ofaZWj2zkdUe+X8Bax+sMS0Y5K/sUhSNvbJbozr9UYPdvjSVBiWgh3s9fsb+etKq9uFukAzGU/FuGYpO0r0="},
  153. // subzone.example.com
  154. {"subzone.example.com", "NS", "ns1.subzone.example.com"},
  155. {"subzone.example.com", "NS", "ns2.subzone.example.com"},
  156. {"subzone.example.com", "NSEC", "*.wild.example.com. NS DS RRSIG NSEC"},
  157. {"subzone.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. Oe2kgIhsLtPJ4+lDZDxznV8/vEVoXKOBFN9lwWyebaKa19BaSXlQ+YVejmulmKDDjEucMvEfuItfn6w7bnU+DzOLk5D1lJCjwDlKz8u3xOAx16TiuQn4bgQAOiFtBQygmGGqO3BVpX+jxsmw7eH3emofy8uUqr/C4aopnwuf28g="},
  158. {"subzone.example.com", "DS", "33313 5 1 0FDD7A2C11AA7F55D50FBF9B7EDDA2322C541A8D"},
  159. {"subzone.example.com", "DS", "33313 5 2 00B99B7006F496D135B01AB17EDB469B4BE9E1973884DEA757BC4E3015A8C3AB"},
  160. {"subzone.example.com", "RRSIG", "DS 5 3 3600 20100322084538 20100220084538 33495 example.com. dIqZKvpkJN1l92SOiWgJh3KbjErIN+EfojMsm4pEdV5xQdZwj6DNNEu6Kw4rRwdvrZIu0TyqPr3jSJb7o6R7vZgZzmLfVV/ojQah7rwuYHCFcfyZ4JyK2311fMhRR1QAvMsdcjdyA1XC140Cm6AnL3cH5rh/KUks/0ec3Ca7GNQ="},
  161. // subset of child zone: sql1
  162. {"sql1.example.com", "NS", "dns01.example.com"},
  163. {"sql1.example.com", "NS", "dns02.example.com"},
  164. {"sql1.example.com", "NS", "dns03.example.com"},
  165. {"sql1.example.com", "DS", "33313 5 1 0FDD7A2C11AA7F55D50FBF9B7EDDA2322C541A8D"},
  166. {"sql1.example.com", "DS", "33313 5 2 00B99B7006F496D135B01AB17EDB469B4BE9E1973884DEA757BC4E3015A8C3AB"},
  167. {"sql1.example.com", "RRSIG", "DS 5 3 3600 20100322084538 20100220084538 33495 example.com. dIqZKvpkJN1l92SOiWgJh3KbjErIN+EfojMsm4pEdV5xQdZwj6DNNEu6Kw4rRwdvrZIu0TyqPr3jSJb7o6R7vZgZzmLfVV/ojQah7rwuYHCFcfyZ4JyK2311fMhRR1QAvMsdcjdyA1XC140Cm6AnL3cH5rh/KUks/0ec3Ca7GNQ="},
  168. {"sql1.example.com", "NSEC", "subzone.example.com. NS DS RRSIG NSEC"},
  169. {"sql1.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. k9FRdFyk/cPdkmmaoZbGZPpzIzfbFWQ3QCHd2qhJa0xAXaEOT/GBL6aFqx9SlunDu2wgES+To5fWPZGi4NzWpp6c5t27rnATN/oCEQ/UYIJKmWbqrXdst0Ps5boznk7suK2Y+km31KxaIf3fDd/T3kZCVsR0aWKRRRatPb7GfLw="},
  170. {NULL, NULL, NULL}
  171. };
  172. const struct RRData example_com_glue_records[] = {
  173. {"ns1.subzone.example.com", "A", "192.0.2.1"},
  174. {"ns2.subzone.example.com", "A", "192.0.2.2"},
  175. {NULL, NULL, NULL}
  176. };
  177. //
  178. // zone data for sql1.example.com
  179. //
  180. const struct RRData sql1_example_com_records[] = {
  181. {"sql1.example.com", "NS", "dns01.example.com"},
  182. {"sql1.example.com", "NS", "dns02.example.com"},
  183. {"sql1.example.com", "NS", "dns03.example.com"},
  184. {"sql1.example.com", "RRSIG", "NS 5 3 3600 20100322084536 20100220084536 12447 sql1.example.com. 0CL8noy0NSgoWwuKd+Dc6vyIIw2BrAEBx0IJzcSB6GlB25x/zjEd6AJG0be13HN6jOaTX8iWTuCVrEYuXg76V+M4EvTZHjEScj0az74TrDv4Vdo459paGKCX9B8NLJW1mW4fzZrrXQ8jmBEZeS91Q5rJrO+UKJEuUz3LYdTPvao="},
  185. {"sql1.example.com", "SOA", "master.example.com. admin.example.com. 678 3600 1800 2419200 7200"},
  186. {"sql1.example.com", "RRSIG", "SOA 5 3 3600 20100322084536 20100220084536 12447 sql1.example.com. oakulfyljL/RAKgCKXEZ3KsG8BJj5WG4JK4moWFB6c9OKem6jIk8hKP2XlUVXFuOYJlRdIM4KicmR2GAK+5jJp6z5ShssstYTXo3QosVm6oCKumuFeLFHzcjfqP1D+F9NsvHldJIBnS/4ebPkmR5OENyCZXQF5HmN2awIj4CLjE="},
  187. {"sql1.example.com", "NSEC", "www.sql1.example.com. NS SOA RRSIG NSEC DNSKEY"},
  188. {"sql1.example.com", "RRSIG", "NSEC 5 3 7200 20100322084536 20100220084536 12447 sql1.example.com. v71CgdTYccCiTqfRcn6HsvISQa8ruvUfCKtpwym0RW/G27xlZn8otj2IMtWwkLxti8Rqqu+PTViLaOIbeVfHBcqzAd7U59cAOYoq3ODZx6auiE3C23HAKqUavKcP7Esaajm1cbcWy6Kyie4CAZc8M7EeKxgkXMKJGqBQzF+/FOo="},
  189. // www.sql1.example.com
  190. {"www.sql1.example.com", "A", "192.0.2.2"},
  191. {"www.sql1.example.com", "RRSIG", "A 5 4 3600 20100322084536 20100220084536 12447 sql1.example.com. DNdVKxB3oBsB14NPoV9WG14Y/g4zMcIXLYnFjj9vRZRZJpAvbTEipiXlayuhOxnqU827OipETQyeULZmLsqIQ1wK4Fgf+9b5aJ8D85/o4wBka00X4hZ3MwDPRb4mjuogwBTBg5NRpNSzUfbkPGiav08BFwgg+Efm9veSB05arS0="},
  192. {"www.sql1.example.com", "NSEC", "sql1.example.com. A RRSIG NSEC"},
  193. {"www.sql1.example.com", "RRSIG", "NSEC 5 4 7200 20100322084536 20100220084536 12447 sql1.example.com. cJMJhDx/ND7/9j3zhyXe+6eaSsU7ByYpXhJzbe+OhjFgH0VasQXq7o1QB3I293UZ+yhkjgXap+9QtPlraaNaYyTyOMQ42OoxSefJpYz9CME/FI2tsUfyrCnLFxYRNet7sMS0q+hLqxRayuEHDFDp72hHPGLJQ8a7jq4SrIonT50="},
  194. {NULL, NULL, NULL}
  195. };
  196. //
  197. // zone data for loop.example
  198. //
  199. const struct RRData loop_example_records[] = {
  200. {"loop.example", "SOA", "master.loop.example admin.loop.example. "
  201. "1234 3600 1800 2419200 7200"},
  202. {"loop.example", "NS", "ns.loop.example"},
  203. {"one.loop.example", "CNAME", "two.loop.example"},
  204. {"two.loop.example", "CNAME", "one.loop.example"},
  205. {NULL, NULL, NULL}
  206. };
  207. //
  208. // zone data for nons.example
  209. //
  210. const struct RRData nons_example_records[] = {
  211. {"nons.example", "SOA", "master.nons.example admin.nons.example. "
  212. "1234 3600 1800 2419200 7200"},
  213. {"www.nons.example", "A", "192.0.2.1"},
  214. {"ns.nons.example", "A", "192.0.2.2"},
  215. // One of the NS names is intentionally non existent in the zone it belongs
  216. // to. This delegation is used to see if we still return the NS and the
  217. // existent glue.
  218. // (These are not relevant to test the case for the "no NS" case. We use
  219. // this zone to minimize the number of test zones)
  220. {"incompletechild.nons.example", "NS", "ns.incompletechild.nons.example"},
  221. {"incompletechild.nons.example", "NS", "nx.nosoa.example"},
  222. {NULL, NULL, NULL}
  223. };
  224. const struct RRData nons_example_glue_records[] = {
  225. {"ns.incompletechild.nons.example", "A", "192.0.2.1"},
  226. {NULL, NULL, NULL}
  227. };
  228. //
  229. // zone data for nons-dname.example
  230. //
  231. const struct RRData nonsdname_example_records[] = {
  232. {"nons-dname.example", "SOA", "master.nons-dname.example "
  233. "admin.nons-dname.example. 1234 3600 1800 2419200 7200"},
  234. {"nons-dname.example", "DNAME", "example.org"},
  235. {"www.nons-dname.example", "A", "192.0.2.1"},
  236. {"ns.nons-dname.example", "A", "192.0.2.2"},
  237. {NULL, NULL, NULL}
  238. };
  239. //
  240. // zone data for nosoa.example
  241. //
  242. const struct RRData nosoa_example_records[] = {
  243. {"nosoa.example", "NS", "ns.nosoa.example"},
  244. {"www.nosoa.example", "A", "192.0.2.1"},
  245. {"ns.nosoa.example", "A", "192.0.2.2"},
  246. {NULL, NULL, NULL}
  247. };
  248. //
  249. // zone data for apexcname.example.
  250. //
  251. const struct RRData apexcname_example_records[] = {
  252. {"apexcname.example", "CNAME", "canonical.apexcname.example"},
  253. {"canonical.apexcname.example", "SOA",
  254. "master.apexcname.example "
  255. "admin.apexcname.example. 1234 3600 1800 2419200 7200"},
  256. {NULL, NULL, NULL}
  257. };
  258. //
  259. // empty data set, for convenience.
  260. //
  261. const struct RRData empty_records[] = {
  262. {NULL, NULL, NULL}
  263. };
  264. //
  265. // test zones
  266. //
  267. const struct ZoneData zone_data[] = {
  268. { "example.com", "IN", example_com_records, example_com_glue_records },
  269. { "sql1.example.com", "IN", sql1_example_com_records, empty_records },
  270. { "loop.example", "IN", loop_example_records, empty_records },
  271. { "nons.example", "IN", nons_example_records, nons_example_glue_records },
  272. { "nons-dname.example", "IN", nonsdname_example_records, empty_records },
  273. { "nosoa.example", "IN", nosoa_example_records, empty_records },
  274. { "apexcname.example", "IN", nosoa_example_records, empty_records }
  275. };
  276. const size_t NUM_ZONES = sizeof(zone_data) / sizeof(zone_data[0]);
  277. struct Zone {
  278. Zone(const char* const name, const char* const class_txt) :
  279. zone_name(Name(name)), rrclass(class_txt)
  280. {}
  281. Name zone_name;
  282. RRClass rrclass;
  283. vector<Name> names;
  284. vector<RRsetPtr> rrsets;
  285. };
  286. vector<Zone> zones;
  287. }
  288. DataSrc::Result
  289. TestDataSrc::init(isc::data::ConstElementPtr) {
  290. return (init());
  291. }
  292. void
  293. buildZone(Zone& zone, const RRData* records, const bool is_glue) {
  294. RRsetPtr prev_rrset;
  295. for (int i = 0; records[i].name != NULL; ++i) {
  296. Name name(records[i].name);
  297. RRType rrtype(records[i].rrtype);
  298. RRsetPtr rrset;
  299. bool new_name = false;
  300. if (!prev_rrset || prev_rrset->getName() != name) {
  301. if (!is_glue) {
  302. zone.names.push_back(name);
  303. }
  304. new_name = true;
  305. }
  306. if (new_name || prev_rrset->getType() != rrtype) {
  307. rrset = RRsetPtr(new RRset(name, zone.rrclass, rrtype,
  308. RRTTL(TEST_TTL)));
  309. if (rrtype != RRType::RRSIG()) {
  310. zone.rrsets.push_back(rrset);
  311. }
  312. } else {
  313. rrset = prev_rrset;
  314. }
  315. rrset->addRdata(createRdata(rrtype, zone.rrclass, records[i].rdata));
  316. if (rrtype == RRType::RRSIG()) {
  317. prev_rrset->addRRsig(rrset);
  318. } else {
  319. prev_rrset = rrset;
  320. }
  321. }
  322. }
  323. DataSrc::Result
  324. TestDataSrc::init() {
  325. if (initialized) {
  326. return (SUCCESS);
  327. }
  328. if (zones.empty()) {
  329. for (int i = 0; i < NUM_ZONES; ++i) {
  330. Zone zone(zone_data[i].zone_name, zone_data[i].rrclass);
  331. buildZone(zone, zone_data[i].records, false);
  332. buildZone(zone, zone_data[i].glue_records, true);
  333. sort(zone.names.begin(), zone.names.end());
  334. zones.push_back(zone);
  335. }
  336. }
  337. initialized = true;
  338. return (SUCCESS);
  339. }
  340. void
  341. TestDataSrc::findClosestEnclosure(DataSrcMatch& match) const {
  342. const Name& qname = match.getName();
  343. if (match.getClass() != getClass() && match.getClass() != RRClass::ANY()) {
  344. return;
  345. }
  346. vector<Zone>::const_iterator it;
  347. vector<Zone>::const_iterator best_it = zones.end();
  348. unsigned int best_common_labels = 0;
  349. for (it = zones.begin(); it != zones.end(); ++it) {
  350. const NameComparisonResult cmp = qname.compare(it->zone_name);
  351. const NameComparisonResult::NameRelation reln = cmp.getRelation();
  352. if ((reln == NameComparisonResult::EQUAL ||
  353. reln == NameComparisonResult::SUBDOMAIN) &&
  354. cmp.getCommonLabels() > best_common_labels) {
  355. best_it = it;
  356. best_common_labels = cmp.getCommonLabels();
  357. }
  358. }
  359. if (best_it != zones.end()) {
  360. match.update(*this, best_it->zone_name);
  361. }
  362. }
  363. struct ZoneNameMatch : public unary_function<Name, bool> {
  364. ZoneNameMatch(const Name& name) : name_(name) {}
  365. bool operator()(const Zone& zone) const {
  366. return (zone.zone_name == name_);
  367. }
  368. const Name& name_;
  369. };
  370. // XXX: the main data source module can override the returned RRset.
  371. // That's bad and should be fixed (Trac #254), but for now we work around it.
  372. RRsetPtr
  373. copyRRset(RRsetPtr const source) {
  374. RRsetPtr rrset = RRsetPtr(new RRset(source->getName(), source->getClass(),
  375. source->getType(), source->getTTL()));
  376. RdataIteratorPtr it = source->getRdataIterator();
  377. for (; !it->isLast(); it->next()) {
  378. rrset->addRdata(it->getCurrent());
  379. }
  380. if (source->getRRsig()) {
  381. rrset->addRRsig(copyRRset(source->getRRsig()));
  382. }
  383. return (rrset);
  384. }
  385. class TestDataSrc::RRsetMatch {
  386. public:
  387. struct MatchResult {
  388. MatchResult(const bool name_found, const bool has_delegation) :
  389. name_found_(name_found), has_delegation_(has_delegation)
  390. {}
  391. bool name_found_;
  392. bool has_delegation_;
  393. };
  394. RRsetMatch(const Name& name, const RRType& rrtype, const Mode mode,
  395. RRsetList& target, uint32_t& flags) :
  396. name_(name), rrtype_(rrtype), mode_(mode), target_(target),
  397. flags_(flags), name_found_(false), has_delegation_(false)
  398. {}
  399. void operator()(const RRsetPtr& rrset) {
  400. if (rrset->getName() != name_) {
  401. return;
  402. }
  403. name_found_ = true;
  404. if (rrset->getType() == RRType::NS() ||
  405. rrset->getType() == RRType::DNAME()) {
  406. has_delegation_ = true;
  407. }
  408. if (mode_ == DELEGATION) {
  409. if (rrset->getType() == RRType::NS() ||
  410. rrset->getType() == RRType::DNAME() ||
  411. rrset->getType() == RRType::DS()) {
  412. target_.addRRset(copyRRset(rrset));
  413. }
  414. } else if (mode_ == ADDRESS) {
  415. if (rrset->getType() == RRType::A() ||
  416. rrset->getType() == RRType::AAAA()) {
  417. target_.addRRset(copyRRset(rrset));
  418. }
  419. } else {
  420. if (rrtype_ == RRType::NSEC() &&
  421. rrset->getType() == RRType::CNAME()) {
  422. // XXX: ignore CNAME if the qtype is NSEC.
  423. // tricky, but necessary.
  424. return;
  425. }
  426. if (rrtype_ == RRType::ANY() || rrtype_ == rrset->getType() ||
  427. rrset->getType() == RRType::CNAME() ||
  428. rrset->getType() == RRType::DNAME()) {
  429. target_.addRRset(copyRRset(rrset));
  430. if (rrset->getType() == RRType::CNAME()) {
  431. flags_ |= CNAME_FOUND;
  432. }
  433. if (rrset->getType() == RRType::DNAME()) {
  434. flags_ |= REFERRAL;
  435. }
  436. }
  437. }
  438. }
  439. MatchResult getResult() { return (MatchResult(name_found_,
  440. has_delegation_)); }
  441. const Name& name_;
  442. const RRType& rrtype_;
  443. const Mode mode_;
  444. RRsetList& target_;
  445. uint32_t& flags_;
  446. bool name_found_;
  447. bool has_delegation_;
  448. };
  449. void
  450. TestDataSrc::findRecords(const Name& name, const RRType& rdtype,
  451. RRsetList& target, const Name* zonename,
  452. const Mode mode, uint32_t& flags) const
  453. {
  454. flags = 0;
  455. assert(zonename != NULL);
  456. vector<Zone>::const_iterator zone = find_if(zones.begin(), zones.end(),
  457. ZoneNameMatch(*zonename));
  458. if (zone == zones.end()) {
  459. return;
  460. }
  461. const RRsetMatch::MatchResult match_result =
  462. for_each(zone->rrsets.begin(), zone->rrsets.end(),
  463. RRsetMatch(name, rdtype, mode, target, flags)).getResult();
  464. if (match_result.has_delegation_) {
  465. flags |= REFERRAL;
  466. }
  467. if (target.size() == 0) {
  468. if (match_result.name_found_) {
  469. flags |= TYPE_NOT_FOUND;
  470. } else {
  471. flags |= NAME_NOT_FOUND;
  472. }
  473. }
  474. }
  475. DataSrc::Result
  476. TestDataSrc::findRRset(const Name& qname,
  477. const RRClass& qclass,
  478. const RRType& qtype,
  479. RRsetList& target,
  480. uint32_t& flags,
  481. const Name* zonename) const
  482. {
  483. if (qclass != getClass() && qclass != RRClass::ANY()) {
  484. return (ERROR);
  485. }
  486. findRecords(qname, qtype, target, zonename, NORMAL, flags);
  487. return (SUCCESS);
  488. }
  489. DataSrc::Result
  490. TestDataSrc::findExactRRset(const Name& qname,
  491. const RRClass& qclass,
  492. const RRType& qtype,
  493. RRsetList& target,
  494. uint32_t& flags,
  495. const Name* zonename) const
  496. {
  497. if (qclass != getClass() && qclass != RRClass::ANY()) {
  498. return (ERROR);
  499. }
  500. findRecords(qname, qtype, target, zonename, NORMAL, flags);
  501. // Ignore referrals in this case
  502. flags &= ~REFERRAL;
  503. // CNAMEs don't count in this case
  504. if ((flags & CNAME_FOUND) != 0) {
  505. flags &= ~CNAME_FOUND;
  506. flags |= TYPE_NOT_FOUND;
  507. }
  508. return (SUCCESS);
  509. }
  510. DataSrc::Result
  511. TestDataSrc::findAddrs(const Name& qname,
  512. const RRClass& qclass,
  513. RRsetList& target,
  514. uint32_t& flags,
  515. const Name* zonename) const
  516. {
  517. if (qclass != getClass() && qclass != RRClass::ANY()) {
  518. return (ERROR);
  519. }
  520. findRecords(qname, RRType::ANY(), target, zonename, ADDRESS, flags);
  521. return (SUCCESS);
  522. }
  523. DataSrc::Result
  524. TestDataSrc::findReferral(const Name& qname,
  525. const RRClass& qclass,
  526. RRsetList& target,
  527. uint32_t& flags,
  528. const Name* zonename) const
  529. {
  530. if (qclass != getClass() && qclass != RRClass::ANY()) {
  531. return (ERROR);
  532. }
  533. findRecords(qname, RRType::ANY(), target, zonename, DELEGATION, flags);
  534. return (SUCCESS);
  535. }
  536. DataSrc::Result
  537. TestDataSrc::findPreviousName(const Name& qname,
  538. Name& target,
  539. const Name* zonename) const
  540. {
  541. assert(zonename != NULL);
  542. vector<Zone>::const_iterator zone = find_if(zones.begin(), zones.end(),
  543. ZoneNameMatch(*zonename));
  544. if (zone == zones.end()) {
  545. return (ERROR);
  546. }
  547. if (zone->names.empty()) {
  548. return (ERROR);
  549. }
  550. // if found, next_name >= qname.
  551. vector<Name>::const_iterator next_name =
  552. lower_bound(zone->names.begin(), zone->names.end(), qname);
  553. if (next_name == zone->names.end()) {
  554. // if no such name was found, the previous name is the last name.
  555. target = zone->names.back();
  556. } else if (*next_name == qname) {
  557. target = *next_name;
  558. } else if (next_name == zone->names.begin()) {
  559. // if qname < first_name, the "previous name" is the last name.
  560. target = zone->names.back();
  561. } else {
  562. // otherwise, qname and next_name share the same previous name.
  563. target = *(next_name - 1);
  564. }
  565. return (SUCCESS);
  566. }
  567. DataSrc::Result
  568. TestDataSrc::findCoveringNSEC3(const Name&, string&, RRsetList&) const {
  569. return (NOT_IMPLEMENTED);
  570. }
  571. }
  572. }