use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class CoapTestBase method testUploadMessageFailsForDisabledGateway.
/**
* Verifies that the CoAP adapter rejects messages from a disabled gateway
* for an enabled device with a 403.
*
* @param ctx The test context
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadMessageFailsForDisabledGateway(final VertxTestContext ctx) {
// GIVEN a device that is connected via a disabled gateway
final Tenant tenant = new Tenant();
final String gatewayId = helper.getRandomDeviceId(tenantId);
final Device gatewayData = new Device();
gatewayData.setEnabled(false);
final Device deviceData = new Device();
deviceData.setVia(Collections.singletonList(gatewayId));
helper.registry.addPskDeviceForTenant(tenantId, tenant, gatewayId, gatewayData, SECRET).compose(ok -> helper.registry.registerDevice(tenantId, deviceId, deviceData)).compose(ok -> {
// WHEN the gateway tries to upload a message for the device
final Promise<OptionSet> result = Promise.promise();
final CoapClient client = getCoapsClient(gatewayId, tenantId, SECRET);
// THEN a FORBIDDEN response code is returned
client.advanced(getHandler(result, ResponseCode.FORBIDDEN), createCoapsRequest(Code.PUT, getPutResource(tenantId, deviceId), 0));
return result.future();
}).onComplete(ctx.succeedingThenComplete());
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class CoapTestBase method testUploadMessageFailsForDisabledTenant.
/**
* Verifies that the CoAP adapter rejects messages from a device that belongs to a tenant for which the CoAP adapter
* has been disabled.
*
* @param ctx The test context
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadMessageFailsForDisabledTenant(final VertxTestContext ctx) {
// GIVEN a tenant for which the CoAP adapter is disabled
final Tenant tenant = new Tenant();
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_COAP).setEnabled(false));
helper.registry.addPskDeviceForTenant(tenantId, tenant, deviceId, SECRET).compose(ok -> {
// WHEN a device that belongs to the tenant uploads a message
final CoapClient client = getCoapsClient(deviceId, tenantId, SECRET);
final Promise<OptionSet> result = Promise.promise();
// THEN a FORBIDDEN response code is returned
client.advanced(getHandler(result, ResponseCode.FORBIDDEN), createCoapsRequest(Code.POST, getPostResource(), 0));
return result.future();
}).onComplete(ctx.succeedingThenComplete());
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class CoapTestBase method testUploadFailsForNonMatchingSharedKey.
/**
* Verifies that the adapter fails to authenticate a device if the shared key registered
* for the device does not match the key used by the device in the DTLS handshake.
*
* @param ctx The vert.x test context.
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadFailsForNonMatchingSharedKey(final VertxTestContext ctx) {
final Tenant tenant = new Tenant();
// GIVEN a device for which PSK credentials have been registered
helper.registry.addPskDeviceForTenant(tenantId, tenant, deviceId, "NOT" + SECRET).compose(ok -> {
// WHEN a device tries to upload data and authenticate using the PSK
// identity for which the server has a different shared secret on record
final CoapClient client = getCoapsClient(deviceId, tenantId, SECRET);
final Promise<OptionSet> result = Promise.promise();
client.advanced(getHandler(result), createCoapsRequest(Code.POST, getPostResource(), 0));
return result.future();
}).onComplete(ctx.failing(t -> {
// THEN the request fails because the DTLS handshake cannot be completed
assertStatus(ctx, HttpURLConnection.HTTP_UNAVAILABLE, t);
ctx.completeNow();
}));
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class AmqpUploadTestBase method testAnonymousRelayRequired.
/**
* Verifies that the AMQP Adapter rejects (closes) AMQP links that contain a target address.
*
* @param context The Vert.x test context.
*/
@Test
@Timeout(timeUnit = TimeUnit.SECONDS, value = 10)
public void testAnonymousRelayRequired(final VertxTestContext context) {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final String username = IntegrationTestSupport.getUsername(deviceId, tenantId);
final String targetAddress = String.format("%s/%s/%s", getEndpointName(), tenantId, deviceId);
final Tenant tenant = new Tenant();
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, DEVICE_PASSWORD).compose(ok -> connectToAdapter(username, DEVICE_PASSWORD)).compose(con -> {
this.connection = con;
return createProducer(targetAddress, ProtonQoS.AT_LEAST_ONCE);
}).onComplete(context.failing(t -> {
log.info("failed to open sender", t);
context.completeNow();
}));
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class AmqpUploadTestBase method testAdapterClosesLinkOnMessageExceedingMaxPayloadSize.
/**
* Verifies that the adapter closes the link when a device sends a message containing a payload which
* exceeds the configured max payload size.
*
* @param ctx The Vert.x test context.
*/
@Test
@Timeout(timeUnit = TimeUnit.SECONDS, value = 10)
public void testAdapterClosesLinkOnMessageExceedingMaxPayloadSize(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
createConsumer(tenantId, msg -> ctx.failNow(new AssertionError("should not have received message"))).compose(consumer -> setupProtocolAdapter(tenantId, new Tenant(), deviceId, ProtonQoS.AT_LEAST_ONCE)).onComplete(ctx.succeeding(s -> {
s.detachHandler(remoteDetach -> {
ctx.verify(() -> {
final ErrorCondition errorCondition = s.getRemoteCondition();
assertThat(remoteDetach.succeeded()).isFalse();
assertThat(errorCondition).isNotNull();
assertThat((Comparable<Symbol>) errorCondition.getCondition()).isEqualTo(LinkError.MESSAGE_SIZE_EXCEEDED);
});
log.info("AMQP adapter detached link as expected");
s.close();
ctx.completeNow();
});
final UnsignedLong maxMessageSize = s.getRemoteMaxMessageSize();
log.info("AMQP adapter uses max-message-size {}", maxMessageSize);
ctx.verify(() -> {
assertWithMessage("max-message-size included in adapter's attach frame").that(maxMessageSize).isNotNull();
assertWithMessage("max-message-size").that(maxMessageSize.longValue()).isGreaterThan(0);
});
final Message msg = ProtonHelper.message();
msg.setContentType("opaque/binary");
msg.setAddress(getEndpointName());
msg.setBody(new Data(new Binary(IntegrationTestSupport.getPayload(maxMessageSize.intValue()))));
context.runOnContext(go -> {
log.debug("sending message");
s.send(msg);
});
}));
}
Aggregations