use of io.vertx.junit5.Timeout in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationFailsForDisabledGateway.
/**
* Verifies that the registry fails a disabled gateway's request to assert a device's registration status with a 403
* error code.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForDisabledGateway(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String gatewayId = getHelper().getRandomDeviceId(tenantId);
final Device gateway = new Device();
gateway.setEnabled(false);
final Device device = new Device();
device.setVia(Collections.singletonList(gatewayId));
getHelper().registry.registerDevice(tenantId, gatewayId, gateway).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(r -> getClient().assertRegistration(tenantId, deviceId, gatewayId, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
assertErrorCode(t, HttpURLConnection.HTTP_FORBIDDEN);
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationSucceedsForDeviceViaGateway.
/**
* Verifies that the registry succeeds a request to assert the registration status of a device that connects via an
* authorized gateway.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationSucceedsForDeviceViaGateway(final VertxTestContext ctx) {
final String gatewayId = getHelper().getRandomDeviceId(tenantId);
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final List<String> via = List.of(gatewayId, "another-gateway");
final Device device = new Device();
device.setVia(via);
getHelper().registry.registerDevice(tenantId, gatewayId).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(ok -> getClient().assertRegistration(tenantId, deviceId, gatewayId, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(resp -> {
ctx.verify(() -> {
assertThat(resp.getDeviceId()).isEqualTo(deviceId);
assertThat(resp.getAuthorizedGateways()).containsExactlyElementsIn(via);
});
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class TelemetryMqttQoS1IT method testUploadMessagesWithNoConsumerSendsErrors.
/**
* Verifies that sending a number of telemetry messages to Hono's MQTT adapter while there is no consumer causes
* corresponding error messages to be published to the client if it is subscribed on the error topic.
*
* @param ctx The test context.
* @throws InterruptedException if the test fails.
*/
@Test
@AssumeMessagingSystem(type = MessagingType.amqp)
public void testUploadMessagesWithNoConsumerSendsErrors(final VertxTestContext ctx) throws InterruptedException {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final Tenant tenant = new Tenant();
final VertxTestContext setup = new VertxTestContext();
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, password).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
ctx.failNow(setup.causeOfFailure());
return;
}
// timeout value should be higher than the "hono.messaging.flowLatency" MQTT adapter configuration value
// so that no timeout doesn't while the MQTT adapter waits for credit after having created the first downstream
// sender link
final long publishCompletionTimeout = 1500;
doTestUploadMessages(ctx, tenantId, connectToAdapter(IntegrationTestSupport.getUsername(deviceId, tenantId), password), (payload) -> send(tenantId, deviceId, payload, true, null, publishCompletionTimeout).map(String::valueOf), // no consumer created here (future succeeded with null value)
(messageHandler) -> Future.succeededFuture(), (msg) -> {
final JsonObject payload = new JsonObject(msg.payload());
final String correlationId = payload.getString(MessageHelper.SYS_PROPERTY_CORRELATION_ID);
ctx.verify(() -> {
assertThat(payload.getInteger("code")).isEqualTo(HttpURLConnection.HTTP_UNAVAILABLE);
// error message should be the localized NoConsumerException message
assertThat(payload.getString("message")).isEqualTo(ServiceInvocationException.getLocalizedMessage(NoConsumerException.CLIENT_FACING_MESSAGE_KEY));
// validate topic segments; example: error//myDeviceId/telemetry/4/503
final String[] topicSegments = msg.topicName().split("/");
assertThat(topicSegments.length).isEqualTo(6);
assertThat(topicSegments[0]).isEqualTo("e");
assertThat(topicSegments[1]).isEqualTo(tenantId);
// device
assertThat(topicSegments[2]).isEmpty();
assertThat(topicSegments[3]).isEqualTo(TelemetryConstants.TELEMETRY_ENDPOINT_SHORT);
assertThat(topicSegments[4]).isEqualTo(correlationId);
assertThat(topicSegments[5]).isEqualTo(Integer.toString(HttpURLConnection.HTTP_UNAVAILABLE));
});
return Future.succeededFuture(correlationId);
}, String.format("e/%s//#", tenantId));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsJmsIT method testRequestFailsForMissingSubject.
/**
* Verifies that the service responds with a 400 status to a request that
* has no subject.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testRequestFailsForMissingSubject(final VertxTestContext ctx) {
final JsonObject searchCriteria = CredentialsConstants.getSearchCriteria(CredentialsConstants.SECRETS_TYPE_PRESHARED_KEY, "device");
getJmsBasedClient().sendRequest(tenantId, null, null, searchCriteria.toBuffer()).onComplete(ctx.failing(t -> {
assertErrorCode(t, HttpURLConnection.HTTP_BAD_REQUEST);
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsWithGatewayAutoProvisioning.
/**
* Verifies when no credentials are found, the properties related to auto-provisioning of gateways are enabled
* in the corresponding tenant's CA entry and the client context contains a serialized X.509 certificate then
* a gateway is auto-provisioned. (i.e A gateway is registered and it's corresponding credentials are stored).
* <p>
* It also verifies that an auto-provisioning event is successfully sent and the device registration
* is updated accordingly.
*
* @param ctx The vert.x test context.
* @throws CertificateException if the self signed certificate cannot be created.
* @throws FileNotFoundException if the self signed certificate cannot be read.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsWithGatewayAutoProvisioning(final VertxTestContext ctx) throws CertificateException, FileNotFoundException {
// GIVEN a tenant's trusted CA entry with auto-provisioning and auto-provision as gateway enabled
// while device has not been registered and no credentials are stored yet
final X509Certificate cert = createCertificate();
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true).setAutoProvisioningAsGatewayEnabled(true);
testAutoProvisioningSucceeds(ctx, tenant, cert, true, null);
}
Aggregations