Search in sources :

Example 66 with Tenant

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) TenantConstants(org.eclipse.hono.util.TenantConstants) LoggerFactory(org.slf4j.LoggerFactory) MultiMap(io.vertx.core.MultiMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Constants(org.eclipse.hono.util.Constants) Nested(org.junit.jupiter.api.Nested) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) CompositeFuture(io.vertx.core.CompositeFuture) Matcher(java.util.regex.Matcher) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) SearchResult(org.eclipse.hono.service.management.SearchResult) TrustedCertificateAuthority(org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority) Map(java.util.Map) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) EnabledIf(org.junit.jupiter.api.condition.EnabledIf) Device(org.eclipse.hono.service.management.device.Device) RegistrationLimits(org.eclipse.hono.service.management.tenant.RegistrationLimits) ResourceLimits(org.eclipse.hono.util.ResourceLimits) Logger(org.slf4j.Logger) JacksonCodec(io.vertx.core.json.jackson.JacksonCodec) TenantWithId(org.eclipse.hono.service.management.tenant.TenantWithId) HttpHeaders(io.vertx.core.http.HttpHeaders) PublicKey(java.security.PublicKey) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) VertxExtension(io.vertx.junit5.VertxExtension) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Adapter(org.eclipse.hono.util.Adapter) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Tenant(org.eclipse.hono.service.management.tenant.Tenant) PublicKey(java.security.PublicKey) TrustedCertificateAuthority(org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority) Test(org.junit.jupiter.api.Test)

Example 67 with Tenant

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) TenantConstants(org.eclipse.hono.util.TenantConstants) LoggerFactory(org.slf4j.LoggerFactory) MultiMap(io.vertx.core.MultiMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Constants(org.eclipse.hono.util.Constants) Nested(org.junit.jupiter.api.Nested) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) CompositeFuture(io.vertx.core.CompositeFuture) Matcher(java.util.regex.Matcher) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) SearchResult(org.eclipse.hono.service.management.SearchResult) TrustedCertificateAuthority(org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority) Map(java.util.Map) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) EnabledIf(org.junit.jupiter.api.condition.EnabledIf) Device(org.eclipse.hono.service.management.device.Device) RegistrationLimits(org.eclipse.hono.service.management.tenant.RegistrationLimits) ResourceLimits(org.eclipse.hono.util.ResourceLimits) Logger(org.slf4j.Logger) JacksonCodec(io.vertx.core.json.jackson.JacksonCodec) TenantWithId(org.eclipse.hono.service.management.tenant.TenantWithId) HttpHeaders(io.vertx.core.http.HttpHeaders) PublicKey(java.security.PublicKey) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) VertxExtension(io.vertx.junit5.VertxExtension) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Adapter(org.eclipse.hono.util.Adapter) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Test(org.junit.jupiter.api.Test)

Example 68 with Tenant

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) DownstreamMessage(org.eclipse.hono.application.client.DownstreamMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) HashMap(java.util.HashMap) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Tenant(org.eclipse.hono.service.management.tenant.Tenant) CompositeFuture(io.vertx.core.CompositeFuture) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) MqttConnAckMessage(io.vertx.mqtt.messages.MqttConnAckMessage) Device(org.eclipse.hono.service.management.device.Device) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) MessageContext(org.eclipse.hono.application.client.MessageContext) Promise(io.vertx.core.Promise) Set(java.util.Set) ServerErrorException(org.eclipse.hono.client.ServerErrorException) DownstreamMessageAssertions(org.eclipse.hono.tests.DownstreamMessageAssertions) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Optional(java.util.Optional) MessageConsumer(org.eclipse.hono.application.client.MessageConsumer) Handler(io.vertx.core.Handler) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test)

Example 69 with Tenant

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);
}
Also used : Tenant(org.eclipse.hono.service.management.tenant.Tenant) VertxTestContext(io.vertx.junit5.VertxTestContext) Test(org.junit.jupiter.api.Test)

Example 70 with Tenant

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) DownstreamMessage(org.eclipse.hono.application.client.DownstreamMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) HashMap(java.util.HashMap) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Tenant(org.eclipse.hono.service.management.tenant.Tenant) CompositeFuture(io.vertx.core.CompositeFuture) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) MqttConnAckMessage(io.vertx.mqtt.messages.MqttConnAckMessage) Device(org.eclipse.hono.service.management.device.Device) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) MessageContext(org.eclipse.hono.application.client.MessageContext) Promise(io.vertx.core.Promise) Set(java.util.Set) ServerErrorException(org.eclipse.hono.client.ServerErrorException) DownstreamMessageAssertions(org.eclipse.hono.tests.DownstreamMessageAssertions) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Optional(java.util.Optional) MessageConsumer(org.eclipse.hono.application.client.MessageConsumer) Handler(io.vertx.core.Handler) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) VertxTestContext(io.vertx.junit5.VertxTestContext) Test(org.junit.jupiter.api.Test)

Aggregations

Tenant (org.eclipse.hono.service.management.tenant.Tenant)165 Test (org.junit.jupiter.api.Test)138 VertxTestContext (io.vertx.junit5.VertxTestContext)137 HttpURLConnection (java.net.HttpURLConnection)122 Truth.assertThat (com.google.common.truth.Truth.assertThat)113 TimeUnit (java.util.concurrent.TimeUnit)109 JsonObject (io.vertx.core.json.JsonObject)108 Future (io.vertx.core.Future)107 Timeout (io.vertx.junit5.Timeout)99 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)98 RegistryManagementConstants (org.eclipse.hono.util.RegistryManagementConstants)97 Constants (org.eclipse.hono.util.Constants)95 Tenants (org.eclipse.hono.tests.Tenants)92 Optional (java.util.Optional)91 Promise (io.vertx.core.Promise)86 Device (org.eclipse.hono.service.management.device.Device)80 Adapter (org.eclipse.hono.util.Adapter)78 VertxExtension (io.vertx.junit5.VertxExtension)77 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)77 Logger (org.slf4j.Logger)74