srv_test.h 4.2 KB

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