use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class TransactionHandlerTest method shouldHaveTransactionIdWithCustomHeader.
@Test
public void shouldHaveTransactionIdWithCustomHeader() throws InterruptedException {
final CountDownLatch lock = new CountDownLatch(1);
when(request.id()).thenReturn(UUID.toString(UUID.random()));
new TransactionHandler(CUSTOM_TRANSACTION_ID_HEADER, request1 -> {
assertNotNull(request1.transactionId());
assertEquals(request1.transactionId(), request1.headers().getFirst(CUSTOM_TRANSACTION_ID_HEADER));
assertEquals(request1.transactionId(), request1.metrics().getTransactionId());
assertEquals(request1.transactionId(), response.headers().getFirst(CUSTOM_TRANSACTION_ID_HEADER));
lock.countDown();
}, response).handle(request);
assertEquals(true, lock.await(10000, TimeUnit.MILLISECONDS));
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class TransactionHandlerTest method shouldPropagateSameTransactionId.
@Test
public void shouldPropagateSameTransactionId() throws InterruptedException {
final CountDownLatch lock = new CountDownLatch(1);
String transactionId = UUID.toString(UUID.random());
request.headers().set(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER, transactionId);
new TransactionHandler(request1 -> {
assertNotNull(request1.transactionId());
assertEquals(transactionId, request1.transactionId());
assertEquals(transactionId, request1.headers().getFirst(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER));
assertEquals(transactionId, request1.metrics().getTransactionId());
assertEquals(request1.transactionId(), response.headers().getFirst(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER));
lock.countDown();
}, response).handle(request);
assertEquals(true, lock.await(10000, TimeUnit.MILLISECONDS));
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class ApiKeyAuthenticationHandlerTest method shouldHandleRequestUsingHeaders.
@Test
public void shouldHandleRequestUsingHeaders() {
Request request = mock(Request.class);
HttpHeaders headers = new HttpHeaders();
headers.set("X-Gravitee-Api-Key", "xxxxx-xxxx-xxxxx");
when(request.headers()).thenReturn(headers);
boolean handle = authenticationHandler.canHandle(request);
Assert.assertTrue(handle);
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class ApiKeyAuthenticationHandlerTest method shouldHandleRequestUsingQueryParameters.
@Test
public void shouldHandleRequestUsingQueryParameters() {
Request request = mock(Request.class);
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.put("api-key", Collections.singletonList("xxxxx-xxxx-xxxxx"));
when(request.parameters()).thenReturn(parameters);
HttpHeaders headers = new HttpHeaders();
when(request.headers()).thenReturn(headers);
boolean handle = authenticationHandler.canHandle(request);
Assert.assertTrue(handle);
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class CheckSubscriptionPolicyTest method shouldReturnUnauthorized_badClient.
@Test
public void shouldReturnUnauthorized_badClient() throws PolicyException, TechnicalException {
CheckSubscriptionPolicy policy = new CheckSubscriptionPolicy();
Request request = mock(Request.class);
Response response = mock(Response.class);
PolicyChain policyChain = mock(PolicyChain.class);
ExecutionContext executionContext = mock(ExecutionContext.class);
when(executionContext.getAttribute(CheckSubscriptionPolicy.CONTEXT_ATTRIBUTE_CLIENT_ID)).thenReturn("my-client-id");
SubscriptionRepository subscriptionRepository = mock(SubscriptionRepository.class);
when(executionContext.getComponent(SubscriptionRepository.class)).thenReturn(subscriptionRepository);
Subscription subscription = mock(Subscription.class);
when(subscription.getClientId()).thenReturn("my-bad-client-id");
when(subscriptionRepository.search(any(SubscriptionCriteria.class))).thenReturn(Collections.singletonList(subscription));
policy.onRequest(request, response, policyChain, executionContext);
verify(policyChain, times(1)).failWith(argThat(statusCode(HttpStatusCode.UNAUTHORIZED_401)));
}
Aggregations