Search in sources :

Example 16 with HttpHeaders

use of io.gravitee.common.http.HttpHeaders in project gravitee-gateway by gravitee-io.

the class JWTAuthenticationHandlerTest method shouldNotHandleRequest_noAuthorizationHeader.

@Test
public void shouldNotHandleRequest_noAuthorizationHeader() {
    Request request = mock(Request.class);
    when(request.headers()).thenReturn(new HttpHeaders());
    boolean handle = authenticationHandler.canHandle(request);
    Assert.assertFalse(handle);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 17 with HttpHeaders

use of io.gravitee.common.http.HttpHeaders in project gravitee-gateway by gravitee-io.

the class OAuth2AuthenticationHandlerTest method shouldHandleRequest_ignoreCaseAuthorizationHeader.

@Test
public void shouldHandleRequest_ignoreCaseAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    Request request = mock(Request.class);
    when(request.headers()).thenReturn(headers);
    headers.add(HttpHeaders.AUTHORIZATION, "BeaRer xxx-xx-xxx-xx-xx");
    boolean handle = authenticationHandler.canHandle(request);
    Assert.assertTrue(handle);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 18 with HttpHeaders

use of io.gravitee.common.http.HttpHeaders in project gravitee-gateway by gravitee-io.

the class OAuth2AuthenticationHandlerTest method shouldNotHandleRequest_noBearerValue.

@Test
public void shouldNotHandleRequest_noBearerValue() {
    HttpHeaders headers = new HttpHeaders();
    Request request = mock(Request.class);
    when(request.headers()).thenReturn(headers);
    headers.add(HttpHeaders.AUTHORIZATION, OAuth2AuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " ");
    boolean handle = authenticationHandler.canHandle(request);
    Assert.assertFalse(handle);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 19 with HttpHeaders

use of io.gravitee.common.http.HttpHeaders in project gravitee-gateway by gravitee-io.

the class OAuth2AuthenticationHandlerTest method shouldNotHandleRequest_noAuthorizationHeader.

@Test
public void shouldNotHandleRequest_noAuthorizationHeader() {
    Request request = mock(Request.class);
    when(request.headers()).thenReturn(new HttpHeaders());
    boolean handle = authenticationHandler.canHandle(request);
    Assert.assertFalse(handle);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 20 with HttpHeaders

use of io.gravitee.common.http.HttpHeaders in project gravitee-gateway by gravitee-io.

the class ReactorTest method processRequest_startedApi.

@Test
public void processRequest_startedApi() throws Exception {
    Request request = mock(Request.class);
    when(request.method()).thenReturn(HttpMethod.GET);
    when(request.headers()).thenReturn(new HttpHeaders());
    when(request.headers()).thenReturn(new HttpHeaders());
    when(request.path()).thenReturn("/team");
    when(request.metrics()).thenReturn(Metrics.on(System.currentTimeMillis()).build());
    when(handlerResolver.resolve(any(Request.class))).thenReturn(new AbstractReactorHandler() {

        @Override
        public Reactable reactable() {
            return new Reactable() {

                @Override
                public Object item() {
                    return null;
                }

                @Override
                public String contextPath() {
                    return "";
                }

                @Override
                public boolean enabled() {
                    return true;
                }

                @Override
                public Set dependencies(Class type) {
                    return null;
                }

                @Override
                public Map<String, Object> properties() {
                    return null;
                }
            };
        }

        @Override
        protected void doHandle(Request request, Response response, Handler<Response> handler) {
            Response proxyResponse = mock(Response.class);
            when(proxyResponse.headers()).thenReturn(new HttpHeaders());
            when(proxyResponse.status()).thenReturn(HttpStatusCode.OK_200);
            handler.handle(proxyResponse);
        }
    });
    final CountDownLatch lock = new CountDownLatch(1);
    Response proxyResponse = mock(Response.class);
    when(proxyResponse.headers()).thenReturn(new HttpHeaders());
    reactor.route(request, proxyResponse, response -> {
        Assert.assertEquals(HttpStatusCode.OK_200, response.status());
        lock.countDown();
    });
    Assert.assertEquals(true, lock.await(10000, TimeUnit.MILLISECONDS));
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Set(java.util.Set) AbstractReactorHandler(io.gravitee.gateway.reactor.handler.AbstractReactorHandler) Request(io.gravitee.gateway.api.Request) CountDownLatch(java.util.concurrent.CountDownLatch) Response(io.gravitee.gateway.api.Response) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HttpHeaders (io.gravitee.common.http.HttpHeaders)24 Test (org.junit.Test)20 Request (io.gravitee.gateway.api.Request)17 LinkedMultiValueMap (io.gravitee.common.util.LinkedMultiValueMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 MultiValueMap (io.gravitee.common.util.MultiValueMap)1 HttpClientSslOptions (io.gravitee.definition.model.HttpClientSslOptions)1 HttpProxy (io.gravitee.definition.model.HttpProxy)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1 Response (io.gravitee.gateway.api.Response)1 AbstractReactorHandler (io.gravitee.gateway.reactor.handler.AbstractReactorHandler)1 EndpointRule (io.gravitee.gateway.services.healthcheck.EndpointRule)1 EndpointStatusDecorator (io.gravitee.gateway.services.healthcheck.EndpointStatusDecorator)1 EvaluationException (io.gravitee.gateway.services.healthcheck.eval.EvaluationException)1 AssertionEvaluation (io.gravitee.gateway.services.healthcheck.eval.assertion.AssertionEvaluation)1 EvaluableHttpResponse (io.gravitee.gateway.services.healthcheck.http.el.EvaluableHttpResponse)1 Request (io.gravitee.reporter.api.common.Request)1 Response (io.gravitee.reporter.api.common.Response)1