use of io.vertx.mqtt.MqttConnectionException in project hono by eclipse.
the class MqttConnectionIT method testConnectFailsForWrongCredentials.
/**
* Verifies that the adapter rejects connection attempts from devices
* using wrong credentials.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForWrongCredentials(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, tenantId), "wrong password")).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 testConnectX509FailsForUnknownSubjectDN.
/**
* Verifies that the adapter rejects connection attempts from devices using a client certificate with an unknown
* subject DN.
*
* @param ctx The test context
*/
@Test
public void testConnectX509FailsForUnknownSubjectDN(final VertxTestContext ctx) {
// GIVEN a registered device
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
return helper.registry.addTenant(tenantId, tenant);
}).compose(ok -> helper.registry.registerDevice(tenantId, deviceId)).compose(ok -> {
final String authId = new X500Principal("CN=4711").getName(X500Principal.RFC2253);
final var credential = X509CertificateCredential.fromSubjectDn(authId, List.of(new X509CertificateSecret()));
return helper.registry.addCredentials(tenantId, deviceId, Collections.singleton(credential));
}).compose(ok -> connectToAdapter(deviceCert)).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();
}));
}
Aggregations