Search in sources :

Example 1 with HttpHeaders

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

the class SpelTemplateEngineTest method shouldTransformJsonContent.

@Test
public void shouldTransformJsonContent() {
    final HttpHeaders headers = new HttpHeaders();
    headers.setAll(new HashMap<String, String>() {

        {
            put("X-Gravitee-Endpoint", "my_api_host");
        }
    });
    when(request.headers()).thenReturn(headers);
    when(request.path()).thenReturn("/stores/123");
    final Map<String, Object> properties = new HashMap<>();
    properties.put("name_123", "Doe");
    properties.put("firstname_123", "John");
    SpelTemplateEngine engine = new SpelTemplateEngine();
    engine.getTemplateContext().setVariable("request", new EvaluableRequest(request));
    engine.getTemplateContext().setVariable("properties", properties);
    String content = "[{id: {#request.paths[2]}, firstname: {#properties['firstname_123']}, name: {#properties['name_123']}, age: 0}]";
    String value = engine.convert(content);
    Assert.assertNotNull(value);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with HttpHeaders

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

the class SpelTemplateEngineTest method shouldTransformWithRequestHeader.

@Test
public void shouldTransformWithRequestHeader() {
    final HttpHeaders headers = new HttpHeaders();
    headers.setAll(new HashMap<String, String>() {

        {
            put("X-Gravitee-Endpoint", "my_api_host");
        }
    });
    when(request.headers()).thenReturn(headers);
    when(request.path()).thenReturn("/stores/99/products/123456");
    SpelTemplateEngine engine = new SpelTemplateEngine();
    engine.getTemplateContext().setVariable("request", new EvaluableRequest(request));
    String value = engine.convert("{#request.headers['X-Gravitee-Endpoint']}");
    Assert.assertEquals("my_api_host", value);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Test(org.junit.Test)

Example 3 with HttpHeaders

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

the class SpelTemplateEngineTest method shouldTransformWithProperties.

@Test
public void shouldTransformWithProperties() {
    final HttpHeaders headers = new HttpHeaders();
    headers.setAll(new HashMap<String, String>() {

        {
            put("X-Gravitee-Endpoint", "my_api_host");
        }
    });
    when(request.headers()).thenReturn(headers);
    when(request.path()).thenReturn("/stores/123");
    final Map<String, Object> properties = new HashMap<>();
    properties.put("name_123", "Doe");
    properties.put("firstname_123", "John");
    SpelTemplateEngine engine = new SpelTemplateEngine();
    engine.getTemplateContext().setVariable("request", new EvaluableRequest(request));
    engine.getTemplateContext().setVariable("properties", properties);
    String value = engine.convert("<user><id>{#request.paths[2]}</id><name>{#properties['name_123']}</name><firstname>{#properties['firstname_' + #request.paths[2]]}</firstname></user>");
    Assert.assertNotNull(value);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with HttpHeaders

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

the class OAuth2AuthenticationHandlerTest method shouldNotHandleRequest_noBearerAuthorizationHeader.

@Test
public void shouldNotHandleRequest_noBearerAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    Request request = mock(Request.class);
    when(request.headers()).thenReturn(headers);
    headers.add(HttpHeaders.AUTHORIZATION, "Basic xxx-xx-xxx-xx-xx");
    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 5 with HttpHeaders

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

the class JWTAuthenticationHandlerTest 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)

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