srv_test.h 3.9 KB

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