use of org.eclipse.hono.auth.Device in project hono by eclipse.
the class CredentialsApiAuthProviderTest method testValidateFailsIfCredentialsAreDisabled.
/**
* Verifies that credentials validation fails if the credentials on record are disabled.
*
* @param ctx The vert.x test context.
*/
@Test
public void testValidateFailsIfCredentialsAreDisabled(final VertxTestContext ctx) {
// WHEN trying to authenticate a disabled device
final AbstractDeviceCredentials creds = getDeviceCredentials("type", "tenant", "identity");
final CredentialsObject credentialsOnRecord = getCredentialsObject("type", "identity", "device", false).addSecret(CredentialsObject.emptySecret(Instant.now().minusSeconds(120), null));
when(credentialsClient.get(eq("tenant"), eq("type"), eq("identity"), any(JsonObject.class), any())).thenReturn(Future.succeededFuture(credentialsOnRecord));
provider.authenticate(creds, null, ctx.failing(t -> {
// THEN authentication fails with a 401 client error
ctx.verify(() -> assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_UNAUTHORIZED));
ctx.completeNow();
}));
}
use of org.eclipse.hono.auth.Device in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testDeviceConnectionIsClosedOnDeviceDeletedNotification.
/**
* Verifies that the adapter closes the connection to an authenticated device when a notification
* about the deletion of registration data of that device has been received.
*
* @param ctx The vert.x test context.
*/
@Test
public void testDeviceConnectionIsClosedOnDeviceDeletedNotification(final VertxTestContext ctx) {
final Device device = new Device("tenant", "deviceId");
testDeviceConnectionIsClosedOnDeviceOrTenantChangeNotification(ctx, device, new DeviceChangeNotification(LifecycleChange.DELETE, "tenant", "deviceId", Instant.now(), true));
}
use of org.eclipse.hono.auth.Device in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testDeviceConnectionIsClosedOnTenantDeletedNotification.
/**
* Verifies that the adapter closes the connection to an authenticated device when a notification
* about the deletion of the tenant of that device has been received.
*
* @param ctx The vert.x test context.
*/
@Test
public void testDeviceConnectionIsClosedOnTenantDeletedNotification(final VertxTestContext ctx) {
final Device device = new Device("tenant", "deviceId");
testDeviceConnectionIsClosedOnDeviceOrTenantChangeNotification(ctx, device, new TenantChangeNotification(LifecycleChange.DELETE, "tenant", Instant.now(), true));
}
use of org.eclipse.hono.auth.Device in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testUploadMessageSupportsShortAndLongEndpointNames.
/**
* Verifies that the adapter will accept uploading messages to standard as well as shortened topic names.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUploadMessageSupportsShortAndLongEndpointNames(final VertxTestContext ctx) {
// GIVEN an adapter with downstream telemetry & event consumers
givenAnAdapter(properties);
givenATelemetrySenderForAnyTenant();
givenAnEventSenderForAnyTenant();
// WHEN a device publishes events and telemetry messages
final MqttEndpoint endpoint = mockEndpoint();
when(endpoint.isConnected()).thenReturn(Boolean.TRUE);
final Buffer payload = Buffer.buffer("some payload");
final MqttPublishMessage messageFromDevice = mock(MqttPublishMessage.class);
when(messageFromDevice.qosLevel()).thenReturn(MqttQoS.AT_LEAST_ONCE);
when(messageFromDevice.messageId()).thenReturn(5555555);
when(messageFromDevice.payload()).thenReturn(payload);
ResourceIdentifier resourceId = ResourceIdentifier.from("telemetry", "my-tenant", "4712");
when(messageFromDevice.topicName()).thenReturn(resourceId.toString());
adapter.uploadMessage(newMqttContext(messageFromDevice, endpoint, span), resourceId, messageFromDevice).onFailure(ctx::failNow);
resourceId = ResourceIdentifier.from("event", "my-tenant", "4712");
when(messageFromDevice.topicName()).thenReturn(resourceId.toString());
adapter.uploadMessage(newMqttContext(messageFromDevice, endpoint, span), resourceId, messageFromDevice).onFailure(ctx::failNow);
resourceId = ResourceIdentifier.from("t", "my-tenant", "4712");
when(messageFromDevice.topicName()).thenReturn(resourceId.toString());
adapter.uploadMessage(newMqttContext(messageFromDevice, endpoint, span), resourceId, messageFromDevice).onFailure(ctx::failNow);
resourceId = ResourceIdentifier.from("e", "my-tenant", "4712");
when(messageFromDevice.topicName()).thenReturn(resourceId.toString());
adapter.uploadMessage(newMqttContext(messageFromDevice, endpoint, span), resourceId, messageFromDevice).onFailure(ctx::failNow);
resourceId = ResourceIdentifier.from("unknown", "my-tenant", "4712");
when(messageFromDevice.topicName()).thenReturn(resourceId.toString());
adapter.uploadMessage(newMqttContext(messageFromDevice, endpoint, span), resourceId, messageFromDevice).onComplete(ctx.failing(t -> {
ctx.verify(() -> assertThat(t).isInstanceOf(ClientErrorException.class));
}));
ctx.completeNow();
}
use of org.eclipse.hono.auth.Device in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testDeviceConnectionIsClosedOnDeviceDisabledNotification.
/**
* Verifies that the adapter closes the connection to an authenticated device when a notification
* has been received that the device has been disabled.
*
* @param ctx The vert.x test context.
*/
@Test
public void testDeviceConnectionIsClosedOnDeviceDisabledNotification(final VertxTestContext ctx) {
final Device device = new Device("tenant", "deviceId");
testDeviceConnectionIsClosedOnDeviceOrTenantChangeNotification(ctx, device, new DeviceChangeNotification(LifecycleChange.UPDATE, "tenant", "deviceId", Instant.now(), false));
}
Aggregations