Skip to content

Commit

Permalink
Moved unit test; Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hypfvieh committed Jul 4, 2023
1 parent f28ac7e commit f30b9f5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ protected ObjectTree getObjectTree() {
*
* @return transport config
*/
public TransportConfig getTransportConfig() {
protected TransportConfig getTransportConfig() {
return transport.getTransportConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit f30b9f5

Please sign in to comment.