srv_test.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef ISC_TESTUTILS_SRVTEST_H
  15. #define ISC_TESTUTILS_SRVTEST_H 1
  16. #include <util/buffer.h>
  17. #include <dns/name.h>
  18. #include <dns/message.h>
  19. #include <dns/messagerenderer.h>
  20. #include <dns/opcode.h>
  21. #include <dns/rcode.h>
  22. #include <dns/rrclass.h>
  23. #include <dns/rrtype.h>
  24. #include "mockups.h"
  25. #include <boost/scoped_ptr.hpp>
  26. namespace asiolink {
  27. class IOSocket;
  28. class IOMessage;
  29. class IOEndpoint;
  30. }
  31. namespace isc {
  32. namespace testutils {
  33. extern const char* const DEFAULT_REMOTE_ADDRESS;
  34. extern const uint16_t DEFAULT_REMOTE_PORT;
  35. // These are flags to indicate whether the corresponding flag bit of the
  36. // DNS header is to be set in the test cases. (The flag values
  37. // is irrelevant to their wire-format values)
  38. extern const unsigned int QR_FLAG;
  39. extern const unsigned int AA_FLAG;
  40. extern const unsigned int TC_FLAG;
  41. extern const unsigned int RD_FLAG;
  42. extern const unsigned int RA_FLAG;
  43. extern const unsigned int AD_FLAG;
  44. extern const unsigned int CD_FLAG;
  45. /// \brief The base class for Auth and Recurse test case
  46. class SrvTestBase : public ::testing::Test {
  47. protected:
  48. SrvTestBase();
  49. virtual ~SrvTestBase() {};
  50. /// Let the server process a DNS message.
  51. ///
  52. /// The derived class implementation is expected to pass \c io_message,
  53. /// \c parse_message, \c response_obuffer, and \c dnsserv to the server
  54. /// implementation it is testing.
  55. virtual void processMessage() = 0;
  56. /// The following methods implement server independent test logic using
  57. /// the template method pattern. Each test calls \c processMessage()
  58. /// to delegate the server-dependent behavior to the actual implementation
  59. /// classes.
  60. void unsupportedRequest();
  61. void multiQuestion();
  62. void shortMessage();
  63. void response();
  64. void shortQuestion();
  65. void shortAnswer();
  66. void ednsBadVers();
  67. void axfrOverUDP();
  68. /// Create DNS packet data from a file.
  69. ///
  70. /// It constructs wire-format DNS packet data from \c datafile in the
  71. /// form of \c IOMessage in \c io_message.
  72. /// The existing content of \c io_message, if any, will be deleted.
  73. void createDataFromFile(const char* const datafile,
  74. int protocol = IPPROTO_UDP);
  75. /// Create DNS packet data from a message.
  76. ///
  77. /// It constructs wire-format DNS packet data from \c message in the
  78. /// form of \c IOMessage in \c io_message.
  79. /// The existing content of \c io_message, if any, will be deleted.
  80. void createRequestPacket(isc::dns::Message& message,
  81. const int protocol = IPPROTO_UDP,
  82. isc::dns::TSIGContext* context = NULL,
  83. const char* const address = DEFAULT_REMOTE_ADDRESS,
  84. uint16_t port = DEFAULT_REMOTE_PORT);
  85. MockSession notify_session;
  86. MockServer dnsserv;
  87. isc::dns::Message request_message;
  88. isc::dns::MessagePtr parse_message;
  89. isc::dns::MessagePtr response_message;
  90. const isc::dns::qid_t default_qid;
  91. const isc::dns::Opcode opcode;
  92. const isc::dns::Name qname;
  93. const isc::dns::RRClass qclass;
  94. const isc::dns::RRType qtype;
  95. asiolink::IOSocket* io_sock;
  96. boost::scoped_ptr<asiolink::IOMessage> io_message;
  97. boost::scoped_ptr<const asiolink::IOEndpoint> endpoint;
  98. isc::dns::MessageRenderer request_renderer;
  99. isc::util::OutputBufferPtr response_obuffer;
  100. std::vector<uint8_t> data;
  101. };
  102. } // end of namespace testutils
  103. } // end of namespace isc
  104. #endif // ISC_TESTUTILS_SRVTEST_H
  105. // Local Variables:
  106. // mode: c++
  107. // End: