From: Francis Dupont Date: Thu, 29 Apr 2021 16:00:18 +0000 (+0200) Subject: [(no branch, rebasing 1815-add-new-drop-points)] [(no branch, rebasing 1815-add-new... X-Git-Tag: Kea-1.9.8~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1b7e159f2e357cbc1a3a0d46ff92aa2b8aff801;p=thirdparty%2Fkea.git [(no branch, rebasing 1815-add-new-drop-points)] [(no branch, rebasing 1815-add-new-drop-points)] [#1815] Added a new unit test --- diff --git a/src/bin/dhcp4/tests/classify_unittest.cc b/src/bin/dhcp4/tests/classify_unittest.cc index b7f4ab8e76..639e821f4e 100644 --- a/src/bin/dhcp4/tests/classify_unittest.cc +++ b/src/bin/dhcp4/tests/classify_unittest.cc @@ -83,7 +83,7 @@ namespace { /// - the following class defined: option[93].hex == 0x0009, DROP /// /// - Configuration 6: -/// - Used for the DROP class and reservations. +/// - Used for the DROP class and reservation existence. /// - 1 subnet: 10.0.0.0/24 /// - 1 pool: 10.0.0.10-10.0.0.100 /// - 1 reservation for HW address 'aa:bb:cc:dd:ee:ff' @@ -93,6 +93,17 @@ namespace { /// @note the reservation includes a hostname because raw reservations are /// not yet allowed. /// +/// - Configuration 7: +/// - Used for the DROP class and reservation class. +/// - 1 subnet: 10.0.0.0/24 +/// - 1 pool: 10.0.0.10-10.0.0.100 +/// - 1 reservation for HW address 'aa:bb:cc:dd:ee:ff' +/// setting the allowed class +/// - the following classes defined: +/// - allowed +/// - member('KNOWN') or member('UNKNOWN'), t +/// not member('allowed') and member('t'), DROP +/// const char* CONFIGS[] = { // Configuration 0 "{ \"interfaces-config\": {" @@ -318,7 +329,7 @@ const char* CONFIGS[] = { "\"client-classes\": [" "{" " \"name\": \"DROP\"," - " \"test\": \"member('UNKNOWN')\"" + " \"test\": \"not member('KNOWN')\"" "}]," "\"subnet4\": [ { " " \"subnet\": \"10.0.0.0/24\", " @@ -328,6 +339,33 @@ const char* CONFIGS[] = { " \"hw-address\": \"aa:bb:cc:dd:ee:ff\"," " \"hostname\": \"allowed\" } ]" " } ]" + "}", + + // Configuration 7 + "{ \"interfaces-config\": {" + " \"interfaces\": [ \"*\" ]" + "}," + "\"valid-lifetime\": 600," + "\"client-classes\": [" + "{" + " \"name\": \"allowed\"" + "}," + "{" + " \"name\": \"t\"," + " \"test\": \"member('KNOWN') or member('UNKNOWN')\"" + "}," + "{" + " \"name\": \"DROP\"," + " \"test\": \"not member('allowed') and member('t')\"" + "}]," + "\"subnet4\": [ { " + " \"subnet\": \"10.0.0.0/24\", " + " \"id\": 1," + " \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]," + " \"reservations\": [ {" + " \"hw-address\": \"aa:bb:cc:dd:ee:ff\"," + " \"client-classes\": [ \"allowed\" ] } ]" + " } ]" "}" }; @@ -1196,8 +1234,44 @@ TEST_F(ClassifyTest, dropClass) { } // This test checks the handling for the DROP special class at the host -// reservation classification point. -TEST_F(ClassifyTest, dropClassHR) { +// reservation classification point with KNOWN / UNKNOWN. +TEST_F(ClassifyTest, dropClassUnknown) { + Dhcp4Client client(Dhcp4Client::SELECTING); + + // Configure DHCP server. + configure(CONFIGS[6], *client.getServer()); + + // Set the HW address to the reservation. + client.setHWAddress("aa:bb:cc:dd:ee:ff"); + + // Send the discover. + client.doDiscover(); + + // Reservation match: no drop. + EXPECT_TRUE(client.getContext().response_); + + // Retry with another HW address. + Dhcp4Client client2(Dhcp4Client::SELECTING); + client2.setHWAddress("aa:bb:cc:dd:ee:fe"); + + // Send the discover. + client2.doDiscover(); + + // No reservation, dropped. + EXPECT_FALSE(client2.getContext().response_); + + // There should also be pkt4-receive-drop stat bumped up. + stats::StatsMgr& mgr = stats::StatsMgr::instance(); + stats::ObservationPtr drop_stat = mgr.getObservation("pkt4-receive-drop"); + + // This statistic must be present and must be set to 1. + ASSERT_TRUE(drop_stat); + EXPECT_EQ(1, drop_stat->getInteger().first); +} + +// This test checks the handling for the DROP special class at the host +// reservation classification point with a reserved class. +TEST_F(ClassifyTest, dropClassReservedClass) { Dhcp4Client client(Dhcp4Client::SELECTING); // Configure DHCP server.