Closed M-Bab closed 4 years ago
Is it possible to write tests for this?
It is - if there is a CI system available where a tcp-dbus connection is possible. Currently we are using a special test system where the dbus is open to the network and allows anonymous authentification (very evil).
I will try out if a simple, safe and effective test can be implemented with socat on the loopback interface.
Okay I managed to get it fully working for a local test:
Open a local socket:
socat TCP-LISTEN:55556,reuseaddr,fork,range=127.0.0.1/32 UNIX-CONNECT:$(echo $DBUS_SESSION_BUS_ADDRESS | sed 's/unix:path=//g')
This piece of code creates a notification via tcp:
import asyncio
import sys
from dbus_next.aio import MessageBus
#from dbus_next.message import Message, MessageType
async def main(args): bus = await MessageBus(bus_address="tcp:host=127.0.0.1,port=55556").connect()
introspection = await bus.introspect('org.freedesktop.Notifications', '/org/freedesktop/Notifications') obj = bus.get_proxy_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications', introspection) notification = obj.get_interface('org.freedesktop.Notifications') await notification.call_notify("test.py", 0, "", "DBus Test", "Test notification", [""], dict(), 3000)
if name == "main": loop = asyncio.get_event_loop() basefilename = loop.run_until_complete(main(sys.argv))
It is somehow amazing that it works because neither d-feet nor notify-send were able to connect to the socat in my case.
Or what kind of tests specifically shall I add?
The only way I can ensure this will be stable with future changes if you add tests to the test suite for your use cases.
Here you go :+1:. Added 2 tests which are simple but should be very effective to protect the functionality. Also added an example for anyone willing to use it.
This is fine for now :+1:
Thanks a lot. I am sorry I could not get a good working test for the combination network+anonymous auth via dbus config. Some colleagues of mine figured it out on an embedded device but it didn't work for me on any x86 machine.
Implementation for D-Bus communication via TCP/IP. Previously there was also AUTH ANONYMOUS added to the authentifications but this is now already implemented - so no need to change anything there.