use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class MqttConnectionIT method testConnectFailsForNonExistingTenant.
/**
* Verifies that the adapter rejects connection attempts from devices
* using credentials that contain a non-existing tenant.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForNonExistingTenant(final VertxTestContext ctx) {
// GIVEN a registered device
final Tenant tenant = new Tenant();
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, password).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername(deviceId, "nonExistingTenant"), "secret")).onComplete(ctx.failing(t -> {
// THEN the connection is refused
ctx.verify(() -> {
assertThat(t).isInstanceOf(MqttConnectionException.class);
assertThat(((MqttConnectionException) t).code()).isEqualTo(MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class MqttConnectionIT method testConnectFailsForDisabledAdapter.
/**
* Verifies that the adapter rejects connection attempts from devices belonging to a tenant for which the MQTT
* adapter has been disabled.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForDisabledAdapter(final VertxTestContext ctx) {
final Tenant tenant = new Tenant();
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT).setEnabled(false));
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, password).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername(deviceId, tenantId), password)).onComplete(ctx.failing(t -> {
// THEN the connection is refused with a NOT_AUTHORIZED code
ctx.verify(() -> {
assertThat(t).isInstanceOf(MqttConnectionException.class);
assertThat(((MqttConnectionException) t).code()).isEqualTo(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class MqttConnectionIT method testConnectSucceedsForRegisteredDevice.
/**
* Verifies that the adapter opens a connection to registered devices with credentials.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param ctx The test context
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@ValueSource(strings = { IntegrationTestSupport.TLS_VERSION_1_2, IntegrationTestSupport.TLS_VERSION_1_3 })
public void testConnectSucceedsForRegisteredDevice(final String tlsVersion, final VertxTestContext ctx) {
final Tenant tenant = new Tenant();
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, password).compose(ok -> connectToAdapter(tlsVersion, IntegrationTestSupport.getUsername(deviceId, tenantId), password)).onComplete(ctx.succeeding(conAckMsg -> {
ctx.verify(() -> assertThat(conAckMsg.code()).isEqualTo(MqttConnectReturnCode.CONNECTION_ACCEPTED));
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithMultipleFiltersSucceeds.
/**
* Verifies that a request to search tenants with multiple filters succeeds and matching tenants are found.
*
* @param ctx The vert.x test context.
*/
@Test
default void testSearchTenantsWithMultipleFiltersSucceeds(final VertxTestContext ctx) {
final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
final int pageSize = 10;
final int pageOffset = 0;
final Filter filter1 = new Filter("/enabled", true);
final Filter filter2 = new Filter("/adapters/0/type", "MQTT");
final Filter filter3 = new Filter("/ext/group", "A");
createTenants(Map.of(tenantId1, new Tenant().setEnabled(true).setExtensions(Map.of("group", "A")), tenantId2, new Tenant().setEnabled(true).addAdapterConfig(new Adapter("MQTT")).setExtensions(Map.of("group", "A")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter1, filter2, filter3), List.of(), NoopSpan.INSTANCE)).onComplete(ctx.succeeding(s -> {
ctx.verify(() -> {
assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
final SearchResult<TenantWithId> searchResult = s.getPayload();
assertThat(searchResult.getTotal()).isEqualTo(1);
assertThat(searchResult.getResult()).hasSize(1);
assertThat(searchResult.getResult().get(0).getId()).isEqualTo(tenantId2);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class AmqpConnectionIT method testConnectFailsForDisabledAdapter.
/**
* Verifies that the adapter rejects connection attempts from devices belonging
* to a tenant for which the AMQP adapter has been disabled.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForDisabledAdapter(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final String password = "secret";
// GIVEN a tenant for which the AMQP adapter is disabled
final Tenant tenant = new Tenant();
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(true));
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_AMQP).setEnabled(false));
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, password).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername(deviceId, tenantId), password)).onComplete(ctx.failing(t -> {
// THEN the connection is refused
ctx.verify(() -> assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_FORBIDDEN));
ctx.completeNow();
}));
}
Aggregations