query_unittest.cc 2.3 KB

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