Skip to content

Commit 50d7d12

Browse files
authored
[O2-5887] Detect if an empty URL is passed to the CCDB api. (AliceO2Group#14349)
* [O2-5887] Detect if an empty URL is passed to the CCDB api. * Update testCcdbApi.cxx
1 parent 6fb9235 commit 50d7d12

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CCDB/src/CcdbApi.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ void CcdbApi::curlInit()
165165

166166
void CcdbApi::init(std::string const& host)
167167
{
168+
if (host.empty()) {
169+
throw std::invalid_argument("Empty url passed CcdbApi, cannot initialize. Aborting.");
170+
}
171+
168172
// if host is prefixed with "file://" this is a local snapshot
169173
// in this case we init the API in snapshot (readonly) mode
170174
constexpr const char* SNAPSHOTPREFIX = "file://";

CCDB/test/testCcdbApi.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,11 @@ BOOST_AUTO_TEST_CASE(vectored)
589589
for (auto context : contexts) {
590590
BOOST_CHECK(context.dest.size() != 0);
591591
}
592-
}
592+
}
593+
594+
BOOST_AUTO_TEST_CASE(empty_url)
595+
{
596+
CcdbApi api;
597+
string url = "";
598+
BOOST_CHECK_EXCEPTION(api.init(url), invalid_argument, [](std::invalid_argument const&) -> bool { return true; });
599+
}

0 commit comments

Comments
 (0)