use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TenantManagementIT method testAddTenantFailsForConfigurationWithDuplicateTrustAnchor.
/**
* Verifies that the service returns a 409 status code for an add tenant request containing a
* CA that is already in use by another tenant that does not belong to the same trust anchor group.
*
* @param context The Vert.x test context.
*/
@Test
public void testAddTenantFailsForConfigurationWithDuplicateTrustAnchor(final VertxTestContext context) {
final PublicKey publicKey = TenantApiTests.getRandomPublicKey();
final TrustedCertificateAuthority trustAnchor = Tenants.createTrustAnchor("test-ca", "CN=test-dn", publicKey.getEncoded(), publicKey.getAlgorithm(), Instant.now(), Instant.now().plus(365, ChronoUnit.DAYS));
final Tenant tenant = new Tenant().setTrustedCertificateAuthorities(List.of(trustAnchor));
final String tenantId = getHelper().getRandomTenantId();
getHelper().registry.addTenant(tenantId, tenant).onFailure(context::failNow).compose(ok -> getHelper().registry.addTenant(getHelper().getRandomTenantId(), tenant, HttpURLConnection.HTTP_CONFLICT)).onComplete(context.succeeding(response -> {
context.verify(() -> IntegrationTestSupport.assertErrorPayload(response));
context.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TenantManagementIT method testUpdateTenantFailsForDuplicateTenantAlias.
/**
* Verifies that the registry rejects an attempt to update a tenant with an alias that is already used
* by another tenant.
*
* @param context The vert.x test context.
*/
@Test
public void testUpdateTenantFailsForDuplicateTenantAlias(final VertxTestContext context) {
assumeTrue(IntegrationTestSupport.isTenantAliasSupported(), "device registry does not support tenant aliases");
final Tenant payload = new Tenant().setAlias("the-alias");
final String tenantId = getHelper().getRandomTenantId();
getHelper().registry.addTenant(getHelper().getRandomTenantId(), payload).onFailure(context::failNow).compose(ok -> getHelper().registry.addTenant(tenantId, new Tenant())).onFailure(context::failNow).compose(ar -> getHelper().registry.updateTenant(tenantId, payload, HttpURLConnection.HTTP_CONFLICT)).onComplete(context.succeeding(response -> {
context.verify(() -> IntegrationTestSupport.assertErrorPayload(response));
context.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MqttPublishTestBase method testAutoProvisioningViaGateway.
/**
* Verifies that an edge device is auto-provisioned if it connects via a gateway equipped with the corresponding
* authority.
*
* @param ctx The test context.
* @throws InterruptedException if the test fails.
*/
@Test
public void testAutoProvisioningViaGateway(final VertxTestContext ctx) throws InterruptedException {
final String tenantId = helper.getRandomTenantId();
final Tenant tenant = new Tenant();
final String gatewayId = helper.getRandomDeviceId(tenantId);
final Device gateway = new Device().setAuthorities(Set.of(RegistryManagementConstants.AUTHORITY_AUTO_PROVISIONING_ENABLED));
final String edgeDeviceId = helper.getRandomDeviceId(tenantId);
final Promise<Void> provisioningNotificationReceived = Promise.promise();
helper.createAutoProvisioningMessageConsumers(ctx, provisioningNotificationReceived, tenantId, edgeDeviceId).compose(ok -> helper.registry.addDeviceForTenant(tenantId, tenant, gatewayId, gateway, password)).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername(gatewayId, tenantId), password)).compose(ok -> {
customizeConnectedClient();
return send(tenantId, edgeDeviceId, Buffer.buffer("hello".getBytes()), false, null);
}).compose(ok -> provisioningNotificationReceived.future()).compose(ok -> helper.registry.getRegistrationInfo(tenantId, edgeDeviceId)).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 MqttPublishTestBase method testUploadMessagesUsingShortTopicNames.
/**
* Verifies that a number of messages published to Hono's MQTT adapter
* using the short topic names can be successfully consumed via the AMQP Messaging Network.
*
* @param ctx The test context.
* @throws InterruptedException if the test fails.
*/
@Test
public void testUploadMessagesUsingShortTopicNames(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;
}
doTestUploadMessages(ctx, tenantId, deviceId, connectToAdapter(IntegrationTestSupport.getUsername(deviceId, tenantId), password), true);
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MqttPublishTestBase method testUploadMessagesUsingClientCertificate.
/**
* Verifies that a number of messages published by a device authenticating with a client certificate can be
* successfully consumed via the AMQP Messaging Network.
*
* @param ctx The test context.
* @throws InterruptedException if the test fails.
*/
@Test
public void testUploadMessagesUsingClientCertificate(final VertxTestContext ctx) throws InterruptedException {
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final VertxTestContext setup = new VertxTestContext();
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
return helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, cert);
}).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
ctx.failNow(setup.causeOfFailure());
return;
}
doTestUploadMessages(ctx, tenantId, deviceId, connectToAdapter(deviceCert), false);
}
Aggregations