Search in sources :

Example 11 with TrustedCertificateAuthority

use of org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority in project hono by eclipse.

the class TenantManagementIT method testUpdateTenantFailsForConfigurationWithNonUniqueTrustAnchorIds.

/**
 * Verifies that the service returns a 400 status code for an update tenant request containing a malformed trust
 * configuration (i.e with non-unique trust anchor IDs).
 *
 * @param context The Vert.x test context.
 */
@Test
public void testUpdateTenantFailsForConfigurationWithNonUniqueTrustAnchorIds(final VertxTestContext context) {
    final PublicKey publicKey = TenantApiTests.getRandomPublicKey();
    final TrustedCertificateAuthority trustAnchor1 = Tenants.createTrustAnchor("test-ca", "CN=test-dn", publicKey.getEncoded(), publicKey.getAlgorithm(), Instant.now(), Instant.now().plus(365, ChronoUnit.DAYS));
    final TrustedCertificateAuthority trustAnchor2 = Tenants.createTrustAnchor("test-ca", "CN=test-dn", publicKey.getEncoded(), publicKey.getAlgorithm(), Instant.now().plus(366, ChronoUnit.DAYS), Instant.now().plus(730, ChronoUnit.DAYS));
    final Tenant tenantForUpdate = new Tenant().setTrustedCertificateAuthorities(List.of(trustAnchor1, trustAnchor2));
    final String tenantId = getHelper().getRandomTenantId();
    getHelper().registry.addTenant(tenantId, new Tenant()).compose(ok -> getHelper().registry.updateTenant(tenantId, tenantForUpdate, HttpURLConnection.HTTP_BAD_REQUEST)).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 12 with TrustedCertificateAuthority

use of org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority in project hono by eclipse.

the class TenantManagementIT method testUpdateTenantFailsForConfigurationWithDuplicateTrustAnchor.

/**
 * Verifies that the service returns a 409 status code for an update 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 testUpdateTenantFailsForConfigurationWithDuplicateTrustAnchor(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(getHelper().getRandomTenantId(), tenant).onFailure(context::failNow).compose(ok -> getHelper().registry.addTenant(tenantId, new Tenant())).onFailure(context::failNow).compose(ok -> getHelper().registry.updateTenant(tenantId, 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)

Aggregations

TrustedCertificateAuthority (org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority)12 Tenant (org.eclipse.hono.service.management.tenant.Tenant)11 JsonArray (io.vertx.core.json.JsonArray)10 JsonObject (io.vertx.core.json.JsonObject)10 Map (java.util.Map)10 TypeReference (com.fasterxml.jackson.core.type.TypeReference)9 Truth.assertThat (com.google.common.truth.Truth.assertThat)9 CompositeFuture (io.vertx.core.CompositeFuture)9 MultiMap (io.vertx.core.MultiMap)9 HttpHeaders (io.vertx.core.http.HttpHeaders)9 JacksonCodec (io.vertx.core.json.jackson.JacksonCodec)9 Timeout (io.vertx.junit5.Timeout)9 VertxExtension (io.vertx.junit5.VertxExtension)9 VertxTestContext (io.vertx.junit5.VertxTestContext)9 HttpURLConnection (java.net.HttpURLConnection)9 PublicKey (java.security.PublicKey)9 Instant (java.time.Instant)9 ChronoUnit (java.time.temporal.ChronoUnit)9 Arrays (java.util.Arrays)9 List (java.util.List)9