From 02d68188d79ae96009b8bb21c1d3faf6e6d7632d Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 3 Jun 2025 09:33:17 +0200 Subject: [PATCH 1/2] [O2-5887] Detect if an empty URL is passed to the CCDB api. --- CCDB/src/CcdbApi.cxx | 4 ++++ CCDB/test/testCcdbApi.cxx | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/CCDB/src/CcdbApi.cxx b/CCDB/src/CcdbApi.cxx index c9d2fad882aa1..1836716688867 100644 --- a/CCDB/src/CcdbApi.cxx +++ b/CCDB/src/CcdbApi.cxx @@ -164,6 +164,10 @@ void CcdbApi::curlInit() void CcdbApi::init(std::string const& host) { + if (host.empty()) { + throw std::invalid_argument("Empty url passed CcdbApi, cannot initialize. Aborting."); + } + // if host is prefixed with "file://" this is a local snapshot // in this case we init the API in snapshot (readonly) mode constexpr const char* SNAPSHOTPREFIX = "file://"; diff --git a/CCDB/test/testCcdbApi.cxx b/CCDB/test/testCcdbApi.cxx index c834f2f30f64a..a9f09952ac885 100644 --- a/CCDB/test/testCcdbApi.cxx +++ b/CCDB/test/testCcdbApi.cxx @@ -589,4 +589,11 @@ BOOST_AUTO_TEST_CASE(vectored) for (auto context : contexts) { BOOST_CHECK(context.dest.size() != 0); } +} + +BOOST_AUTO_TEST_CASE(empty_url) +{ + CcdbApi api; + ccdbUrl = ""; + BOOST_CHECK_EXCEPTION(api.init(ccdbUrl), invalid_argument, [](std::invalid_argument const&) -> bool { return true; }); } \ No newline at end of file From 043c8e4a3a41696704be481608651497e214993d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Thu, 9 Oct 2025 15:32:37 +0200 Subject: [PATCH 2/2] Update testCcdbApi.cxx --- CCDB/test/testCcdbApi.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CCDB/test/testCcdbApi.cxx b/CCDB/test/testCcdbApi.cxx index a9f09952ac885..6572a6dcba462 100644 --- a/CCDB/test/testCcdbApi.cxx +++ b/CCDB/test/testCcdbApi.cxx @@ -594,6 +594,6 @@ BOOST_AUTO_TEST_CASE(vectored) BOOST_AUTO_TEST_CASE(empty_url) { CcdbApi api; - ccdbUrl = ""; - BOOST_CHECK_EXCEPTION(api.init(ccdbUrl), invalid_argument, [](std::invalid_argument const&) -> bool { return true; }); -} \ No newline at end of file + string url = ""; + BOOST_CHECK_EXCEPTION(api.init(url), invalid_argument, [](std::invalid_argument const&) -> bool { return true; }); +}