use of io.vertx.mqtt.MqttConnectionException 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 io.vertx.mqtt.MqttConnectionException in project hono by eclipse.
the class MqttConnectionIT method testConnectFailsForDisabledCredentials.
/**
* Verifies that the adapter rejects connection attempts from devices for which credentials exist but are disabled.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForDisabledCredentials(final VertxTestContext ctx) {
helper.registry.addTenant(tenantId).compose(ok -> {
return helper.registry.registerDevice(tenantId, deviceId);
}).compose(ok -> {
final PasswordCredential secret = IntegrationTestSupport.createPasswordCredential(deviceId, password);
secret.setEnabled(false);
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_BAD_USER_NAME_OR_PASSWORD);
});
ctx.completeNow();
}));
}
use of io.vertx.mqtt.MqttConnectionException 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 io.vertx.mqtt.MqttConnectionException 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 io.vertx.mqtt.MqttConnectionException in project hono by eclipse.
the class MqttConnectionIT method testConnectFailsForDisabledTenant.
/**
* Verifies that the adapter rejects connection attempts from devices that belong to a disabled tenant.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForDisabledTenant(final VertxTestContext ctx) {
// Given a disabled tenant for which the MQTT adapter is enabled
final Tenant tenant = new Tenant();
tenant.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();
}));
}
Aggregations