use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class CommandAndControlAmqpIT method createRandomTenantAndInitDeviceId.
/**
* Creates a random tenant.
* <p>
* The tenant will be configured with a max TTL for command responses.
*
* @param ctx The vert.x test context.
*/
@BeforeEach
public void createRandomTenantAndInitDeviceId(final VertxTestContext ctx) {
tenantId = helper.getRandomTenantId();
deviceId = helper.getRandomDeviceId(tenantId);
final Tenant tenantConfig = new Tenant().setResourceLimits(new ResourceLimits().setMaxTtlCommandResponse(TTL_COMMAND_RESPONSE.toSeconds()));
helper.registry.addTenant(tenantId, tenantConfig).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpUploadTestBase method testAdapterRejectsBadInboundMessage.
/**
* Verifies that a message containing a payload which has the <em>empty notification</em>
* content type is rejected by the adapter.
*
* @param context The Vert.x context for running asynchronous tests.
* @throws InterruptedException if test is interrupted while running.
*/
@Test
@Timeout(timeUnit = TimeUnit.SECONDS, value = 10)
public void testAdapterRejectsBadInboundMessage(final VertxTestContext context) throws InterruptedException {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final VertxTestContext setup = new VertxTestContext();
setupProtocolAdapter(tenantId, new Tenant(), deviceId, ProtonQoS.AT_LEAST_ONCE).map(s -> {
setup.verify(() -> {
final UnsignedLong maxMessageSize = s.getRemoteMaxMessageSize();
assertWithMessage("max-message-size included in adapter's attach frame").that(maxMessageSize).isNotNull();
assertWithMessage("max-message-size").that(maxMessageSize.longValue()).isGreaterThan(0);
});
sender = s;
return s;
}).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
context.failNow(setup.causeOfFailure());
return;
}
final Message msg = ProtonHelper.message("some payload");
msg.setContentType(EventConstants.CONTENT_TYPE_EMPTY_NOTIFICATION);
msg.setAddress(getEndpointName());
sender.send(msg, delivery -> {
context.verify(() -> {
assertThat(delivery.getRemoteState()).isInstanceOf(Rejected.class);
final Rejected rejected = (Rejected) delivery.getRemoteState();
final ErrorCondition error = rejected.getError();
assertThat((Object) error.getCondition()).isEqualTo(Constants.AMQP_BAD_REQUEST);
});
context.completeNow();
});
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class MongoDbBasedRegistrationServiceTest method testDeleteDeviceSucceedsForNonExistingTenant.
/**
* Verifies that a request to delete a device succeeds even if the tenant that the device belongs to does not
* exist (anymore).
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteDeviceSucceedsForNonExistingTenant(final VertxTestContext ctx) {
when(tenantInformationService.tenantExists(eq(TENANT), any(Span.class))).thenReturn(// report that tenant exists when createDevice is invoked
Future.succeededFuture(OperationResult.ok(HttpURLConnection.HTTP_OK, TenantKey.from(TENANT), Optional.empty(), Optional.empty())), // report that tenant does not exist afterwards
Future.succeededFuture(OperationResult.from(HttpURLConnection.HTTP_NOT_FOUND)));
getDeviceManagementService().createDevice(TENANT, Optional.empty(), new Device(), NoopSpan.INSTANCE).compose(result -> getDeviceManagementService().deleteDevice(TENANT, result.getPayload().getId(), Optional.empty(), NoopSpan.INSTANCE)).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.hono.service.management.tenant.Tenant 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.Tenant in project hono by eclipse.
the class MongoDbBasedTenantServiceTest method testAddTenantFailsForDuplicateAlias.
/**
* Verifies that a tenant cannot be added if it uses an already registered
* alias.
*
* @param ctx The vert.x test context.
*/
@Test
public void testAddTenantFailsForDuplicateAlias(final VertxTestContext ctx) {
final var tenantSpec = new Tenant().setAlias("the-alias");
addTenant("tenant", tenantSpec).compose(ok -> getTenantManagementService().createTenant(Optional.of("other-tenant"), tenantSpec, NoopSpan.INSTANCE)).onComplete(ctx.failing(t -> {
ctx.verify(() -> Assertions.assertServiceInvocationException(t, HttpURLConnection.HTTP_CONFLICT));
ctx.completeNow();
}));
}
Aggregations