From f8833f8ff65af5a4e72ee24f43bf69a51f84cd82 Mon Sep 17 00:00:00 2001 From: bneradt Date: Tue, 19 May 2026 15:54:16 -0500 Subject: [PATCH] Allow DNS search_default_domains mode 2 proxy.config.dns.search_default_domains documents mode 2, and the DNS runtime accepts it, but the record validation range rejected the value through config updates. This expands the record validation range to include 2 and adds a records unit test that keeps the documented values accepted while still rejecting values outside the range. Fixes: #13175 --- src/records/CMakeLists.txt | 2 +- src/records/RecordsConfig.cc | 2 +- src/records/unit_tests/test_RecUtils.cc | 40 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/records/unit_tests/test_RecUtils.cc diff --git a/src/records/CMakeLists.txt b/src/records/CMakeLists.txt index a06cdf74dfd..f898c818c9b 100644 --- a/src/records/CMakeLists.txt +++ b/src/records/CMakeLists.txt @@ -40,7 +40,7 @@ target_link_libraries( ) if(BUILD_TESTING) - add_executable(test_records unit_tests/unit_test_main.cc unit_tests/test_RecHttp.cc) + add_executable(test_records unit_tests/unit_test_main.cc unit_tests/test_RecHttp.cc unit_tests/test_RecUtils.cc) target_link_libraries(test_records PRIVATE records catch2::catch2 ts::tscore libswoc::libswoc) add_test(NAME test_records COMMAND test_records) diff --git a/src/records/RecordsConfig.cc b/src/records/RecordsConfig.cc index faf1e5aad0a..21f3387716e 100644 --- a/src/records/RecordsConfig.cc +++ b/src/records/RecordsConfig.cc @@ -899,7 +899,7 @@ static const RecordElement RecordsConfig[] = , {RECT_CONFIG, "proxy.config.dns.retries", RECD_INT, "5", RECU_RESTART_TS, RR_NULL, RECC_NULL, "[0-9]", RECA_NULL} , - {RECT_CONFIG, "proxy.config.dns.search_default_domains", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL} + {RECT_CONFIG, "proxy.config.dns.search_default_domains", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-2]", RECA_NULL} , {RECT_CONFIG, "proxy.config.dns.failover_number", RECD_INT, "5", RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL} , diff --git a/src/records/unit_tests/test_RecUtils.cc b/src/records/unit_tests/test_RecUtils.cc new file mode 100644 index 00000000000..03740334f90 --- /dev/null +++ b/src/records/unit_tests/test_RecUtils.cc @@ -0,0 +1,40 @@ +/** @file + + Catch-based tests for RecUtils.cc + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "catch.hpp" + +#include "../P_RecUtils.h" +#include "records/RecordsConfig.h" + +TEST_CASE("search_default_domains accepts documented values", "[librecords][RecUtils]") +{ + const auto *record = GetRecordElementByName("proxy.config.dns.search_default_domains"); + + REQUIRE(record != nullptr); + REQUIRE(record->check == RECC_INT); + REQUIRE(record->regex != nullptr); + REQUIRE(RecordValidityCheck("0", record->check, record->regex)); + REQUIRE(RecordValidityCheck("1", record->check, record->regex)); + REQUIRE(RecordValidityCheck("2", record->check, record->regex)); + REQUIRE_FALSE(RecordValidityCheck("3", record->check, record->regex)); +}