Island: Add a check for None credentials in get_user_credentials()

This commit is contained in:
Mike Salvatore 2021-11-18 11:09:12 -05:00
parent f5e1b46a31
commit a2eab2fa5d
2 changed files with 6 additions and 1 deletions

View File

@ -51,7 +51,7 @@ class JsonFileUserDatastore(IUserDatastore):
json.dump(self._credentials.to_dict(), f, indent=2)
def get_user_credentials(self, username: str) -> UserCreds:
if self._credentials.username != username:
if self._credentials is None or self._credentials.username != username:
raise UnknownUserError(f"User {username} does not exist.")
return self._credentials

View File

@ -75,3 +75,8 @@ def test_get_user_credentials_from_file(tmp_path):
def test_get_unknown_user(populated_datastore):
with pytest.raises(UnknownUserError):
populated_datastore.get_user_credentials("unregistered_user")
def test_get_user_credentials__no_user_registered(empty_datastore):
with pytest.raises(UnknownUserError):
empty_datastore.get_user_credentials("unregistered_user")