use of io.vertx.junit5.Timeout in project hono by eclipse.
the class TenantApiTests method testGetTenantByCaFailsIfNotAuthorized.
/**
* Verifies that a request to retrieve information for a tenant by the
* subject DN of the trusted certificate authority fails with a
* <em>403 Forbidden</em> status if the client is not authorized to retrieve
* information for the tenant.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetTenantByCaFailsIfNotAuthorized(final VertxTestContext ctx) {
final String tenantId = getHelper().getRandomTenantId();
final X500Principal subjectDn = new X500Principal("CN=ca-http,OU=Hono,O=Eclipse");
final PublicKey publicKey = getRandomPublicKey();
final Tenant tenant = Tenants.createTenantForTrustAnchor(subjectDn, publicKey);
getHelper().registry.addTenant(tenantId, tenant).compose(r -> getRestrictedClient().get(subjectDn, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
assertErrorCode(t, HttpURLConnection.HTTP_FORBIDDEN);
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class TenantApiTests method testGetTenant.
/**
* Verifies that an existing tenant can be retrieved.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetTenant(final VertxTestContext ctx) {
final JsonObject defaults = new JsonObject().put("ttl", 30);
final Map<String, Object> httpAdapterExtensions = Map.of("deployment", Map.of("maxInstances", 4));
final ResourceLimits resourceLimits = new ResourceLimits().setMaxConnections(100000).setMaxTtl(30L).setDataVolume(new DataVolume(Instant.parse("2019-07-27T14:30:00Z"), new ResourceLimitsPeriod(PeriodMode.days).setNoOfDays(30), 2147483648L));
final String tenantId = getHelper().getRandomTenantId();
final Tenant tenant = new Tenant();
tenant.setEnabled(true);
tenant.setResourceLimits(resourceLimits);
tenant.setDefaults(defaults.getMap());
tenant.putExtension("customer", "ACME Inc.");
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT).setEnabled(true).setDeviceAuthenticationRequired(false)).addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(true).setDeviceAuthenticationRequired(true).setExtensions(httpAdapterExtensions));
// expected tenant object
final TenantObject expectedTenantObject = TenantObject.from(tenantId, true).setDefaults(defaults).setResourceLimits(resourceLimits).addAdapter(new org.eclipse.hono.util.Adapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT).setEnabled(Boolean.TRUE).setDeviceAuthenticationRequired(Boolean.FALSE)).addAdapter(new org.eclipse.hono.util.Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(Boolean.TRUE).setDeviceAuthenticationRequired(Boolean.TRUE).setExtensions(httpAdapterExtensions));
getHelper().registry.addTenant(tenantId, tenant).compose(ok -> getAdminClient().get(tenantId, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(tenantObject -> {
ctx.verify(() -> {
assertThat(tenantObject.getDefaults()).isEqualTo(expectedTenantObject.getDefaults());
Assertions.assertThat(tenantObject.getAdapters()).usingRecursiveFieldByFieldElementComparator().containsAll(expectedTenantObject.getAdapters());
assertThat(tenantObject.getResourceLimits().getMaxConnections()).isEqualTo(expectedTenantObject.getResourceLimits().getMaxConnections());
assertThat(tenantObject.getResourceLimits().getMaxTtl()).isEqualTo(expectedTenantObject.getResourceLimits().getMaxTtl());
assertThat(tenantObject.getResourceLimits().getDataVolume().getMaxBytes()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getMaxBytes());
assertThat(tenantObject.getResourceLimits().getDataVolume().getEffectiveSince()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getEffectiveSince());
assertThat(tenantObject.getResourceLimits().getDataVolume().getPeriod().getMode()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getPeriod().getMode());
assertThat(tenantObject.getResourceLimits().getDataVolume().getPeriod().getNoOfDays()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getPeriod().getNoOfDays());
final JsonObject extensions = tenantObject.getProperty("ext", JsonObject.class);
assertThat(extensions.getString("customer")).isEqualTo("ACME Inc.");
// implicitly added by DeviceRegistryHttpClient
assertThat(extensions.getString(TenantConstants.FIELD_EXT_MESSAGING_TYPE)).isEqualTo(IntegrationTestSupport.getConfiguredMessagingType().name());
});
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class TenantApiTests method testGetTenantByCa.
/**
* Verifies that an existing tenant can be retrieved by a trusted CA's subject DN.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetTenantByCa(final VertxTestContext ctx) {
final String tenantId = getHelper().getRandomTenantId();
final X500Principal subjectDn = new X500Principal("CN=ca, OU=Hono, O=Eclipse");
final PublicKey publicKey = getRandomPublicKey();
final Tenant tenant = Tenants.createTenantForTrustAnchor(subjectDn, publicKey);
getHelper().registry.addTenant(tenantId, tenant).compose(r -> getAdminClient().get(subjectDn, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(tenantObject -> {
ctx.verify(() -> {
assertThat(tenantObject.getTenantId()).isEqualTo(tenantId);
assertThat(tenantObject.getTrustAnchors()).hasSize(1);
final TrustAnchor trustAnchor = tenantObject.getTrustAnchors().iterator().next();
assertThat(trustAnchor.getCA()).isEqualTo(subjectDn);
assertThat(trustAnchor.getCAPublicKey()).isEqualTo(publicKey);
});
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsJmsIT method testRequestFailsForUnsupportedOperation.
/**
* Verifies that the service responds with a 400 status to a request that
* indicates an unsupported operation in its subject.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testRequestFailsForUnsupportedOperation(final VertxTestContext ctx) {
final JsonObject searchCriteria = CredentialsConstants.getSearchCriteria(CredentialsConstants.SECRETS_TYPE_PRESHARED_KEY, "device");
getJmsBasedClient().sendRequest(tenantId, "unsupported-operation", null, searchCriteria.toBuffer()).onComplete(ctx.failing(t -> {
assertErrorCode(t, HttpURLConnection.HTTP_BAD_REQUEST);
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsFailsForNonMatchingClientContext.
/**
* Verifies that a request for credentials using a client context that does not match
* the credentials on record fails with a 404.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsFailsForNonMatchingClientContext(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String authId = UUID.randomUUID().toString();
final CommonCredential credentials = getRandomHashedPasswordCredential(authId).putExtension("client-id", UUID.randomUUID().toString());
final JsonObject clientContext = new JsonObject().put("client-id", "non-matching");
getHelper().registry.registerDevice(tenantId, deviceId).compose(httpResponse -> getHelper().registry.addCredentials(tenantId, deviceId, List.of(credentials))).compose(ok -> getClient().get(tenantId, CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD, authId, clientContext, spanContext)).onComplete(ctx.failing(t -> {
ctx.verify(() -> assertErrorCode(t, HttpURLConnection.HTTP_NOT_FOUND));
ctx.completeNow();
}));
}
Aggregations