use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class AmqpConnectionIT method testConnectX509SucceedsForRegisteredDevice.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate succeeds.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param ctx The test context
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@ValueSource(strings = { IntegrationTestSupport.TLS_VERSION_1_2, IntegrationTestSupport.TLS_VERSION_1_3 })
public void testConnectX509SucceedsForRegisteredDevice(final String tlsVersion, final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert), deviceId, cert)).compose(ok -> connectToAdapter(IntegrationTestSupport.AMQP_HOST, deviceCert, tlsVersion)).onComplete(ctx.succeeding(con -> {
ctx.verify(() -> assertThat(con.isDisconnected()).isFalse());
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class AmqpConnectionIT method testConnectFailsForNonExistingDevice.
/**
* Verifies that the adapter rejects connection attempts from unknown devices
* for which neither registration information nor credentials are on record.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsForNonExistingDevice(final VertxTestContext ctx) {
// GIVEN an existing tenant
final String tenantId = helper.getRandomTenantId();
final Tenant tenant = new Tenant();
tenant.setEnabled(true);
helper.registry.addTenant(tenantId, tenant).compose(ok -> connectToAdapter(IntegrationTestSupport.getUsername("non-existing", tenantId), "secret")).onComplete(ctx.failing(t -> {
// THEN the connection is refused
ctx.verify(() -> assertThat(t).isInstanceOf(SaslException.class));
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class AmqpConnectionIT method testConnectX509SucceedsUsingSniWithTenantAlias.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate succeeds
* for a device belonging to a tenant with a tenant alias.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param ctx The test context
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@ValueSource(strings = { IntegrationTestSupport.TLS_VERSION_1_2, IntegrationTestSupport.TLS_VERSION_1_3 })
public void testConnectX509SucceedsUsingSniWithTenantAlias(final String tlsVersion, final VertxTestContext ctx) {
assumeTrue(IntegrationTestSupport.isTrustAnchorGroupsSupported(), "device registry does not support trust anchor groups");
assumeTrue(IntegrationTestSupport.isTenantAliasSupported(), "device registry does not support tenant aliases");
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addTenant(helper.getRandomTenantId(), Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group")).map(cert)).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group").setAlias("test-alias"), deviceId, cert)).compose(ok -> connectToAdapter("test-alias." + IntegrationTestSupport.AMQP_HOST, deviceCert, tlsVersion)).onComplete(ctx.succeeding(con -> {
ctx.verify(() -> assertThat(con.isDisconnected()).isFalse());
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class AmqpConnectionIT method testConnectSucceedsWithAutoProvisioning.
/**
* Verifies that the adapter opens a connection if auto-provisioning is enabled for the device certificate.
*
* @param ctx The test context.
*/
@Test
public void testConnectSucceedsWithAutoProvisioning(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
final Promise<String> autoProvisionedDeviceId = Promise.promise();
helper.createAutoProvisioningNotificationConsumer(ctx, autoProvisionedDeviceId, tenantId).compose(ok -> helper.getCertificate(deviceCert.certificatePath())).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true);
return helper.registry.addTenant(tenantId, tenant);
}).compose(ok -> connectToAdapter(deviceCert)).compose(ok -> autoProvisionedDeviceId.future()).compose(deviceId -> helper.registry.getRegistrationInfo(tenantId, deviceId)).onComplete(ctx.succeeding(registrationResult -> {
ctx.verify(() -> {
final var info = registrationResult.bodyAsJsonObject();
IntegrationTestSupport.assertDeviceStatusProperties(info.getJsonObject(RegistryManagementConstants.FIELD_STATUS), true);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.util.Adapter in project hono by eclipse.
the class VertxBasedAmqpProtocolAdapterTest method testMessageLimitExceededForADownstreamMessage.
private void testMessageLimitExceededForADownstreamMessage(final VertxTestContext ctx, final Message message, final Consumer<Void> postUploadAssertions) {
final ProtonDelivery delivery = mock(ProtonDelivery.class);
// AT LEAST ONCE
when(delivery.remotelySettled()).thenReturn(false);
final AmqpContext amqpContext = AmqpContext.fromMessage(delivery, message, span, null);
// GIVEN an AMQP adapter
givenAnAdapter(properties);
givenATelemetrySenderForAnyTenant();
// which is enabled for a tenant with exceeded message limit
when(resourceLimitChecks.isMessageLimitReached(any(TenantObject.class), anyLong(), any(SpanContext.class))).thenReturn(Future.succeededFuture(Boolean.TRUE));
// WHEN a device uploads a message to the adapter with AT_LEAST_ONCE delivery semantics
adapter.onMessageReceived(amqpContext).onComplete(ctx.failing(t -> {
ctx.verify(() -> {
// THEN the message limit is exceeded
assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpUtils.HTTP_TOO_MANY_REQUESTS);
// AND the client receives a corresponding REJECTED disposition
verify(delivery).disposition(argThat(s -> {
if (s instanceof Rejected) {
return AmqpError.RESOURCE_LIMIT_EXCEEDED.equals(((Rejected) s).getError().getCondition());
} else {
return false;
}
}), eq(true));
// AND
postUploadAssertions.accept(null);
});
ctx.completeNow();
}));
}
Aggregations