Search in sources :

Example 31 with Timeout

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) X509Certificate(java.security.cert.X509Certificate) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) X500Principal(javax.security.auth.x500.X500Principal) DownstreamMessage(org.eclipse.hono.application.client.DownstreamMessage) CertificateFactory(java.security.cert.CertificateFactory) LoggerFactory(org.slf4j.LoggerFactory) Credentials(org.eclipse.hono.service.management.credentials.Credentials) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) OptionalInt(java.util.OptionalInt) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) CredentialsClient(org.eclipse.hono.client.registry.CredentialsClient) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Device(org.eclipse.hono.service.management.device.Device) Logger(org.slf4j.Logger) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Vertx(io.vertx.core.Vertx) FileInputStream(java.io.FileInputStream) CertificateException(java.security.cert.CertificateException) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) DeviceStatus(org.eclipse.hono.service.management.device.DeviceStatus) MessageHelper(org.eclipse.hono.util.MessageHelper) EventConstants(org.eclipse.hono.util.EventConstants) FileNotFoundException(java.io.FileNotFoundException) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) AuthenticationConstants(org.eclipse.hono.util.AuthenticationConstants) SpanContext(io.opentracing.SpanContext) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) CommonCredential(org.eclipse.hono.service.management.credentials.CommonCredential) Checkpoint(io.vertx.junit5.Checkpoint) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) CredentialsObject(org.eclipse.hono.util.CredentialsObject) PasswordCredential(org.eclipse.hono.service.management.credentials.PasswordCredential) CertificateEncodingException(java.security.cert.CertificateEncodingException) CommonCredential(org.eclipse.hono.service.management.credentials.CommonCredential) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 32 with Timeout

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Device(org.eclipse.hono.service.management.device.Device) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 33 with Timeout

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Device(org.eclipse.hono.service.management.device.Device) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) Device(org.eclipse.hono.service.management.device.Device) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 34 with Timeout

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Device(org.eclipse.hono.service.management.device.Device) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 35 with Timeout

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiMap(io.vertx.core.MultiMap) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) BodyProcessorException(io.vertx.ext.web.validation.BodyProcessorException) Timeout(io.vertx.junit5.Timeout) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MultipartForm(io.vertx.ext.web.multipart.MultipartForm) ParameterLocation(io.vertx.ext.web.validation.impl.ParameterLocation) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) Route(io.vertx.ext.web.Route) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) StaticHandler(io.vertx.ext.web.handler.StaticHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Stream(java.util.stream.Stream) ValidationTestUtils(io.vertx.ext.web.validation.testutils.ValidationTestUtils) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) ParameterProcessorException(io.vertx.ext.web.validation.ParameterProcessorException) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Pattern(java.util.regex.Pattern) Handler(io.vertx.core.Handler) Checkpoint(io.vertx.junit5.Checkpoint) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Aggregations

Timeout (io.vertx.junit5.Timeout)75 VertxTestContext (io.vertx.junit5.VertxTestContext)75 Test (org.junit.jupiter.api.Test)73 TimeUnit (java.util.concurrent.TimeUnit)67 Truth.assertThat (com.google.common.truth.Truth.assertThat)65 Future (io.vertx.core.Future)56 HttpURLConnection (java.net.HttpURLConnection)52 Handler (io.vertx.core.Handler)49 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)49 Buffer (io.vertx.core.buffer.Buffer)48 BeforeEach (org.junit.jupiter.api.BeforeEach)46 Promise (io.vertx.core.Promise)45 Vertx (io.vertx.core.Vertx)39 JsonObject (io.vertx.core.json.JsonObject)39 VertxExtension (io.vertx.junit5.VertxExtension)39 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)39 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 Tenant (org.eclipse.hono.service.management.tenant.Tenant)36 MethodSource (org.junit.jupiter.params.provider.MethodSource)35