Skip to content

Commit eea1187

Browse files
committed
Add error message in broker when authorization file not loaded
1 parent 26aa8c0 commit eea1187

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

example/broker.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,15 @@ void run_broker(boost::program_options::variables_map const& vm) {
409409

410410
std::ifstream input(auth_file);
411411

412-
MQTT_NS::broker::security security;
413-
security.load_json(input);
414-
b.set_security(MQTT_NS::force_move(security));
412+
if (input) {
413+
MQTT_NS::broker::security security;
414+
security.load_json(input);
415+
b.set_security(MQTT_NS::force_move(security));
416+
} else
417+
{
418+
MQTT_LOG("mqtt_broker", error)
419+
<< "Authorization file '" << auth_file << "' not found, broker doesn't use authorization file." << std::endl;
420+
}
415421
}
416422
}
417423

@@ -651,7 +657,7 @@ int main(int argc, char **argv) {
651657
std::string config_file = vm["cfg"].as<std::string>();
652658
if (!config_file.empty()) {
653659
std::ifstream input(vm["cfg"].as<std::string>());
654-
if (input.good()) {
660+
if (input) {
655661
boost::program_options::store(boost::program_options::parse_config_file(input, desc), vm);
656662
} else
657663
{

test/unit/ut_broker_security.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ BOOST_AUTO_TEST_CASE(json_comments) {
2929
BOOST_CHECK(json_remove_comments("\"#test\"") == "\"#test\"");
3030
BOOST_CHECK(json_remove_comments("\"'#test'\"") == "\"'#test'\"");
3131
BOOST_CHECK(json_remove_comments("'\"#test\"'") == "'\"#test\"'");
32+
BOOST_CHECK(json_remove_comments("") == "");
3233
}
3334

3435
BOOST_AUTO_TEST_CASE(default_config) {

0 commit comments

Comments
 (0)