Commit 6a3dd4ec authored by Evan Hunt's avatar Evan Hunt
Browse files

DNSKEY, DS, NSEC unittests


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1025 e5f2f494-b856-4b98-b285-d166d9295462
parent 9506f69d
// Copyright (C) 2010 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.
// $Id$
#include <string>
#include <dns/base64.h>
#include <dns/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <gtest/gtest.h>
#include "unittest_util.h"
#include "rdata_unittest.h"
using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
using namespace isc::dns::rdata;
namespace {
class Rdata_DNSKEY_Test : public RdataTest {
// there's nothing to specialize
};
string dnskey_txt("257 3 5 BEAAAAOhHQDBrhQbtphgq2wQUpEQ5t4DtUHxoMV"
"Fu2hWLDMvoOMRXjGrhhCeFvAZih7yJHf8ZGfW6hd38hXG/x"
"ylYCO6Krpbdojwx8YMXLA5/kA+u50WIL8ZR1R6KTbsYVMf/"
"Qx5RiNbPClw+vT+U8eXEJmO20jIS1ULgqy347cBB1zMnnz/"
"4LJpA0da9CbKj3A254T515sNIMcwsB8/2+2E63/zZrQzBkj"
"0BrN/9Bexjpiks3jRhZatEsXn3dTy47R09Uix5WcJt+xzqZ"
"7+ysyLKOOedS39Z7SDmsn2eA0FKtQpwA6LXeG2w+jxmw3oA"
"8lVUgEf/rzeC/bByBNsO70aEFTd");
TEST_F(Rdata_DNSKEY_Test, fromText)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
EXPECT_EQ(dnskey_txt, rdata_dnskey.toText());
}
TEST_F(Rdata_DNSKEY_Test, assign)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
generic::DNSKEY rdata_dnskey2 = rdata_dnskey;
EXPECT_EQ(0, rdata_dnskey.compare(rdata_dnskey2));
}
TEST_F(Rdata_DNSKEY_Test, badText)
{
EXPECT_THROW(generic::DNSKEY rdata_dnskey("257 3 5"),
InvalidRdataText);
EXPECT_THROW(generic::DNSKEY rdata_dnskey("99999 3 5 BAAAAAAAAAAAD"),
InvalidRdataText);
EXPECT_THROW(generic::DNSKEY rdata_dnskey("257 300 5 BAAAAAAAAAAAD"),
InvalidRdataText);
EXPECT_THROW(generic::DNSKEY rdata_dnskey("257 3 500 BAAAAAAAAAAAD"),
InvalidRdataText);
EXPECT_THROW(generic::DNSKEY rdata_dnskey("257 3 5 BAAAAAAAAAAAD"),
BadBase64String);
}
TEST_F(Rdata_DNSKEY_Test, toWireRenderer)
{
renderer.skip(2);
generic::DNSKEY rdata_dnskey(dnskey_txt);
rdata_dnskey.toWire(renderer);
vector<unsigned char> data;
UnitTestUtil::readWireData("testdata/rdata_dnskey_fromWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(obuffer.getData()) + 2,
obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_DNSKEY_Test, toWireBuffer)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
rdata_dnskey.toWire(obuffer);
}
TEST_F(Rdata_DNSKEY_Test, createFromWire_DNSKEY)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
EXPECT_EQ(0, rdata_dnskey.compare(
*rdataFactoryFromFile(RRType("DNSKEY"), RRClass("IN"),
"testdata/rdata_dnskey_fromWire")));
}
TEST_F(Rdata_DNSKEY_Test, getTag_DNSKEY)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
EXPECT_EQ(12892, rdata_dnskey.getTag());
}
TEST_F(Rdata_DNSKEY_Test, getAlgorithm_DNSKEY)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
EXPECT_EQ(5, rdata_dnskey.getAlgorithm());
}
TEST_F(Rdata_DNSKEY_Test, getFlags_DNSKEY)
{
generic::DNSKEY rdata_dnskey(dnskey_txt);
EXPECT_EQ(257, rdata_dnskey.getFlags());
}
}
// Copyright (C) 2010 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.
// $Id$
#include <string>
#include <dns/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <gtest/gtest.h>
#include "unittest_util.h"
#include "rdata_unittest.h"
using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
using namespace isc::dns::rdata;
namespace {
class Rdata_DS_Test : public RdataTest {
// there's nothing to specialize
};
string ds_txt("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D"
"5F0EB5C777586DE18DA6B5");
const generic::DS rdata_ds(ds_txt);
TEST_F(Rdata_DS_Test, toText_DS)
{
EXPECT_EQ(ds_txt, rdata_ds.toText());
}
TEST_F(Rdata_DS_Test, badText_DS)
{
EXPECT_THROW(const generic::DS ds2("99999 5 2 BEEF"), InvalidRdataText);
EXPECT_THROW(const generic::DS ds2("11111 555 2 BEEF"), InvalidRdataText);
EXPECT_THROW(const generic::DS ds2("11111 5 22222 BEEF"), InvalidRdataText);
EXPECT_THROW(const generic::DS ds2("11111 5 2"), InvalidRdataText);
EXPECT_THROW(const generic::DS ds2("GARBAGE IN"), InvalidRdataText);
}
TEST_F(Rdata_DS_Test, createFromWire_DS)
{
EXPECT_EQ(0, rdata_ds.compare(
*rdataFactoryFromFile(RRType("DS"), RRClass("IN"),
"testdata/rdata_ds_fromWire")));
}
TEST_F(Rdata_DS_Test, getTag_DS)
{
EXPECT_EQ(12892, rdata_ds.getTag());
}
TEST_F(Rdata_DS_Test, toWireRenderer)
{
renderer.skip(2);
generic::DS rdata_ds(ds_txt);
rdata_ds.toWire(renderer);
vector<unsigned char> data;
UnitTestUtil::readWireData("testdata/rdata_ds_fromWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(obuffer.getData()) + 2,
obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_DS_Test, toWireBuffer)
{
generic::DS rdata_ds(ds_txt);
rdata_ds.toWire(obuffer);
}
}
// Copyright (C) 2010 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.
// $Id$
#include <string>
#include <dns/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <gtest/gtest.h>
#include "unittest_util.h"
#include "rdata_unittest.h"
using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
using namespace isc::dns::rdata;
namespace {
class Rdata_NSEC_Test : public RdataTest {
// there's nothing to specialize
};
string nsec_txt("www2.isc.org. CNAME RRSIG NSEC");
TEST_F(Rdata_NSEC_Test, toText_NSEC)
{
const generic::NSEC rdata_nsec(nsec_txt);
EXPECT_EQ(nsec_txt, rdata_nsec.toText());
}
TEST_F(Rdata_NSEC_Test, badText_NSEC)
{
EXPECT_THROW(generic::NSEC rdata_nsec("www.isc.org. BIFF POW SPOON"),
InvalidRRType);
EXPECT_THROW(generic::NSEC rdata_nsec("www.isc.org."),
InvalidRRType);
}
TEST_F(Rdata_NSEC_Test, createFromWire_NSEC)
{
const generic::NSEC rdata_nsec(nsec_txt);
EXPECT_EQ(0, rdata_nsec.compare(
*rdataFactoryFromFile(RRType("NSEC"), RRClass("IN"),
"testdata/rdata_nsec_fromWire")));
}
TEST_F(Rdata_NSEC_Test, toWireRenderer_NSEC)
{
renderer.skip(2);
const generic::NSEC rdata_nsec(nsec_txt);
rdata_nsec.toWire(renderer);
vector<unsigned char> data;
UnitTestUtil::readWireData("testdata/rdata_nsec_fromWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(obuffer.getData()) + 2,
obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_NSEC_Test, toWireBuffer_NSEC)
{
const generic::NSEC rdata_nsec(nsec_txt);
rdata_nsec.toWire(obuffer);
}
TEST_F(Rdata_NSEC_Test, assign)
{
generic::NSEC rdata_nsec(nsec_txt);
generic::NSEC rdata_nsec2 = rdata_nsec;
EXPECT_EQ(0, rdata_nsec.compare(rdata_nsec2));
}
}
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