use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractProtocolAdapterBaseTest method setup.
/**
* Sets up the fixture.
*/
@Before
public void setup() {
registrationClient = mock(RegistrationClient.class);
HonoClient honoClient = mock(HonoClient.class);
when(honoClient.getOrCreateRegistrationClient(anyString())).thenReturn(Future.succeededFuture(registrationClient));
properties = new ProtocolAdapterProperties();
adapter = newProtocolAdapter(properties);
adapter.setRegistrationServiceClient(honoClient);
}
use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testEndpointHandlerAcceptsUnauthenticatedDevices.
/**
* Verifies that an adapter that is configured to not require devices to authenticate,
* accepts connections from devices not providing any credentials.
*/
@Test
public void testEndpointHandlerAcceptsUnauthenticatedDevices() {
// 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 without providing credentials
final MqttEndpoint endpoint = mock(MqttEndpoint.class);
adapter.handleEndpointConnection(endpoint);
// THEN the connection is established
verify(endpoint).accept(false);
}
use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testEndpointHandlerRejectsDeviceOfDisabledTenant.
/**
* Verifies that an adapter rejects a connection attempt from a device that
* belongs to a tenant for which the adapter is disabled.
*/
@Test
public void testEndpointHandlerRejectsDeviceOfDisabledTenant() {
// GIVEN an adapter
final MqttServer server = getMqttServer(false);
// which is disabled for tenant "my-tenant"
final TenantObject myTenantConfig = TenantObject.from("my-tenant", true);
myTenantConfig.addAdapterConfiguration(new JsonObject().put(TenantConstants.FIELD_ADAPTERS_TYPE, ADAPTER_TYPE).put(TenantConstants.FIELD_ENABLED, false));
when(tenantClient.get("my-tenant")).thenReturn(Future.succeededFuture(myTenantConfig));
final AbstractVertxBasedMqttProtocolAdapter<ProtocolAdapterProperties> adapter = getAdapter(server);
forceClientMocksToConnected();
// WHEN a device of "my-tenant" tries to connect
final MqttAuth deviceCredentials = new MqttAuth("device@my-tenant", "irrelevant");
final MqttEndpoint endpoint = mock(MqttEndpoint.class);
when(endpoint.auth()).thenReturn(deviceCredentials);
adapter.handleEndpointConnection(endpoint);
// THEN the connection is not established
verify(endpoint).reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED);
}
use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method setup.
/**
* Creates clients for the needed micro services and sets the configuration to enable the insecure port.
*/
@Before
@SuppressWarnings("unchecked")
public void setup() {
config = new ProtocolAdapterProperties();
config.setInsecurePortEnabled(true);
regClient = mock(RegistrationClient.class);
final JsonObject result = new JsonObject().put(RegistrationConstants.FIELD_ASSERTION, "token");
when(regClient.assertRegistration(anyString(), any())).thenReturn(Future.succeededFuture(result));
tenantClient = mock(TenantClient.class);
when(tenantClient.get(anyString())).thenAnswer(invocation -> {
return Future.succeededFuture(TenantObject.from(invocation.getArgument(0), true));
});
tenantServiceClient = mock(HonoClient.class);
when(tenantServiceClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(tenantServiceClient));
when(tenantServiceClient.getOrCreateTenantClient()).thenReturn(Future.succeededFuture(tenantClient));
messagingClient = mock(HonoClient.class);
when(messagingClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(messagingClient));
deviceRegistrationServiceClient = mock(HonoClient.class);
when(deviceRegistrationServiceClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(deviceRegistrationServiceClient));
when(deviceRegistrationServiceClient.getOrCreateRegistrationClient(anyString())).thenReturn(Future.succeededFuture(regClient));
credentialsAuthProvider = mock(HonoClientBasedAuthProvider.class);
when(credentialsAuthProvider.start()).thenReturn(Future.succeededFuture());
}
use of org.eclipse.hono.config.ProtocolAdapterProperties in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testUploadQoS1MessageSendsPubAckOnSuccess.
private void testUploadQoS1MessageSendsPubAckOnSuccess(final Future<ProtonDelivery> outcome, final BiConsumer<AbstractVertxBasedMqttProtocolAdapter<?>, MqttContext> upload) {
// GIVEN an adapter with a downstream event consumer
final MqttServer server = getMqttServer(false);
final AbstractVertxBasedMqttProtocolAdapter<ProtocolAdapterProperties> adapter = getAdapter(server);
// WHEN a device publishes an event
final MqttEndpoint endpoint = mock(MqttEndpoint.class);
when(endpoint.isConnected()).thenReturn(Boolean.TRUE);
final Buffer payload = Buffer.buffer("some payload");
final MqttPublishMessage messageFromDevice = mock(MqttPublishMessage.class);
when(messageFromDevice.qosLevel()).thenReturn(MqttQoS.AT_LEAST_ONCE);
when(messageFromDevice.messageId()).thenReturn(5555555);
when(messageFromDevice.payload()).thenReturn(payload);
final MqttContext context = new MqttContext(messageFromDevice, endpoint);
upload.accept(adapter, context);
// THEN the device does not receive a PUBACK
verify(endpoint, never()).publishAcknowledge(anyInt());
// until the event has been settled and accepted
outcome.complete(mock(ProtonDelivery.class));
verify(endpoint).publishAcknowledge(5555555);
}
Aggregations