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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations