use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MongoDbBasedRegistrationServiceTest method testCreateDeviceFailsIfTenantLevelDeviceLimitHasBeenReached.
/**
* Verifies that a request to create more devices than the limit configured at the tenant level fails with a 403.
*
* @param ctx The vert.x test context.
*/
@Test
public void testCreateDeviceFailsIfTenantLevelDeviceLimitHasBeenReached(final VertxTestContext ctx) {
config.setMaxDevicesPerTenant(3);
when(tenantInformationService.getTenant(anyString(), any())).thenReturn(Future.succeededFuture(new Tenant().setRegistrationLimits(new RegistrationLimits().setMaxNumberOfDevices(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();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TenantManagementIT method testUpdateTenantFailsForRequestPayloadExceedingLimit.
/**
* Verifies that a request to update a tenant with a body that exceeds the registry's max payload limit
* fails with a {@link HttpURLConnection#HTTP_ENTITY_TOO_LARGE} status code.
*
* @param context The vert.x test context.
*/
@Test
public void testUpdateTenantFailsForRequestPayloadExceedingLimit(final VertxTestContext context) {
final String tenantId = getHelper().getRandomTenantId();
getHelper().registry.addTenant(tenantId, new Tenant()).compose(ok -> {
final var data = new char[3000];
Arrays.fill(data, 'x');
final Tenant payload = new Tenant();
payload.setExtensions(Map.of("data", new String(data)));
return getHelper().registry.updateTenant(tenantId, payload, HttpURLConnection.HTTP_ENTITY_TOO_LARGE);
}).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 buildTenantPayload.
/**
* Creates a tenant payload.
* <p>
* The tenant payload contains configurations for the http, mqtt and a custom adapter.
*
* @return The tenant object.
*/
private static Tenant buildTenantPayload() {
final Tenant tenant = new Tenant();
tenant.putExtension("plan", "unlimited");
// explicitly (add the messaging-type extension (implicitly added by DeviceRegistryHttpClient)
// here so that it is also part of the expected output and hence verified
tenant.putExtension(TenantConstants.FIELD_EXT_MESSAGING_TYPE, IntegrationTestSupport.getConfiguredMessagingType().name());
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(true).setDeviceAuthenticationRequired(true));
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT).setEnabled(true).setDeviceAuthenticationRequired(true));
tenant.addAdapterConfig(new Adapter("custom").setEnabled(false).setDeviceAuthenticationRequired(false).putExtension("maxInstances", 4));
return tenant;
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TenantManagementIT method testAddTenantFailsForMalformedAdapterConfiguration.
/**
* Verifies that the service returns a 400 status code for a request to add a tenant containing
* multiple adapter configurations for the same adapter type.
*
* @param context The Vert.x test context.
*/
@Test
public void testAddTenantFailsForMalformedAdapterConfiguration(final VertxTestContext context) {
final Adapter httpAdapter = new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP);
final JsonObject requestBody = JsonObject.mapFrom(buildTenantPayload());
requestBody.getJsonArray(RegistryManagementConstants.FIELD_ADAPTERS).add(JsonObject.mapFrom(httpAdapter));
final String tenantId = getHelper().getRandomTenantId();
getHelper().registry.addTenant(tenantId, requestBody, "application/json", HttpURLConnection.HTTP_BAD_REQUEST).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 testAddTenantFailsForConfigurationWithNonUniqueTrustAnchorIds.
/**
* Verifies that the service returns a 400 status code for an add 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 testAddTenantFailsForConfigurationWithNonUniqueTrustAnchorIds(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 tenant = new Tenant().setTrustedCertificateAuthorities(List.of(trustAnchor1, trustAnchor2));
final String tenantId = getHelper().getRandomTenantId();
getHelper().registry.addTenant(tenantId, tenant, HttpURLConnection.HTTP_BAD_REQUEST).onComplete(context.succeeding(response -> {
context.verify(() -> IntegrationTestSupport.assertErrorPayload(response));
context.completeNow();
}));
}
Aggregations