From: Francis Dupont Date: Sat, 7 Apr 2018 22:37:01 +0000 (+0200) Subject: [5374] Finished to address comments X-Git-Tag: trac5458a_base~14^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=317b6afe7d6777240cc678c3eec5c5d7d5732e0b;p=thirdparty%2Fkea.git [5374] Finished to address comments --- diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index 2c92453ab8..293e8506c0 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -1205,6 +1205,41 @@ public: ASSERT_NO_FATAL_FAILURE(verifyAssignedStats()); } + /// @brief Check precedence. + /// + /// @param config the configuration. + /// @param ns_address expected name server address. + void testPrecedence(const std::string& config, const std::string& ns_address) { + // Create client and set MAC address to the one that has a reservation. + Dhcp4Client client(Dhcp4Client::SELECTING); + client.setIfaceName("eth1"); + client.setHWAddress("aa:bb:cc:dd:ee:ff"); + // Request domain-name-servers. + client.requestOptions(DHO_DOMAIN_NAME_SERVERS); + + // Create server configuration. + configure(config, *client.getServer()); + + // Perform a DORA. + doDORA(client, "192.0.2.28", "192.0.2.28"); + + // Check response. + Pkt4Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + EXPECT_EQ(DHCPACK, resp->getType()); + EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); + + // Check domain-name-servers option. + OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); + ASSERT_TRUE(opt); + Option4AddrLstPtr servers = + boost::dynamic_pointer_cast(opt); + ASSERT_TRUE(servers); + auto addrs = servers->getAddresses(); + ASSERT_EQ(1, addrs.size()); + EXPECT_EQ(ns_address, addrs[0].toText()); + } + /// @brief Destructor. virtual ~Dhcpv4SharedNetworkTest() { StatsMgr::instance().removeAll(); @@ -2091,34 +2126,7 @@ TEST_F(Dhcpv4SharedNetworkTest, precedenceGlobal) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("192.0.2.1", addrs[0].toText()); + testPrecedence(config, "192.0.2.1"); } // Verify option processing precedence @@ -2173,34 +2181,7 @@ TEST_F(Dhcpv4SharedNetworkTest, precedenceClass) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("192.0.2.2", addrs[0].toText()); + testPrecedence(config, "192.0.2.2"); } // Verify option processing precedence @@ -2265,35 +2246,8 @@ TEST_F(Dhcpv4SharedNetworkTest, precedenceClasses) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); // Class order is the insert order - EXPECT_EQ("192.0.2.2", addrs[0].toText()); + testPrecedence(config, "192.0.2.2"); } // Verify option processing precedence @@ -2354,34 +2308,7 @@ TEST_F(Dhcpv4SharedNetworkTest, precedenceNetwork) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("192.0.2.3", addrs[0].toText()); + testPrecedence(config, "192.0.2.3"); } // Verify option processing precedence @@ -2448,34 +2375,7 @@ TEST_F(Dhcpv4SharedNetworkTest, precedenceSubnet) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("192.0.2.4", addrs[0].toText()); + testPrecedence(config, "192.0.2.4"); } // Verify option processing precedence @@ -2548,34 +2448,7 @@ TEST_F(Dhcpv4SharedNetworkTest, precedencePool) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("192.0.2.5", addrs[0].toText()); + testPrecedence(config, "192.0.2.5"); } // Verify option processing precedence @@ -2654,34 +2527,7 @@ TEST_F(Dhcpv4SharedNetworkTest, precedenceReservation) { " ]" "}"; - // Create client and set MAC address to the one that has a reservation. - Dhcp4Client client(Dhcp4Client::SELECTING); - client.setIfaceName("eth1"); - client.setHWAddress("aa:bb:cc:dd:ee:ff"); - // Request domain-name-servers - client.requestOptions(DHO_DOMAIN_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform a DORA - doDORA(client, "192.0.2.28", "192.0.2.28"); - - // Check response - Pkt4Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - EXPECT_EQ(DHCPACK, resp->getType()); - EXPECT_EQ("192.0.2.28", resp->getYiaddr().toText()); - - // Check domain-name-servers option - OptionPtr opt = resp->getOption(DHO_DOMAIN_NAME_SERVERS); - ASSERT_TRUE(opt); - Option4AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("192.0.2.6", addrs[0].toText()); + testPrecedence(config, "192.0.2.6"); } } // end of anonymous namespace diff --git a/src/bin/dhcp6/tests/classify_unittests.cc b/src/bin/dhcp6/tests/classify_unittests.cc index 6ca129a4bb..c7d90acdbd 100644 --- a/src/bin/dhcp6/tests/classify_unittests.cc +++ b/src/bin/dhcp6/tests/classify_unittests.cc @@ -235,14 +235,18 @@ const char* CONFIGS[] = { "\"subnet6\": [ " "{ \"subnet\": \"2001:db8::/32\", " " \"interface\": \"eth1\"," - " \"pools\": [ " - " { \"pool\": \"2001:db8:1::/48\"," + " \"pd-pools\": [ " + " { \"prefix\": \"2001:db8:1::\"," + " \"prefix-len\": 48, \"delegated-len\": 64," " \"client-class\": \"server1_and_telephones\" }," - " { \"pool\": \"2001:db8:2::/48\"," + " { \"prefix\": \"2001:db8:2::\"," + " \"prefix-len\": 48, \"delegated-len\": 64," " \"client-class\": \"server1_and_computers\" }," - " { \"pool\": \"2001:db8:3::/48\"," + " { \"prefix\": \"2001:db8:3::\"," + " \"prefix-len\": 48, \"delegated-len\": 64," " \"client-class\": \"server2_and_telephones\" }," - " { \"pool\": \"2001:db8:4::/48\"," + " { \"prefix\": \"2001:db8:4::\"," + " \"prefix-len\": 48, \"delegated-len\": 64," " \"client-class\": \"server2_and_computers\" } ]" " } ]," "\"valid-lifetime\": 4000 }" @@ -1721,4 +1725,204 @@ TEST_F(ClassifyTest, server1Telephone) { EXPECT_EQ("2001:db8:1:1::", lease_client.addr_.toText()); } +// This test checks the complex membership from HA with server1 computer. +TEST_F(ClassifyTest, server1Computer) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestAddress(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "bar")); + client.addExtraOption(hostname); + + // Add server1 + client.addClass("server1"); + + // Load the config and perform a SARR + configure(CONFIGS[1], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The address is from the second pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:1:2::", lease_client.addr_.toText()); +} + +// This test checks the complex membership from HA with server2 telephone. +TEST_F(ClassifyTest, server2Telephone) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestAddress(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "foo")); + client.addExtraOption(hostname); + + // Add server2 + client.addClass("server2"); + + // Load the config and perform a SARR + configure(CONFIGS[1], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The address is from the third pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:1:3::", lease_client.addr_.toText()); +} + +// This test checks the complex membership from HA with server2 computer. +TEST_F(ClassifyTest, server2Computer) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestAddress(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "bar")); + client.addExtraOption(hostname); + + // Add server2 + client.addClass("server2"); + + // Load the config and perform a SARR + configure(CONFIGS[1], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The address is from the forth pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:1:4::", lease_client.addr_.toText()); +} + +// This test checks the complex membership from HA with server1 telephone +// with prefixes. +TEST_F(ClassifyTest, pDserver1Telephone) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestPrefix(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "foo")); + client.addExtraOption(hostname); + + // Add server1 + client.addClass("server1"); + + // Load the config and perform a SARR + configure(CONFIGS[2], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The prefix is from the first pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:1::", lease_client.addr_.toText()); +} + +// This test checks the complex membership from HA with server1 computer +// with prefix. +TEST_F(ClassifyTest, pDserver1Computer) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestPrefix(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "bar")); + client.addExtraOption(hostname); + + // Add server1 + client.addClass("server1"); + + // Load the config and perform a SARR + configure(CONFIGS[2], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The prefix is from the second pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:2::", lease_client.addr_.toText()); +} + +// This test checks the complex membership from HA with server2 telephone +// with prefixes. +TEST_F(ClassifyTest, pDserver2Telephone) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestPrefix(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "foo")); + client.addExtraOption(hostname); + + // Add server2 + client.addClass("server2"); + + // Load the config and perform a SARR + configure(CONFIGS[2], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The prefix is from the third pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:3::", lease_client.addr_.toText()); +} + +// This test checks the complex membership from HA with server2 computer +// with prefix. +TEST_F(ClassifyTest, pDserver2Computer) { + // Create a client. + Dhcp6Client client; + client.setInterface("eth1"); + ASSERT_NO_THROW(client.requestPrefix(0xabca0)); + + // Add option. + OptionStringPtr hostname(new OptionString(Option::V6, 1234, "bar")); + client.addExtraOption(hostname); + + // Add server2 + client.addClass("server2"); + + // Load the config and perform a SARR + configure(CONFIGS[2], *client.getServer()); + ASSERT_NO_THROW(client.doSARR()); + + // Check response + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // The prefix is from the forth pool. + ASSERT_EQ(1, client.getLeaseNum()); + Lease6 lease_client = client.getLease(0); + EXPECT_EQ("2001:db8:4::", lease_client.addr_.toText()); +} + } // end of anonymous namespace diff --git a/src/bin/dhcp6/tests/shared_network_unittest.cc b/src/bin/dhcp6/tests/shared_network_unittest.cc index 1f12e76e9f..800db9cc55 100644 --- a/src/bin/dhcp6/tests/shared_network_unittest.cc +++ b/src/bin/dhcp6/tests/shared_network_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -1452,6 +1452,41 @@ public: } } + /// @brief Check precedence. + /// + /// @param config the configuration. + /// @param ns_address expected name server address. + void testPrecedence(const std::string& config, const std::string& ns_address) { + // Create client and set DUID to the one that has a reservation. + Dhcp6Client client; + client.setInterface("eth1"); + client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); + client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); + // Request dns-servers. + client.requestOption(D6O_NAME_SERVERS); + + // Create server configuration. + configure(config, *client.getServer()); + + // Perform SARR. + ASSERT_NO_THROW(client.doSARR()); + + // Check response. + EXPECT_EQ(1, client.getLeaseNum()); + Pkt6Ptr resp = client.getContext().response_; + ASSERT_TRUE(resp); + + // Check dns-servers option. + OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); + ASSERT_TRUE(opt); + Option6AddrLstPtr servers = + boost::dynamic_pointer_cast(opt); + ASSERT_TRUE(servers); + auto addrs = servers->getAddresses(); + ASSERT_EQ(1, addrs.size()); + EXPECT_EQ(ns_address, addrs[0].toText()); + } + /// @brief Destructor. virtual ~Dhcpv6SharedNetworkTest() { StatsMgr::instance().removeAll(); @@ -2469,34 +2504,7 @@ TEST_F(Dhcpv6SharedNetworkTest, precedenceGlobal) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("2001:db8:1::1", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::1"); } // Verify option processing precedence @@ -2547,34 +2555,7 @@ TEST_F(Dhcpv6SharedNetworkTest, precedenceClass) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("2001:db8:1::2", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::2"); } // Verify option processing precedence @@ -2635,35 +2616,8 @@ TEST_F(Dhcpv6SharedNetworkTest, precedenceClasses) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); // Class order is the insert order - EXPECT_EQ("2001:db8:1::2", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::2"); } // Verify option processing precedence @@ -2720,34 +2674,7 @@ TEST_F(Dhcpv6SharedNetworkTest, precedenceNetworkClass) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("2001:db8:1::3", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::3"); } // Verify option processing precedence @@ -2810,34 +2737,7 @@ TEST_F(Dhcpv6SharedNetworkTest, precedenceSubnet) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("2001:db8:1::4", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::4"); } // Verify option processing precedence @@ -2906,34 +2806,7 @@ TEST_F(Dhcpv6SharedNetworkTest, precedencePool) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("2001:db8:1::5", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::5"); } // Verify option processing precedence @@ -3008,34 +2881,7 @@ TEST_F(Dhcpv6SharedNetworkTest, precedenceReservation) { " ]" "}"; - // Create client and set DUID to the one that has a reservation. - Dhcp6Client client; - client.setInterface("eth1"); - client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff"); - client.requestAddress(0xabca, IOAddress("2001:db8:1::28")); - // Request dns-servers - client.requestOption(D6O_NAME_SERVERS); - - // Create server configuration - configure(config, *client.getServer()); - - // Perform SARR - ASSERT_NO_THROW(client.doSARR()); - - // Check response - EXPECT_EQ(1, client.getLeaseNum()); - Pkt6Ptr resp = client.getContext().response_; - ASSERT_TRUE(resp); - - // Check dns-servers option - OptionPtr opt = resp->getOption(D6O_NAME_SERVERS); - ASSERT_TRUE(opt); - Option6AddrLstPtr servers = - boost::dynamic_pointer_cast(opt); - ASSERT_TRUE(servers); - auto addrs = servers->getAddresses(); - ASSERT_EQ(1, addrs.size()); - EXPECT_EQ("2001:db8:1::6", addrs[0].toText()); + testPrecedence(config, "2001:db8:1::6"); } } // end of anonymous namespace diff --git a/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc b/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc index 474c551f25..d3af6cf043 100644 --- a/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -925,6 +925,19 @@ TEST_F(ClientClassDefListParserTest, dependentList) { EXPECT_EQ("three", cclass->getName()); } +// Verifies that not defined dependencies will not parse. +TEST_F(ClientClassDefListParserTest, dependentNotDefined) { + std::string cfg_text = + "[ \n" + " { \n" + " \"name\": \"one\", \n" + " \"test\": \"member('foo')\" \n" + " } \n" + "] \n"; + + EXPECT_THROW(parseClientClassDefList(cfg_text, AF_INET6), DhcpConfigError); +} + // Verifies that forward dependencies will not parse. TEST_F(ClientClassDefListParserTest, dependentForwardError) { std::string cfg_text = @@ -932,10 +945,29 @@ TEST_F(ClientClassDefListParserTest, dependentForwardError) { " { \n" " \"name\": \"one\", \n" " \"test\": \"member('foo')\" \n" + " }, \n" + " { \n" + " \"name\": \"foo\" \n" " } \n" "] \n"; EXPECT_THROW(parseClientClassDefList(cfg_text, AF_INET6), DhcpConfigError); } +// Verifies that backward dependencies will parse. +TEST_F(ClientClassDefListParserTest, dependentBackward) { + std::string cfg_text = + "[ \n" + " { \n" + " \"name\": \"foo\" \n" + " }, \n" + " { \n" + " \"name\": \"one\", \n" + " \"test\": \"member('foo')\" \n" + " } \n" + "] \n"; + + EXPECT_NO_THROW(parseClientClassDefList(cfg_text, AF_INET6)); +} + } // end of anonymous namespace