use of org.eclipse.hono.service.management.tenant.RegistrationLimits 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.RegistrationLimits in project hono by eclipse.
the class MongoDbBasedCredentialServiceTest method testUpdateCredentialsFailsForExceededCredentialsPerDeviceLimit.
/**
* Verifies that a request to update credentials of a device fails with a 403 status code
* if the number of credentials exceeds the tenant's configured limit.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUpdateCredentialsFailsForExceededCredentialsPerDeviceLimit(final VertxTestContext ctx) {
final var tenantId = UUID.randomUUID().toString();
final var deviceId = UUID.randomUUID().toString();
when(tenantInformationService.getTenant(anyString(), any())).thenReturn(Future.succeededFuture(new Tenant().setRegistrationLimits(new RegistrationLimits().setMaxCredentialsPerDevice(1))));
credentialsManagementService.updateCredentials(tenantId, deviceId, List.of(Credentials.createPasswordCredential("device1", "secret"), Credentials.createPasswordCredential("device2", "secret")), Optional.empty(), NoopSpan.INSTANCE).onComplete(ctx.failing(t -> {
ctx.verify(() -> {
Assertions.assertServiceInvocationException(t, HttpURLConnection.HTTP_FORBIDDEN);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.RegistrationLimits in project hono by eclipse.
the class JdbcBasedCredentialsServiceTest method testUpdateCredentialsFailsForExceededCredentialsPerDeviceLimit.
/**
* Verifies that a request to update credentials of a device fails with a 403 status code
* if the number of credentials exceeds the tenant's configured limit.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUpdateCredentialsFailsForExceededCredentialsPerDeviceLimit(final VertxTestContext ctx) {
final var tenantId = UUID.randomUUID().toString();
final var deviceId = UUID.randomUUID().toString();
when(tenantInformationService.getTenant(anyString(), any())).thenReturn(Future.succeededFuture(new Tenant().setRegistrationLimits(new RegistrationLimits().setMaxCredentialsPerDevice(1))));
getDeviceManagementService().createDevice(tenantId, Optional.of(deviceId), new Device(), NoopSpan.INSTANCE).onFailure(ctx::failNow).compose(ok -> getCredentialsManagementService().updateCredentials(tenantId, deviceId, List.of(Credentials.createPasswordCredential("device1", "secret"), Credentials.createPasswordCredential("device2", "secret")), Optional.empty(), NoopSpan.INSTANCE)).onComplete(ctx.failing(t -> {
ctx.verify(() -> {
Assertions.assertServiceInvocationException(t, HttpURLConnection.HTTP_FORBIDDEN);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.RegistrationLimits in project hono by eclipse.
the class JdbcBasedRegistrationServiceTest 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) {
properties.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.RegistrationLimits in project hono by eclipse.
the class TenantManagementIT method testGetTenantSucceeds.
/**
* Verifies that a correctly added tenant record can be successfully looked up again.
*
* @param context The vert.x test context.
*/
@Test
public void testGetTenantSucceeds(final VertxTestContext context) {
final var resourceLimits = new ResourceLimits();
resourceLimits.setMaxConnections(1000);
final var registrationLimits = new RegistrationLimits();
registrationLimits.setMaxNumberOfDevices(100);
registrationLimits.setMaxCredentialsPerDevice(5);
final Tenant requestBody = buildTenantPayload();
requestBody.setMinimumMessageSize(2048);
requestBody.setResourceLimits(resourceLimits);
requestBody.setRegistrationLimits(registrationLimits);
final String tenantId = getHelper().getRandomTenantId();
LOG.debug("registering tenant using Management API: {}", JsonObject.mapFrom(requestBody).encodePrettily());
getHelper().registry.addTenant(tenantId, requestBody).compose(ar -> getHelper().registry.getTenant(tenantId)).onComplete(context.succeeding(httpResponse -> {
final JsonObject json = httpResponse.bodyAsJsonObject();
LOG.debug("retrieved tenant using Tenant API: {}", json.encodePrettily());
context.verify(() -> {
assertThat(json.containsKey(RegistryManagementConstants.FIELD_STATUS)).isFalse();
assertTrue(IntegrationTestSupport.testJsonObjectToBeContained(json, JsonObject.mapFrom(requestBody)));
});
context.completeNow();
}));
}
Aggregations