use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.
the class RequestResponseEndpointTest method testHandleMessageRejectsMalformedMessage.
/**
* Verifies that the endpoint rejects malformed request messages.
*/
@Test
public void testHandleMessageRejectsMalformedMessage() {
Message msg = ProtonHelper.message();
ProtonConnection con = mock(ProtonConnection.class);
ProtonDelivery delivery = mock(ProtonDelivery.class);
RequestResponseEndpoint<ServiceConfigProperties> endpoint = getEndpoint(false);
// WHEN a malformed message is received
endpoint.handleMessage(con, receiver, resource, delivery, msg);
// THEN the link is closed and the message is rejected
ArgumentCaptor<DeliveryState> deliveryState = ArgumentCaptor.forClass(DeliveryState.class);
verify(delivery).disposition(deliveryState.capture(), booleanThat(is(Boolean.TRUE)));
assertThat(deliveryState.getValue(), instanceOf(Rejected.class));
verify(receiver, never()).close();
}
use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.
the class RequestResponseEndpointTest method testHandleMessageProcessesAuthorizedRequests.
/**
* Verifies that the endpoint processes request messages for operations the client
* is authorized to invoke.
*/
@Test
public void testHandleMessageProcessesAuthorizedRequests() {
Message msg = ProtonHelper.message();
msg.setSubject("get");
ProtonConnection con = mock(ProtonConnection.class);
ProtonDelivery delivery = mock(ProtonDelivery.class);
AuthorizationService authService = mock(AuthorizationService.class);
when(authService.isAuthorized(any(HonoUser.class), any(ResourceIdentifier.class), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
Future<Void> processingTracker = Future.future();
RequestResponseEndpoint<ServiceConfigProperties> endpoint = getEndpoint(true, processingTracker);
endpoint.setAuthorizationService(authService);
// WHEN a request for an operation is received that the client is authorized to invoke
endpoint.handleMessage(con, receiver, resource, delivery, msg);
// THEN then the message gets processed
ArgumentCaptor<DeliveryState> deliveryState = ArgumentCaptor.forClass(DeliveryState.class);
verify(delivery).disposition(deliveryState.capture(), booleanThat(is(Boolean.TRUE)));
assertThat(deliveryState.getValue(), instanceOf(Accepted.class));
verify(receiver, never()).close();
verify(authService).isAuthorized(Constants.PRINCIPAL_ANONYMOUS, resource, "get");
assertTrue(processingTracker.isComplete());
}
use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.
the class RequestResponseEndpointTest method testHandleMessageRejectsUnauthorizedRequests.
/**
* Verifies that the endpoint rejects request messages for operations the client
* is not authorized to invoke.
*/
@Test
public void testHandleMessageRejectsUnauthorizedRequests() {
Message msg = ProtonHelper.message();
msg.setSubject("unauthorized");
ProtonConnection con = mock(ProtonConnection.class);
ProtonDelivery delivery = mock(ProtonDelivery.class);
AuthorizationService authService = mock(AuthorizationService.class);
when(authService.isAuthorized(any(HonoUser.class), any(ResourceIdentifier.class), anyString())).thenReturn(Future.succeededFuture(Boolean.FALSE));
Future<Void> processingTracker = Future.future();
RequestResponseEndpoint<ServiceConfigProperties> endpoint = getEndpoint(true, processingTracker);
endpoint.setAuthorizationService(authService);
// WHEN a request for an operation is received that the client is not authorized to invoke
endpoint.handleMessage(con, receiver, resource, delivery, msg);
// THEN the the message is rejected
ArgumentCaptor<DeliveryState> deliveryState = ArgumentCaptor.forClass(DeliveryState.class);
verify(delivery).disposition(deliveryState.capture(), booleanThat(is(Boolean.TRUE)));
assertThat(deliveryState.getValue(), instanceOf(Rejected.class));
verify(receiver, never()).close();
verify(authService).isAuthorized(Constants.PRINCIPAL_ANONYMOUS, resource, "unauthorized");
assertFalse(processingTracker.isComplete());
}
use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.
the class BaseRegistrationServiceTest method testStartupFailsIfNoRegistrationAssertionFactoryIsSet.
/**
* Verifies that the service cannot be started without either <em>signingSecret</em> or
* <em>signingKeyPath</em> being set.
*
* @param ctx The vertx unit test context.
*/
@Test
public void testStartupFailsIfNoRegistrationAssertionFactoryIsSet(final TestContext ctx) {
// GIVEN a registry without an assertion factory being set
final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
// WHEN starting the service
Async startupFailure = ctx.async();
Future<Void> startFuture = Future.future();
startFuture.setHandler(ctx.asyncAssertFailure(t -> startupFailure.complete()));
registrationService.doStart(startFuture);
// THEN startup fails
startupFailure.await();
}
Aggregations