dnsname_check_unittest.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2011 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 <gtest/gtest.h>
  15. #include <dns/name.h>
  16. #include <acl/dnsname_check.h>
  17. using namespace isc::dns;
  18. using namespace isc::acl::dns;
  19. // Provide a specialization of the DNSNameCheck::matches() method.
  20. namespace isc {
  21. namespace acl {
  22. namespace dns {
  23. template <>
  24. bool NameCheck<Name>::matches(const Name& name) const {
  25. return (name_ == name);
  26. }
  27. } // namespace dns
  28. } // namespace acl
  29. } // namespace isc
  30. namespace {
  31. TEST(DNSNameCheck, construct) {
  32. EXPECT_EQ(Name("example.com"),
  33. NameCheck<Name>(Name("example.com")).getName());
  34. // Construct the same check with an explicit trailing dot. Should result
  35. // in the same result.
  36. EXPECT_EQ(Name("example.com"),
  37. NameCheck<Name>(Name("example.com.")).getName());
  38. }
  39. TEST(DNSNameCheck, match) {
  40. NameCheck<Name> check(Name("example.com"));
  41. EXPECT_TRUE(check.matches(Name("example.com")));
  42. EXPECT_FALSE(check.matches(Name("example.org")));
  43. // comparison is case insensitive
  44. EXPECT_TRUE(check.matches(Name("EXAMPLE.COM")));
  45. // this is exact match. so super/sub domains don't match
  46. EXPECT_FALSE(check.matches(Name("com")));
  47. EXPECT_FALSE(check.matches(Name("www.example.com")));
  48. }
  49. } // Unnamed namespace