feat: allow hardcoding uid in auth (#189)
Closes https://github.com/Bluetooth-Devices/dbus-fast/issues/188
This commit is contained in:
parent
bd0e80c4d6
commit
091c262e27
@ -1,6 +1,6 @@
|
||||
import enum
|
||||
import os
|
||||
from typing import List, Tuple
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from .errors import AuthError
|
||||
|
||||
@ -60,13 +60,17 @@ class AuthExternal(Authenticator):
|
||||
:sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, uid: int = None) -> None:
|
||||
self.negotiate_unix_fd: bool = False
|
||||
self.negotiating_fds: bool = False
|
||||
self.uid: Optional[int] = uid
|
||||
|
||||
def _authentication_start(self, negotiate_unix_fd: bool = False) -> str:
|
||||
self.negotiate_unix_fd = negotiate_unix_fd
|
||||
hex_uid = str(os.getuid()).encode().hex()
|
||||
uid = self.uid
|
||||
if uid is None:
|
||||
uid = os.getuid()
|
||||
hex_uid = str(uid).encode().hex()
|
||||
return f"AUTH EXTERNAL {hex_uid}"
|
||||
|
||||
def _receive_line(self, line: str) -> str:
|
||||
|
||||
11
tests/test_auth.py
Normal file
11
tests/test_auth.py
Normal file
@ -0,0 +1,11 @@
|
||||
"""This tests setting a hardcoded UID in AuthExternal"""
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast.auth import AuthExternal
|
||||
|
||||
|
||||
def test_uid_is_set():
|
||||
auth = AuthExternal(uid=999)
|
||||
assert auth._authentication_start() == "AUTH EXTERNAL 393939"
|
||||
Loading…
x
Reference in New Issue
Block a user