use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsSucceedsForNonExistingClientContext.
/**
* Verifies that a request for credentials using a client context succeeds if the credentials on record
* do not have any extension properties with keys matching the provided client context.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsSucceedsForNonExistingClientContext(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String authId = UUID.randomUUID().toString();
final CommonCredential credentials = getRandomHashedPasswordCredential(authId).putExtension("other", "property");
final JsonObject clientContext = new JsonObject().put("client-id", "gateway-one");
getHelper().registry.registerDevice(tenantId, deviceId).compose(httpResponse -> getHelper().registry.addCredentials(tenantId, deviceId, List.of(credentials))).compose(httpResponse -> getClient().get(tenantId, CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD, authId, clientContext, spanContext)).onComplete(ctx.succeeding(credentialsObject -> {
ctx.verify(() -> {
assertThat(credentialsObject.getSecrets()).isNotEmpty();
});
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationFailsForDisabledDevice.
/**
* Verifies that the registry fails to assert a disabled device's registration status with a 404 error code.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForDisabledDevice(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final Device device = new Device();
device.setEnabled(false);
getHelper().registry.registerDevice(tenantId, deviceId, device).compose(ok -> getClient().assertRegistration(tenantId, deviceId, null, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
ctx.verify(() -> assertErrorCode(t, HttpURLConnection.HTTP_NOT_FOUND));
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationSucceedsForDevice.
/**
* Verifies that the registry succeeds a request to assert a device's registration status.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationSucceedsForDevice(final VertxTestContext ctx) {
final JsonObject defaults = new JsonObject().put(MessageHelper.SYS_PROPERTY_CONTENT_TYPE, "application/vnd.acme+json");
final Device device = new Device();
device.setDefaults(defaults.getMap());
final String deviceId = getHelper().getRandomDeviceId(tenantId);
getHelper().registry.registerDevice(tenantId, deviceId, device).compose(r -> getClient().assertRegistration(tenantId, deviceId, null, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(resp -> {
ctx.verify(() -> {
assertThat(resp.getDeviceId()).isEqualTo(deviceId);
assertThat(resp.getDefaults()).containsExactlyEntriesIn(defaults.getMap());
});
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationFailsForUnauthorizedGateway.
/**
* Verifies that the registry fails a gateway's request to assert a device's registration status for which it is not
* authorized with a 403 error code.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForUnauthorizedGateway(final VertxTestContext ctx) {
// Prepare the identities to insert
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String authorizedGateway = getHelper().getRandomDeviceId(tenantId);
final String unauthorizedGateway = getHelper().getRandomDeviceId(tenantId);
final Device device = new Device();
device.setVia(Collections.singletonList(authorizedGateway));
getHelper().registry.registerDevice(tenantId, authorizedGateway).compose(ok -> getHelper().registry.registerDevice(tenantId, unauthorizedGateway)).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(ok -> getClient().assertRegistration(tenantId, deviceId, unauthorizedGateway, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
assertErrorCode(t, HttpURLConnection.HTTP_FORBIDDEN);
ctx.completeNow();
}));
}
use of io.vertx.junit5.Timeout in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testIssue1876.
@Timeout(10000)
@Test
public void testIssue1876(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, "specs/repro_1876.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false).setMountNotImplementedHandler(true));
routerBuilder.operation("createAccount").handler(routingContext -> routingContext.response().setStatusCode(200).end());
routerBuilder.operation("createAccountMember").handler(routingContext -> routingContext.response().setStatusCode(200).end());
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/accounts").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("id", 123).put("type", "account-registration").put("attributes", new JsonObject().put("ownerEmail", "test@gmail.com"))), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/members").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("type", "account-member-registration").put("attributes", new JsonObject().put("email", "test@gmail.com"))), testContext, checkpoint);
});
}
Aggregations