From f30b9f55504bd854f2b5732d87b6ee23ad2e5c17 Mon Sep 17 00:00:00 2001 From: David M Date: Tue, 4 Jul 2023 10:04:21 +0200 Subject: [PATCH] Moved unit test; Updated readme --- README.md | 1 + .../dbus/connections/AbstractConnection.java | 2 +- .../dbus/bin/EmbeddedDBusDaemonTest.java | 34 --------------- .../dbus/connections/SASLTest.java | 41 +++++++++++++++++++ 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index bc413733..7f091898 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ The library will remain open source and MIT licensed and can still be used, fork - Fixed possible issue with used serial numbers in messages because signals may manually incremented the serial without updating global serial ([#220](https://github.com/hypfvieh/dbus-java/issues/220)) - Updated module-info exports, thanks to [brett-smith](https://github.com/brett-smith) ([#221](https://github.com/hypfvieh/dbus-java/issues/221)) - Ensure that DBusDaemonThread is terminated when close() is called, thanks to [brett-smith](https://github.com/brett-smith) ([#222](https://github.com/hypfvieh/dbus-java/issues/222)) + - Fixed configured authentication mechanism was always ignored when connecting, thanks to [brett-smith](https://github.com/brett-smith) ([#223](https://github.com/hypfvieh/dbus-java/issues/223)) ##### Changes in 4.3.0 (2023-03-10): diff --git a/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/AbstractConnection.java b/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/AbstractConnection.java index 64c6f189..81148050 100644 --- a/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/AbstractConnection.java +++ b/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/AbstractConnection.java @@ -1243,7 +1243,7 @@ protected ObjectTree getObjectTree() { * * @return transport config */ - public TransportConfig getTransportConfig() { + protected TransportConfig getTransportConfig() { return transport.getTransportConfig(); } diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/bin/EmbeddedDBusDaemonTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/bin/EmbeddedDBusDaemonTest.java index 74b20027..1ec8d1d3 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/bin/EmbeddedDBusDaemonTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/bin/EmbeddedDBusDaemonTest.java @@ -5,7 +5,6 @@ import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; import org.freedesktop.dbus.connections.transports.TransportBuilder; -import org.freedesktop.dbus.connections.transports.TransportBuilder.SaslAuthMode; import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.test.AbstractBaseTest; import org.junit.jupiter.api.Test; @@ -18,39 +17,6 @@ */ public class EmbeddedDBusDaemonTest extends AbstractBaseTest { - @Test - public void testAnonymousAuthentication() throws DBusException { - String protocolType = TransportBuilder.getRegisteredBusTypes().get(0); - String newAddress = TransportBuilder.createDynamicSession(protocolType, false); - - BusAddress busAddress = BusAddress.of(newAddress); - BusAddress listenBusAddress = BusAddress.of(newAddress + ",listen=true"); - - logger.debug("Starting embedded bus on address {})", listenBusAddress); - try (EmbeddedDBusDaemon daemon = new EmbeddedDBusDaemon(listenBusAddress)) { - daemon.setSaslAuthMode(SaslAuthMode.AUTH_ANONYMOUS); - daemon.startInBackground(); - logger.debug("Started embedded bus on address {}", listenBusAddress); - - waitForDaemon(daemon); - - // connect to started daemon process - logger.info("Connecting to embedded DBus {}", busAddress); - - try (DBusConnection conn = DBusConnectionBuilder.forAddress(busAddress) - .transportConfig().configureSasl().withAuthMode(SaslAuthMode.AUTH_EXTERNAL).back().back() - .build()) { - logger.debug("Connected to embedded DBus {}", busAddress); - } catch (Exception _ex) { - fail("Connection to EmbeddedDbusDaemon failed", _ex); - logger.error("Error connecting to EmbeddedDbusDaemon", _ex); - } - } catch (IOException _ex1) { - fail("Failed to start EmbeddedDbusDaemon", _ex1); - logger.error("Error starting EmbeddedDbusDaemon", _ex1); - } - } - @Test public void testStartAndConnectEmbeddedDBusDaemon() throws DBusException { String protocolType = TransportBuilder.getRegisteredBusTypes().get(0); diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/SASLTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/SASLTest.java index 52181267..cec261b7 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/SASLTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/SASLTest.java @@ -1,7 +1,13 @@ package org.freedesktop.dbus.connections; +import org.freedesktop.dbus.bin.EmbeddedDBusDaemon; import org.freedesktop.dbus.connections.SASL.Command; import org.freedesktop.dbus.connections.SASL.SaslCommand; +import org.freedesktop.dbus.connections.impl.DBusConnection; +import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; +import org.freedesktop.dbus.connections.transports.TransportBuilder; +import org.freedesktop.dbus.connections.transports.TransportBuilder.SaslAuthMode; +import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.test.AbstractBaseTest; import org.junit.jupiter.api.Test; @@ -30,4 +36,39 @@ public void testCommandAuth() throws IOException { assertNull(cmdData.getData()); } + @Test + public void testAnonymousAuthentication() throws DBusException { + String protocolType = TransportBuilder.getRegisteredBusTypes().get(0); + String newAddress = TransportBuilder.createDynamicSession(protocolType, false); + + BusAddress busAddress = BusAddress.of(newAddress); + BusAddress listenBusAddress = BusAddress.of(newAddress + ",listen=true"); + + logger.debug("Starting embedded bus on address {})", listenBusAddress); + try (EmbeddedDBusDaemon daemon = new EmbeddedDBusDaemon(listenBusAddress)) { + daemon.setSaslAuthMode(SaslAuthMode.AUTH_ANONYMOUS); + daemon.startInBackground(); + logger.debug("Started embedded bus on address {}", listenBusAddress); + + waitForDaemon(daemon); + + // connect to started daemon process + logger.info("Connecting to embedded DBus {}", busAddress); + + try (DBusConnection conn = DBusConnectionBuilder.forAddress(busAddress) + .transportConfig().configureSasl().withAuthMode(SaslAuthMode.AUTH_ANONYMOUS).back().back() + .build()) { + + logger.debug("Connected to embedded DBus {}", busAddress); + + assertEquals(SaslAuthMode.AUTH_ANONYMOUS.getAuthMode(), conn.getTransportConfig().getSaslConfig().getAuthMode()); + } catch (Exception _ex) { + fail("Connection to EmbeddedDbusDaemon failed", _ex); + logger.error("Error connecting to EmbeddedDbusDaemon", _ex); + } + } catch (IOException _ex1) { + fail("Failed to start EmbeddedDbusDaemon", _ex1); + logger.error("Error starting EmbeddedDbusDaemon", _ex1); + } + } }