use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpConnectionIT method testDeviceConnectionIsClosedOnDeviceOrTenantDisabledOrDeleted.
private void testDeviceConnectionIsClosedOnDeviceOrTenantDisabledOrDeleted(final VertxTestContext ctx, final String tenantId, final String deviceId, final Supplier<Future<?>> deviceRegistryChangeOperation) {
final String password = "secret";
final Promise<Void> disconnectedPromise = Promise.promise();
// GIVEN a connected device
helper.registry.addDeviceForTenant(tenantId, new Tenant(), deviceId, password).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername(deviceId, tenantId), password)).compose(con -> {
con.disconnectHandler(ignore -> disconnectedPromise.complete());
con.closeHandler(remoteClose -> {
con.close();
con.disconnect();
});
// WHEN corresponding device/tenant is removed/disabled
return deviceRegistryChangeOperation.get();
}).compose(ok -> disconnectedPromise.future()).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpConnectionIT method testConnectFailsForNonExistingDevice.
/**
* Verifies that the adapter rejects connection attempts from unknown devices
* for which neither registration information nor credentials are on record.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForNonExistingDevice(final VertxTestContext ctx) {
// GIVEN an existing tenant
final String tenantId = helper.getRandomTenantId();
final Tenant tenant = new Tenant();
tenant.setEnabled(true);
helper.registry.addTenant(tenantId, tenant).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername("non-existing", tenantId), "secret")).onComplete(ctx.failing(t -> {
// THEN the connection is refused
ctx.verify(() -> assertThat(t).isInstanceOf(SaslException.class));
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpConnectionIT method testConnectX509SucceedsUsingSniWithTenantAlias.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate succeeds
* for a device belonging to a tenant with a tenant alias.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param ctx The test context
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@ValueSource(strings = { IntegrationTestSupport.TLS_VERSION_1_2, IntegrationTestSupport.TLS_VERSION_1_3 })
public void testConnectX509SucceedsUsingSniWithTenantAlias(final String tlsVersion, final VertxTestContext ctx) {
assumeTrue(IntegrationTestSupport.isTrustAnchorGroupsSupported(), "device registry does not support trust anchor groups");
assumeTrue(IntegrationTestSupport.isTenantAliasSupported(), "device registry does not support tenant aliases");
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addTenant(helper.getRandomTenantId(), Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group")).map(cert)).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group").setAlias("test-alias"), deviceId, cert)).compose(ok -> connectToAdapter("test-alias." + IntegrationTestSupport.AMQP_HOST, deviceCert, tlsVersion)).onComplete(ctx.succeeding(con -> {
ctx.verify(() -> assertThat(con.isDisconnected()).isFalse());
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpConnectionIT method testConnectSucceedsWithAutoProvisioning.
/**
* Verifies that the adapter opens a connection if auto-provisioning is enabled for the device certificate.
*
* @param ctx The test context.
*/
@Test
public void testConnectSucceedsWithAutoProvisioning(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
final Promise<String> autoProvisionedDeviceId = Promise.promise();
helper.createAutoProvisioningNotificationConsumer(ctx, autoProvisionedDeviceId, tenantId).compose(ok -> helper.getCertificate(deviceCert.certificatePath())).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true);
return helper.registry.addTenant(tenantId, tenant);
}).compose(ok -> connectToAdapter(deviceCert)).compose(ok -> autoProvisionedDeviceId.future()).compose(deviceId -> helper.registry.getRegistrationInfo(tenantId, deviceId)).onComplete(ctx.succeeding(registrationResult -> {
ctx.verify(() -> {
final var info = registrationResult.bodyAsJsonObject();
IntegrationTestSupport.assertDeviceStatusProperties(info.getJsonObject(RegistryManagementConstants.FIELD_STATUS), true);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant 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();
}));
}
Aggregations