use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MqttConnectionIT method testDeviceConnectionIsClosedOnTenantDisabled.
/**
* Verifies that the adapter closes the connection to a device when the tenant of the device
* is disabled.
*
* @param ctx The vert.x test context.
*/
@Test
public void testDeviceConnectionIsClosedOnTenantDisabled(final VertxTestContext ctx) {
final Tenant updatedTenant = new Tenant().setEnabled(false);
testDeviceConnectionIsClosedOnDeviceOrTenantDisabledOrDeleted(ctx, () -> helper.registry.updateTenant(tenantId, updatedTenant, HttpURLConnection.HTTP_NO_CONTENT));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MqttConnectionIT method testConnectFailsForDisabledDevice.
/**
* Verifies that the adapter rejects connection attempts from devices for which credentials exist but the device is
* disabled.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForDisabledDevice(final VertxTestContext ctx) {
final Tenant tenant = new Tenant();
helper.registry.addTenant(tenantId, tenant).compose(ok -> {
final var device = new Device();
device.setEnabled(false);
return helper.registry.registerDevice(tenantId, deviceId, device);
}).compose(ok -> {
final PasswordCredential secret = IntegrationTestSupport.createPasswordCredential(deviceId, password);
return helper.registry.addCredentials(tenantId, deviceId, Collections.singleton(secret));
}).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.service.management.tenant.Tenant 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.service.management.tenant.Tenant 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.service.management.tenant.Tenant in project hono by eclipse.
the class MqttConnectionIT method testDeviceConnectionIsClosedOnDeviceOrTenantDisabledOrDeleted.
private void testDeviceConnectionIsClosedOnDeviceOrTenantDisabledOrDeleted(final VertxTestContext ctx, final Supplier<Future<?>> deviceRegistryChangeOperation) {
final Promise<Void> connectionClosedPromise = Promise.promise();
// GIVEN a connected device
helper.registry.addDeviceForTenant(tenantId, new Tenant(), deviceId, password).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername(deviceId, tenantId), password)).compose(conAckMsg -> {
ctx.verify(() -> assertThat(conAckMsg.code()).isEqualTo(MqttConnectReturnCode.CONNECTION_ACCEPTED));
mqttClient.closeHandler(remoteClose -> connectionClosedPromise.complete());
// WHEN corresponding device/tenant is removed/disabled
return deviceRegistryChangeOperation.get();
}).compose(ok -> connectionClosedPromise.future()).onComplete(ctx.succeedingThenComplete());
}
Aggregations