Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jenkins/python3-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ python3 setup.py build
python3 setup.py build_ext --inplace

# make sure we have a dbus session for the dbus tests
dbus-run-session coverage run
dbus-run-session coverage run -m pytest -vvl

coverage report
coverage xml
14 changes: 13 additions & 1 deletion src/rhsmlib/dbus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ class DomainSocketServer(object):
session bus since those aren't really locked down. The work-around is the client asks our service
to open another server on a domain socket, gets socket information back, and then connects and sends
the register command (with the credentials) to the server on the domain socket."""

# FIXME Use `dir` instead.
# `tmpdir` behaves differently from `dir` on old versions of dbus
# (earlier than 1.12.24 and 1.14.4).
# In newer versions we are not getting abstract socket anymore.
_server_socket_iface: str = "unix:tmpdir="
_server_socket_path: str = "/run"

@property
def _server_socket(self):
return self._server_socket_iface + self._server_socket_path

@staticmethod
def connection_added(domain_socket_server, service_class, object_list, conn):
object_list.append(service_class(conn=conn))
Expand Down Expand Up @@ -305,7 +317,7 @@ def shutdown(self):

def run(self):
try:
self._server = dbus.server.Server("unix:tmpdir=/run")
self._server = dbus.server.Server(self._server_socket)

for clazz in self.object_classes:
self._server.on_connection_added.append(
Expand Down
24 changes: 18 additions & 6 deletions test/rhsmlib_test/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import dbus.connection
import socket
import six
import tempfile
from typing import Optional

import subscription_manager.injection as inj

Expand All @@ -38,6 +40,7 @@
from rhsm import connection

from rhsmlib.dbus import constants
from rhsmlib.dbus.server import DomainSocketServer
from rhsmlib.dbus.objects import RegisterDBusObject

from rhsmlib.services import register, exceptions
Expand Down Expand Up @@ -743,6 +746,8 @@ def test_requires_basic_auth_for_normal_registration(self):

@subman_marker_dbus
class DomainSocketRegisterDBusObjectTest(DBusObjectTest, InjectionMockingTest):
socket_dir: Optional[tempfile.TemporaryDirectory] = None

def dbus_objects(self):
return [RegisterDBusObject]

Expand Down Expand Up @@ -788,6 +793,16 @@ def setUp(self):
self.mock_ent_cert_service_invoker = ent_cert_service_patcher.start()
self.addCleanup(ent_cert_service_patcher.stop)

self.socket_dir = tempfile.TemporaryDirectory()
self.addCleanup(self.socket_dir.cleanup)
socket_path_patch = mock.patch.object(DomainSocketServer, "_server_socket_path", self.socket_dir.name)
socket_path_patch.start()
# `tmpdir` behaves differently from `dir` on old versions of dbus
# (earlier than 1.12.24 and 1.14.4).
# In newer versions we are not getting abstract socket anymore.
socket_iface_patch = mock.patch.object(DomainSocketServer, "_server_socket_iface", "unix:dir=")
socket_iface_patch.start()

def injection_definitions(self, *args, **kwargs):
if args[0] == inj.IDENTITY:
return self.mock_identity
Expand All @@ -801,7 +816,7 @@ def test_open_domain_socket(self):

def assertions(*args):
result = args[0]
six.assertRegex(self, result, r'/run/dbus.*')
six.assertRegex(self, result, self.socket_dir.name + "/dbus.*")

self.dbus_request(assertions, self.interface.Start, dbus_method_args)

Expand All @@ -812,7 +827,7 @@ def assertions(*args):
# Assign the result as an attribute to this function.
# See http://stackoverflow.com/a/27910553/6124862
assertions.result = args[0]
six.assertRegex(self, assertions.result, r'/run/dbus.*')
six.assertRegex(self, assertions.result, self.socket_dir.name + "/dbus.*")

self.dbus_request(assertions, self.interface.Start, dbus_method_args)

Expand Down Expand Up @@ -844,10 +859,7 @@ def get_address(*args):

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
# The socket returned for connection is an abstract socket so we have
# to begin the name with a NUL byte to get into that namespace. See
# http://blog.eduardofleury.com/archives/2007/09/13
sock.connect('\0' + get_address.address)
sock.connect(get_address.address)
finally:
sock.close()

Expand Down