use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsWithDeviceAutoProvisioningUsingDeviceIdTemplate.
/**
* Verifies when no credentials are found and if the properties related to auto-provisioning of devices are
* enabled, the device id template is configured in the corresponding tenant's CA entry and the client context
* contains a serialized X.509 certificate then a device is auto-provisioned.
* (i.e A device is registered and it's corresponding credentials are stored).
* <p>
* Also verify that the device is auto-provisioned with a device id generated in accordance
* with the configured device id template.
* <p>
* It also verifies that an auto-provisioning event is successfully sent and the device registration
* is updated accordingly.
*
* @param ctx The vert.x test context.
* @throws CertificateException if the self signed certificate cannot be created.
* @throws FileNotFoundException if the self signed certificate cannot be read.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsWithDeviceAutoProvisioningUsingDeviceIdTemplate(final VertxTestContext ctx) throws CertificateException, FileNotFoundException {
// GIVEN a tenant's trusted CA entry with auto-provisioning enabled
// while device has not been registered and no credentials are stored yet
final X509Certificate cert = createCertificate();
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true).setAutoProvisioningDeviceIdTemplate("test-device-{{subject-dn}}");
final String expectedDeviceId = "test-device-" + cert.getSubjectX500Principal().getName(X500Principal.RFC2253);
testAutoProvisioningSucceeds(ctx, tenant, cert, false, expectedDeviceId);
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsWithAutoProvisioning.
/**
* Verifies that if no credentials are found and the client context in the Get request contains a serialized X.509
* certificate, the credentials and device are created (i.e., automatic provisioning is performed).
* <p>
* It also verifies that an auto-provisioning event is successfully sent and the device registration
* is updated accordingly.
*
* @param ctx The vert.x test context.
* @throws CertificateException if the self signed certificate cannot be created.
* @throws FileNotFoundException if the self signed certificate cannot be read.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsWithAutoProvisioning(final VertxTestContext ctx) throws CertificateException, FileNotFoundException {
// GIVEN a tenant with auto-provisioning enabled and a client context that contains a client certificate
// while device has not been registered and no credentials are stored yet
final X509Certificate cert = createCertificate();
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true);
testAutoProvisioningSucceeds(ctx, tenant, cert, false, null);
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsWithGatewayAutoProvisioningUsingDeviceIdTemplate.
/**
* Verifies when no credentials are found and if the properties related to auto-provisioning of gateways are
* enabled, device id template is configured in the corresponding tenant's CA entry and the client context
* contains a serialized X.509 certificate then a gateway is auto-provisioned.
* (i.e A gateway is registered and it's corresponding credentials are stored).
* <p>
* Also verify that the gateway is auto-provisioned with a device id generated in accordance
* with the configured device id template.
* <p>
* It also verifies that an auto-provisioning event is sent successfully sent and the device registration's
* property {@value RegistryManagementConstants#FIELD_AUTO_PROVISIONING_NOTIFICATION_SENT} is updated to
* {@code true}.
*
* @param ctx The vert.x test context.
* @throws CertificateException if the self signed certificate cannot be created.
* @throws FileNotFoundException if the self signed certificate cannot be read.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsWithGatewayAutoProvisioningUsingDeviceIdTemplate(final VertxTestContext ctx) throws CertificateException, FileNotFoundException {
// GIVEN a tenant's trusted CA entry with auto-provisioning and auto-provision as gateway enabled
// while gateway has not been registered and no credentials are stored yet
final X509Certificate cert = createCertificate();
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true).setAutoProvisioningAsGatewayEnabled(true).setAutoProvisioningDeviceIdTemplate("test-device-{{subject-cn}}");
final String expectedDeviceId = "test-device-" + AuthenticationConstants.getCommonName(cert.getSubjectX500Principal().getName(X500Principal.RFC2253));
testAutoProvisioningSucceeds(ctx, tenant, cert, true, expectedDeviceId);
}
use of io.vertx.junit5.Timeout in project hono by eclipse.
the class CredentialsApiTests method testGetCredentialsFailsForDisabledCredentials.
/**
* Verifies that the service fails when the credentials set is disabled.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsFailsForDisabledCredentials(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String authId = UUID.randomUUID().toString();
final CommonCredential credential = getRandomHashedPasswordCredential(authId);
credential.setEnabled(false);
getHelper().registry.registerDevice(tenantId, deviceId).compose(ok -> getHelper().registry.addCredentials(tenantId, deviceId, Collections.singleton(credential))).compose(ok -> getClient().get(tenantId, CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD, authId, spanContext)).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 CredentialsApiTests method testGetCredentialsByClientContext.
/**
* Verifies that the service returns credentials for a given type, authentication ID and matching client context.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetCredentialsByClientContext(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String authId = UUID.randomUUID().toString();
final CommonCredential credentials = getRandomHashedPasswordCredential(authId).putExtension("client-id", "gateway-one");
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(ok -> getClient().get(tenantId, CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD, authId, clientContext, spanContext)).onComplete(ctx.succeeding(result -> {
ctx.verify(() -> {
assertStandardProperties(result, deviceId, authId, CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD, 2);
});
ctx.completeNow();
}));
}
Aggregations