use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpUploadTestBase method testUploadMessagesUsingSaslExternal.
/**
* Verifies that a number of messages uploaded to the AMQP adapter using client certificate
* based authentication can be successfully consumed via the AMQP Messaging Network.
*
* @param senderQos The delivery semantics used by the device for uploading messages.
* @throws InterruptedException if test execution is interrupted.
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("senderQoSTypes")
public void testUploadMessagesUsingSaslExternal(final ProtonQoS senderQos) throws InterruptedException {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
final VertxTestContext setup = new VertxTestContext();
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
prepareTenantConfig(tenant);
return helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, cert);
}).compose(ok -> connectToAdapter(deviceCert)).compose(con -> createProducer(null, senderQos)).onComplete(setup.succeeding(s -> {
setup.verify(() -> {
final UnsignedLong maxMessageSize = s.getRemoteMaxMessageSize();
assertWithMessage("max-message-size included in adapter's attach frame").that(maxMessageSize).isNotNull();
assertWithMessage("max-message-size").that(maxMessageSize.longValue()).isGreaterThan(0);
});
sender = s;
setup.completeNow();
}));
assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
assertWithMessage("adapter connection failure occurred").that(setup.failed()).isFalse();
testUploadMessages(tenantId, senderQos);
}
use of org.eclipse.hono.service.management.tenant.Tenant 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);
});
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class DeviceRegistryHttpClient method addDeviceForTenant.
/**
* Creates a tenant and adds a device to it with a given password.
* <p>
* The password will be added as a hashed password using the device identifier as the authentication identifier.
*
* @param tenantId The ID of the tenant to create.
* @param tenant The tenant payload as specified by the Tenant management API.
* @param deviceId The identifier of the device to add.
* @param device The data to register for the device.
* @param password The password to use for the device's credentials.
* @return A future indicating the outcome of the operation.
* @throws NullPointerException if tenant is {@code null}.
*/
public Future<HttpResponse<Buffer>> addDeviceForTenant(final String tenantId, final Tenant tenant, final String deviceId, final Device device, final String password) {
Objects.requireNonNull(tenant);
final PasswordCredential secret = IntegrationTestSupport.createPasswordCredential(deviceId, password);
return addTenant(tenantId, tenant).compose(ok -> registerDevice(tenantId, deviceId, device)).compose(ok -> addCredentials(tenantId, deviceId, Collections.singleton(secret)));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class DeviceRegistryHttpClient method addPskDeviceForTenant.
/**
* Creates a tenant and adds a device to it with a given Pre-Shared Key.
* <p>
* The device will be registered with a set of <em>psk</em> credentials using the device identifier as the
* authentication identifier and PSK identity.
*
* @param tenantId The identifier of the tenant to add the secret to.
* @param tenant The tenant payload as specified by the Tenant management API.
* @param deviceId The identifier of the device to add to the tenant.
* @param deviceData Additional data to register for the device.
* @param key The shared key.
* @return A future indicating the outcome of the operation.
* @throws NullPointerException if any of the parameters are are {@code null}.
*/
public Future<HttpResponse<Buffer>> addPskDeviceForTenant(final String tenantId, final Tenant tenant, final String deviceId, final Device deviceData, final String key) {
Objects.requireNonNull(tenant);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(deviceData);
Objects.requireNonNull(key);
final PskCredential credential = IntegrationTestSupport.createPskCredentials(deviceId, key);
return addTenant(tenantId, tenant).compose(ok -> registerDevice(tenantId, deviceId, deviceData)).compose(ok -> addCredentials(tenantId, deviceId, Collections.singleton(credential)));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MongoDbBasedRegistrationServiceTest method testCreateDeviceFailsIfGlobalDeviceLimitHasBeenReached.
/**
* Verifies that a request to create more devices than the globally configured limit fails with a 403.
*
* @param ctx The vert.x test context.
*/
@Test
public void testCreateDeviceFailsIfGlobalDeviceLimitHasBeenReached(final VertxTestContext ctx) {
config.setMaxDevicesPerTenant(1);
getDeviceManagementService().createDevice(TENANT, Optional.empty(), new Device(), NoopSpan.INSTANCE).onFailure(ctx::failNow).compose(ok -> getDeviceManagementService().createDevice(TENANT, Optional.empty(), new Device(), NoopSpan.INSTANCE)).onComplete(ctx.failing(t -> {
ctx.verify(() -> Assertions.assertServiceInvocationException(t, HttpURLConnection.HTTP_FORBIDDEN));
ctx.completeNow();
}));
}
Aggregations