Better handle missing usernames. Fix test.

This commit is contained in:
James Pace 2022-03-16 23:42:07 +00:00
parent a319e7f3c7
commit b18ed96444
3 changed files with 9 additions and 3 deletions

View File

@ -46,7 +46,7 @@ void Authorizer::add_unknown(const std::string& username)
bool Authorizer::is_unknown(const std::string& username)
{
return _unknownList.confirm(username);
return (username.empty() or _unknownList.confirm(username));
}
bool Authorizer::add(const std::string& token, const std::string& username)

View File

@ -102,7 +102,13 @@ int jwp_auth_basic_auth_callback(int event, void *event_data, void *userdata)
struct mosquitto_evt_basic_auth *auth_data = static_cast<struct mosquitto_evt_basic_auth*>(event_data);
if(!auth_data->username or !auth_data->password)
if(!auth_data->username)
{
// We need a username to do anything.
return MOSQ_ERR_PLUGIN_DEFER;
}
if(!auth_data->password)
{
authorizer->add_unknown(std::string(auth_data->username));
return MOSQ_ERR_PLUGIN_DEFER;

View File

@ -1,2 +1,2 @@
#!/usr/bin/env bash
/usr/local/sbin/mosquitto -v -c $PWD/mosquitto.conf
/usr/sbin/mosquitto -v -c $PWD/mosquitto.conf