query_unittest.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <dns/message.h>
  15. #include <dns/name.h>
  16. #include <dns/rcode.h>
  17. #include <dns/rrtype.h>
  18. #include <datasrc/zonetable.h>
  19. #include <auth/query.h>
  20. #include <gtest/gtest.h>
  21. using namespace isc::dns;
  22. using namespace isc::datasrc;
  23. using namespace isc::auth;
  24. namespace {
  25. class QueryTest : public ::testing::Test {
  26. protected:
  27. QueryTest() :
  28. qname(Name("www.example.com")), qclass(RRClass::IN()),
  29. qtype(RRType::A()), response(Message::RENDER),
  30. query(zone_table, qname, qtype, response)
  31. {
  32. response.setRcode(Rcode::NOERROR());
  33. }
  34. ZoneTable zone_table;
  35. const Name qname;
  36. const RRClass qclass;
  37. const RRType qtype;
  38. Message response;
  39. Query query;
  40. };
  41. TEST_F(QueryTest, noZone) {
  42. // There's no zone in the zone table. So the response should have
  43. // SERVFAIL.
  44. query.process();
  45. EXPECT_EQ(Rcode::SERVFAIL(), response.getRcode());
  46. }
  47. TEST_F(QueryTest, matchZone) {
  48. // add a matching zone. since the zone is empty right now, the response
  49. // should have NXDOMAIN.
  50. zone_table.add(ZonePtr(new MemoryZone(qclass, Name("example.com"))));
  51. query.process();
  52. EXPECT_EQ(Rcode::NXDOMAIN(), response.getRcode());
  53. }
  54. TEST_F(QueryTest, noMatchZone) {
  55. // there's a zone in the table but it doesn't match the qname. should
  56. // result in SERVFAIL.
  57. zone_table.add(ZonePtr(new MemoryZone(qclass, Name("example.org"))));
  58. query.process();
  59. EXPECT_EQ(Rcode::SERVFAIL(), response.getRcode());
  60. }
  61. }