Commit 136adbda authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[trac1104] added a straightforward NameCheck class

parent bb79e799
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __DNSNAME_CHECK_H
#define __DNSNAME_CHECK_H 1
#include <dns/name.h>
#include <acl/check.h>
namespace isc {
namespace acl {
namespace dns {
template <typename Context>
class NameCheck : public Check<Context> {
public:
NameCheck(const isc::dns::Name& name) : name_(name) {}
/// \brief Destructor
virtual ~NameCheck() {}
/// \brief The check itself
///
/// Matches the passed argument to the condition stored here. Different
/// specialisations must be provided for different argument types, and the
/// program will fail to compile if a required specialisation is not
/// provided.
///
/// \param context Information to be matched
virtual bool matches(const Context& context) const;
private:
const isc::dns::Name name_;
};
} // namespace dns
} // namespace acl
} // namespace isc
#endif // __DNSNAME_CHECK_H
// Local Variables:
// mode: c++
// End:
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <gtest/gtest.h>
#include <dns/name.h>
#include <acl/dnsname_check.h>
using namespace isc::dns;
using namespace isc::acl::dns;
// Provide a specialization of the DNSNameCheck::matches() method.
namespace isc {
namespace acl {
namespace dns {
template <>
bool NameCheck<Name>::matches(const Name& name) const {
return (name_ == name);
}
} // namespace dns
} // namespace acl
} // namespace isc
namespace {
TEST(DNSNameCheck, match) {
NameCheck<Name> check(Name("example.com"));
EXPECT_TRUE(check.matches(Name("example.com")));
EXPECT_FALSE(check.matches(Name("example.org")));
// comparison is case insensitive
EXPECT_TRUE(check.matches(Name("EXAMPLE.COM")));
// this is exact match. so super/sub domains don't match
EXPECT_FALSE(check.matches(Name("org")));
EXPECT_FALSE(check.matches(Name("www.example.com")));
}
} // Unnamed namespace
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment