use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testUploadTelemetryMessageFailsForUnknownDevice.
/**
* Verifies that the adapter does not forward a message published by a device
* if the device's registration status cannot be asserted.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUploadTelemetryMessageFailsForUnknownDevice(final TestContext ctx) {
// GIVEN an adapter
final MqttServer server = getMqttServer(false);
final AbstractVertxBasedMqttProtocolAdapter<ProtocolAdapterProperties> adapter = getAdapter(server);
givenATelemetrySenderForOutcome(Future.succeededFuture(mock(ProtonDelivery.class)));
// WHEN an unknown device publishes a telemetry message
when(regClient.assertRegistration(eq("unknown"), any())).thenReturn(Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_NOT_FOUND)));
final MessageSender sender = mock(MessageSender.class);
when(messagingClient.getOrCreateTelemetrySender(anyString())).thenReturn(Future.succeededFuture(sender));
adapter.uploadTelemetryMessage(new MqttContext(mock(MqttPublishMessage.class), mock(MqttEndpoint.class)), "my-tenant", "unknown", Buffer.buffer("test")).setHandler(ctx.asyncAssertFailure(t -> {
// THEN the message has not been sent downstream
verify(sender, never()).send(any(Message.class));
// because the device's registration status could not be asserted
ctx.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ((ClientErrorException) t).getErrorCode());
}));
}
use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testUnauthenticatedMqttAdapterCreatesMessageHandlersForAllDevices.
/**
* Verifies that the adapter registers message handlers on client connections
* when device authentication is disabled.
*/
@SuppressWarnings("unchecked")
@Test
public void testUnauthenticatedMqttAdapterCreatesMessageHandlersForAllDevices() {
// GIVEN an adapter that does not require devices to authenticate
config.setAuthenticationRequired(false);
final MqttServer server = getMqttServer(false);
final AbstractVertxBasedMqttProtocolAdapter<ProtocolAdapterProperties> adapter = getAdapter(server);
forceClientMocksToConnected();
// WHEN a device connects that does not provide any credentials
final MqttEndpoint endpoint = mock(MqttEndpoint.class);
adapter.handleEndpointConnection(endpoint);
// THEN the connection is established and handlers are registered
verify(credentialsAuthProvider, never()).authenticate(any(DeviceCredentials.class), any(Handler.class));
verify(endpoint).publishHandler(any(Handler.class));
verify(endpoint).closeHandler(any(Handler.class));
verify(endpoint).accept(false);
}
Aggregations