Skip to content

Commit

Permalink
fix: use a named constant for an unspecified uid in EXTERNAL auth
Browse files Browse the repository at this point in the history
  • Loading branch information
mvn23 committed Jan 4, 2023
1 parent 692b659 commit 8084bd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/dbus_fast/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .errors import AuthError

UID_NOT_SPECIFIED = -1

# The auth interface here is unstable. I would like to eventually open this up
# for people to define their own custom authentication protocols, but I'm not
# familiar with what's needed for that exactly. To work with any message bus
Expand Down Expand Up @@ -68,7 +70,7 @@ def __init__(self, uid: int = None) -> None:
def _authentication_start(self, negotiate_unix_fd: bool = False) -> str:
self.negotiate_unix_fd = negotiate_unix_fd
uid = self.uid
if uid == -1:
if uid == UID_NOT_SPECIFIED:
return "AUTH EXTERNAL"
if uid is None:
uid = os.getuid()
Expand All @@ -88,7 +90,7 @@ def _receive_line(self, line: str) -> str:
if response is _AuthResponse.AGREE_UNIX_FD:
return "BEGIN"

if response is _AuthResponse.DATA and self.uid == -1:
if response is _AuthResponse.DATA and self.uid == UID_NOT_SPECIFIED:
return "DATA"

raise AuthError(f"authentication failed: {response.value}: {args}")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from dbus_fast.auth import AuthExternal
from dbus_fast.auth import AuthExternal, UID_NOT_SPECIFIED


def test_uid_is_set():
Expand All @@ -12,6 +12,6 @@ def test_uid_is_set():


def test_no_uid():
auth = AuthExternal(uid=-1)
auth = AuthExternal(uid=UID_NOT_SPECIFIED)
assert auth._authentication_start() == "AUTH EXTERNAL"
assert auth._receive_line("DATA") == "DATA"

0 comments on commit 8084bd4

Please sign in to comment.