]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[v1_3_0] Merges in 5416 and 5522 Beanfield patches
authorThomas Markwalder <tmark@isc.org>
Fri, 2 Feb 2018 20:20:05 +0000 (15:20 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 2 Feb 2018 20:20:05 +0000 (15:20 -0500)
1  2 
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc

index ef0703f5bc191e84fbfca198b706117228b65a3b,ead3b672cef53b1be35e1129308672ccd035c10a..954155e401380b172ded5a935afa11d2a5483a48
@@@ -1406,7 -1423,7 +1423,7 @@@ TaggedStatementArray tagged_statements 
      // and client's identifier. Left joining the dhcp4_options table results in
      // multiple rows being returned for the same host.
      {3,
--     { OID_INT4, OID_INT2, OID_BYTEA },
++     { OID_INT8, OID_INT2, OID_BYTEA },
       "get_host_subid4_dhcpid",
       "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
       "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      // associated with a host. The number of rows returned is a multiplication
      // of number of IPv6 reservations and DHCPv6 options.
      {3,
--     { OID_INT4, OID_INT2, OID_BYTEA },
++     { OID_INT8, OID_INT2, OID_BYTEA },
       "get_host_subid6_dhcpid",
       "SELECT h.host_id, h.dhcp_identifier, "
       "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
      // results in multiple rows being returned for the host. The number of
      // rows depends on the number of options defined for the host.
      {2,
--     { OID_INT4, OID_INT8 },
++     { OID_INT8, OID_INT8 },
       "get_host_subid_addr",
       "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
       "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      // The number of rows returned is multiplication of number of existing
      // IPv6 reservations and DHCPv6 options.
      {2,
--     { OID_INT4, OID_VARCHAR },
++     { OID_INT8, OID_VARCHAR },
       "get_host_subid6_addr",
       "SELECT h.host_id, h.dhcp_identifier, "
       "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
      // Inserts a host into the 'hosts' table. Returns the inserted host id.
      {11,
       { OID_BYTEA, OID_INT2,
--       OID_INT4, OID_INT4, OID_INT8, OID_VARCHAR,
++       OID_INT8, OID_INT8, OID_INT8, OID_VARCHAR,
         OID_VARCHAR, OID_VARCHAR },
       "insert_host",
       "INSERT INTO hosts(dhcp_identifier, dhcp_identifier_type, "
      // PgSqlHostDataSourceImpl::DEL_HOST_ADDR4
      // Deletes a v4 host that matches (subnet-id, addr4)
      {2,
--     { OID_INT4, OID_INT8 },
++     { OID_INT8, OID_INT8 },
       "del_host_addr4",
       "DELETE FROM hosts WHERE dhcp4_subnet_id = $1 AND ipv4_address = $2"
      },
      // PgSqlHostDataSourceImpl::DEL_HOST_SUBID4_ID
      // Deletes a v4 host that matches (subnet4-id, identifier-type, identifier)
      {3,
--     { OID_INT4, OID_INT2, OID_BYTEA },
++     { OID_INT8, OID_INT2, OID_BYTEA },
       "del_host_subid4_id",
       "DELETE FROM hosts WHERE dhcp4_subnet_id = $1 "
       "AND dhcp_identifier_type = $2 "
      // PgSqlHostDataSourceImpl::DEL_HOST_SUBID6_ID
      // Deletes a v6 host that matches (subnet6-id, identifier-type, identifier)
      {3,
--     { OID_INT4, OID_INT2, OID_BYTEA },
++     { OID_INT8, OID_INT2, OID_BYTEA },
       "del_host_subid6_id",
       "DELETE FROM hosts WHERE dhcp6_subnet_id = $1 "
       "AND dhcp_identifier_type = $2 "
index 75e46c14b4bf644b0cce4a6a18b9d15799bc8930,71f9f46f7e4665dfe7e03beec2c2e5d2f09aa7d2..cf5733dd7b327de8f6bedf6a4a90fdb54bf1cfd9
@@@ -581,6 -581,6 +581,67 @@@ void GenericHostDataSourceTest::testBas
      compareHosts(host, from_hds);
  }
  
++void GenericHostDataSourceTest::testMaxSubnetId4() {
++    std::vector<uint8_t> ident;
++
++    ident = generateIdentifier();
++    SubnetID subnet_id4 = numeric_limits<uint32_t>::max();
++    HostPtr host(new Host(&ident[0], ident.size(), Host::IDENT_DUID, 
++                          subnet_id4, 0, IOAddress("0.0.0.0")));
++
++    ASSERT_NO_THROW(addTestOptions(host, true, DHCP4_ONLY));
++    ASSERT_NO_THROW(hdsptr_->add(host));
++
++    // get4(subnet_id, identifier_type, identifier, identifier_size)
++    ConstHostPtr host_by_id = hdsptr_->get4(subnet_id4,
++                                            host->getIdentifierType(),
++                                            &host->getIdentifier()[0],
++                                            host->getIdentifier().size());
++
++    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_id));
++
++    // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
++    EXPECT_TRUE(hdsptr_->del4(subnet_id4, Host::IDENT_DUID, &ident[0], 
++                              ident.size()));
++
++    host_by_id = hdsptr_->get4(subnet_id4, host->getIdentifierType(),
++                               &host->getIdentifier()[0],
++                               host->getIdentifier().size());
++
++    EXPECT_FALSE(host_by_id);
++}
++
++void GenericHostDataSourceTest::testMaxSubnetId6() {
++    std::vector<uint8_t> ident;
++
++    ident = generateIdentifier();
++    SubnetID subnet_id6 = numeric_limits<uint32_t>::max();
++    HostPtr host(new Host(&ident[0], ident.size(), Host::IDENT_DUID, 
++                          0, subnet_id6, IOAddress("0.0.0.0")));
++
++    ASSERT_NO_THROW(addTestOptions(host, true, DHCP6_ONLY));
++    ASSERT_NO_THROW(hdsptr_->add(host));
++
++    // get6(subnet_id, identifier_type, identifier, identifier_size)
++    ConstHostPtr host_by_id = hdsptr_->get6(subnet_id6,
++                                            host->getIdentifierType(),
++                                            &host->getIdentifier()[0],
++                                            host->getIdentifier().size());
++
++    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_id));
++
++    // Now try to delete it: del6(subnet6-id, identifier-type, identifier)
++    EXPECT_TRUE(hdsptr_->del6(subnet_id6, Host::IDENT_DUID, &ident[0], 
++                              ident.size()));
++
++    host_by_id = hdsptr_->get4(subnet_id6, host->getIdentifierType(),
++                               &host->getIdentifier()[0],
++                               host->getIdentifier().size());
++
++    EXPECT_FALSE(host_by_id);
++}
++
++
  
  void GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
      // Make sure we have a pointer to the host data source.
index c5bef733460c105109092257fcbd39e665f53521,d41d539de1af10f426a810d03a33cbd536113622..f578000d268d2de6a1a9278fe2b8e88cb5e1182b
@@@ -394,6 -394,6 +394,18 @@@ public
      /// @param id Identifier type.
      void testBasic4(const Host::IdentifierType& id);
  
++    /// @brief Test that Verifies that an IPv4 host reservation with
++    /// options can have a max value for dhcp4_subnet id
++    ///
++    /// Uses gtest macros to report failures.
++    void testMaxSubnetId4();
++
++    /// @brief Test that Verifies that an IPv6 host reservation with
++    /// options can have a max value for dhcp6_subnet id
++    ///
++    /// Uses gtest macros to report failures.
++    void testMaxSubnetId6();
++
      /// @brief Test inserts several hosts with unique IPv4 address and
      ///        checks that they can be retrieved properly.
      ///
index 2ca2b0f67a3297d058bba88103d777a888249c48,da76ca04748e7038e03451d0db98248b80624216..2719e46e80611e0ec1150f91602c1fc29e7fa907
@@@ -271,6 -271,6 +271,18 @@@ TEST_F(MySqlHostDataSourceTest, basic4H
      testBasic4(Host::IDENT_HWADDR);
  }
  
++// Verifies that IPv4 host reservation with options can have a max value
++// for  dhcp4_subnet id
++TEST_F(MySqlHostDataSourceTest, maxSubnetId4) {
++    testMaxSubnetId4();
++}
++
++// Verifies that IPv6 host reservation with options can have a max value
++// for  dhcp6_subnet id
++TEST_F(MySqlHostDataSourceTest, maxSubnetId6) {
++    testMaxSubnetId6();
++}
++
  // Test verifies if a host reservation can be added and later retrieved by IPv4
  // address. Host uses client-id (DUID) as identifier.
  TEST_F(MySqlHostDataSourceTest, basic4ClientId) {
index f9aae9d93d3daa0a0022cc054d33d1479339c771,d0dbba539451627ecc2da8cdd6a376c4fcbc337f..d6ac295e79e1c1dd31d449c90b1ace2f685f857a
@@@ -227,6 -227,6 +227,18 @@@ TEST_F(PgSqlHostDataSourceTest, basic4H
      testBasic4(Host::IDENT_HWADDR);
  }
  
++// Verifies that IPv4 host reservation with options can have a max value
++// for  dhcp4_subnet id
++TEST_F(PgSqlHostDataSourceTest, maxSubnetId4) {
++    testMaxSubnetId4();
++}
++
++// Verifies that IPv6 host reservation with options can have a max value
++// for  dhcp6_subnet id
++TEST_F(PgSqlHostDataSourceTest, maxSubnetId6) {
++    testMaxSubnetId6();
++}
++
  // Test verifies if a host reservation can be added and later retrieved by IPv4
  // address. Host uses client-id (DUID) as identifier.
  TEST_F(PgSqlHostDataSourceTest, basic4ClientId) {