/** * Verifies that a device's status can be asserted by an existing gateway. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationSucceedsForExistingGateway(final TestContext ctx) { // GIVEN a registry that contains an enabled device that is configured to // be connected to an enabled gateway final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert the device's registration status for a gateway registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", "gw-1", ctx.asyncAssertSuccess(result -> { // THEN the response contains a 200 status ctx.assertEquals(HttpURLConnection.HTTP_OK, result.getStatus()); final JsonObject payload = result.getPayload(); ctx.assertNotNull(payload); // and contains a JWT token ctx.assertNotNull(payload.getString(RegistrationConstants.FIELD_ASSERTION)); })); }
/** * Verifies that an enabled device's status can be asserted successfully. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationReturnsToken(final TestContext ctx) { // GIVEN a registry that contains an enabled device with a default content type set final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert the device's registration status registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", ctx.asyncAssertSuccess(result -> { ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_OK); final JsonObject payload = result.getPayload(); ctx.assertNotNull(payload); // THEN the response contains a JWT token asserting the device's registration status final String compactJws = payload.getString(RegistrationConstants.FIELD_ASSERTION); ctx.assertNotNull(compactJws); // and contains the registered default content type final JsonObject defaults = payload.getJsonObject(RegistrationConstants.FIELD_DEFAULTS); ctx.assertNotNull(defaults); ctx.assertEquals("application/default", defaults.getString(MessageHelper.SYS_PROPERTY_CONTENT_TYPE)); })); }
/** * Verifies that a disabled device's status cannot be asserted. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationFailsForDisabledDevice(final TestContext ctx) { // GIVEN a registry that contains a disabled device final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert the device's registration status registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4712", ctx.asyncAssertSuccess(result -> { // THEN the response does not contain a JWT token ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_NOT_FOUND); ctx.assertNull(result.getPayload()); })); }
/** * Verifies that a non existing device's status cannot be asserted. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationFailsForNonExistingDevice(final TestContext ctx) { // GIVEN a registry that does not contain any devices final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert a device's registration status registrationService.assertRegistration(Constants.DEFAULT_TENANT, "non-existent", ctx.asyncAssertSuccess(result -> { // THEN the response does not contain a JWT token ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_NOT_FOUND); ctx.assertNull(result.getPayload()); })); }
/** * Verifies that a device's status cannot be asserted by a disabled gateway. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationFailsForDisabledGateway(final TestContext ctx) { // GIVEN a registry that contains an enabled device // and a gateway that the device is configured for but // which is disabled final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert the device's registration status for a gateway registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4713", "gw-3", ctx.asyncAssertSuccess(result -> { // THEN the response contains a 403 status ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_FORBIDDEN); // and does not contain a JWT token ctx.assertNull(result.getPayload()); })); }
/** * Verifies that a device's status cannot be asserted by a non-existing gateway. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationFailsForNonExistingGateway(final TestContext ctx) { // GIVEN a registry that contains an enabled device but no gateway final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert the device's registration status for a gateway registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", "non-existent-gw", ctx.asyncAssertSuccess(result -> { // THEN the response contains a 403 status ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_FORBIDDEN); // and does not contain a JWT token ctx.assertNull(result.getPayload()); })); }
/** * Verifies that a device's status cannot be asserted by a gateway that does not * match the device's configured gateway. * * @param ctx The vertx unit test context. */ @Test public void testAssertDeviceRegistrationFailsForWrongGateway(final TestContext ctx) { // GIVEN a registry that contains an enabled device and two gateways: // 1. the gateway that the device is configured for. // 2. another gateway final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService(); registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props)); // WHEN trying to assert the device's registration status for the wrong gateway registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", "gw-2", ctx.asyncAssertSuccess(result -> { // THEN the response contains a 403 status ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_FORBIDDEN); // and does not contain a JWT token ctx.assertNull(result.getPayload()); })); }