Java Code Examples for io.gravitee.common.http.HttpHeaders#add()

The following examples show how to use io.gravitee.common.http.HttpHeaders#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuth2AuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHandleRequest_invalidAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, "");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertFalse(handle);
}
 
Example 2
Source File: OAuth2AuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHandleRequest_noBearerAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, "Basic xxx-xx-xxx-xx-xx");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertFalse(handle);
}
 
Example 3
Source File: OAuth2AuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleRequest_validAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, OAuth2AuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " xxx-xx-xxx-xx-xx");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertTrue(handle);
}
 
Example 4
Source File: OAuth2AuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleRequest_ignoreCaseAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, "BeaRer xxx-xx-xxx-xx-xx");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertTrue(handle);
}
 
Example 5
Source File: OAuth2AuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHandleRequest_noBearerValue() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, OAuth2AuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " ");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertFalse(handle);
}
 
Example 6
Source File: TokenExtractorTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotExtract_unknownAuthorizationHeader() {
    String jwt = "dummy-token";

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + jwt);
    when(request.headers()).thenReturn(headers);

    String token = TokenExtractor.extract(request);

    Assert.assertNull(token);
}
 
Example 7
Source File: TokenExtractorTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotExtract_bearerAuthorizationHeader_noValue() {
    String jwt = "dummy-token";

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", TokenExtractor.BEARER);
    when(request.headers()).thenReturn(headers);

    String token = TokenExtractor.extract(request);

    Assert.assertNull(token);
}
 
Example 8
Source File: TokenExtractorTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldExtract_fromHeader() {
    String jwt = "dummy-token";

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", TokenExtractor.BEARER + ' ' + jwt);
    when(request.headers()).thenReturn(headers);

    String token = TokenExtractor.extract(request);

    Assert.assertNotNull(token);
    Assert.assertEquals(jwt, token);
}
 
Example 9
Source File: JWTAuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHandleRequest_invalidAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, "");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertFalse(handle);
}
 
Example 10
Source File: JWTAuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHandleRequest_noBearerAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, "Basic xxx-xx-xxx-xx-xx");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertFalse(handle);
    Assert.assertNull(authenticationContext.get(JWTAuthenticationHandler.JWT_CONTEXT_ATTRIBUTE));
}
 
Example 11
Source File: JWTAuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleRequest_validAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, JWTAuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " xxx-xx-xxx-xx-xx");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertTrue(handle);
    Assert.assertNotNull(authenticationContext.get(JWTAuthenticationHandler.JWT_CONTEXT_ATTRIBUTE));
}
 
Example 12
Source File: JWTAuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleRequest_ignoreCaseAuthorizationHeader() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, "BeaRer xxx-xx-xxx-xx-xx");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertTrue(handle);
    Assert.assertNotNull(authenticationContext.get(JWTAuthenticationHandler.JWT_CONTEXT_ATTRIBUTE));
}
 
Example 13
Source File: JWTAuthenticationHandlerTest.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHandleRequest_noBearerValue() {
    HttpHeaders headers = new HttpHeaders();
    when(request.headers()).thenReturn(headers);

    headers.add(HttpHeaders.AUTHORIZATION, JWTAuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " ");

    boolean handle = authenticationHandler.canHandle(authenticationContext);
    Assert.assertFalse(handle);
    Assert.assertNull(authenticationContext.get(JWTAuthenticationHandler.JWT_CONTEXT_ATTRIBUTE));
}
 
Example 14
Source File: LogMapperTest.java    From gravitee-management-rest-api with Apache License 2.0 4 votes vote down vote up
@Test
public void testConvertFull() {
    //init
    ApplicationRequest applicationRequest = new ApplicationRequest();
    applicationRequest.setApi(LOG_API);
    applicationRequest.setHost(LOG_HOST);
    applicationRequest.setId(LOG_APPLICATION);
    
    Map<String, Map<String, String>> metadata = new HashMap<String, Map<String,String>>();
    HashMap<String, String> appMetadata = new HashMap<String, String>();
    appMetadata.put(LOG_API, LOG_API);
    metadata.put(LOG_APPLICATION, appMetadata);
    applicationRequest.setMetadata(metadata);
    
    applicationRequest.setMethod(HttpMethod.CONNECT);
    applicationRequest.setPath(LOG_PATH);
    applicationRequest.setPlan(LOG_PLAN);
    
    Request request = new Request();
    request.setBody(LOG_REQUEST_BODY);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.add(HttpHeaders.ACCEPT, LOG_ID);
    request.setHeaders(requestHeaders);
    request.setMethod(HttpMethod.CONNECT);
    request.setUri(LOG_REQUEST_URI);
    applicationRequest.setRequest(request);
 
    applicationRequest.setRequestContentLength(1L);
    
    Response response = new Response();
    response.setBody(LOG_RESPONSE_BODY);
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add(HttpHeaders.ACCEPT_CHARSET, LOG_ID);
    response.setHeaders(responseHeaders);
    response.setStatus(1);
    applicationRequest.setResponse(response);
    applicationRequest.setResponseContentLength(1L);
    
    applicationRequest.setResponseTime(1);
    
    applicationRequest.setSecurityToken(LOG_SECURITY_TOKEN);
    applicationRequest.setSecurityType(LOG_SECURITY_TYPE);
    applicationRequest.setStatus(1);
    applicationRequest.setTimestamp(1);
    applicationRequest.setTransactionId(LOG_TRANSACTION);
    applicationRequest.setUser(LOG_USER);
    
    //Test
    Log log = logMapper.convert(applicationRequest);
    assertNotNull(log);
    
    assertEquals(LOG_API, log.getApi());
    assertEquals(LOG_HOST, log.getHost());
    assertEquals(LOG_APPLICATION, log.getId());
    
    assertEquals(metadata, log.getMetadata());
    
    assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, log.getMethod());
    assertEquals(LOG_PATH, log.getPath());
    assertEquals(LOG_PLAN, log.getPlan());
    
    final io.gravitee.rest.api.portal.rest.model.Request logRequest = log.getRequest();
    assertNotNull(logRequest);
    assertEquals(LOG_REQUEST_BODY, logRequest.getBody());
    assertEquals(requestHeaders, logRequest.getHeaders());
    assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, logRequest.getMethod());
    assertEquals(LOG_REQUEST_URI, logRequest.getUri());
    
    assertEquals(1L, log.getRequestContentLength().longValue());
    
    final io.gravitee.rest.api.portal.rest.model.Response logResponse = log.getResponse();
    assertNotNull(logResponse);
    assertEquals(LOG_RESPONSE_BODY, logResponse.getBody());
    assertEquals(responseHeaders, logResponse.getHeaders());
    assertEquals(1, logResponse.getStatus().intValue());
    
    assertEquals(1L, log.getResponseContentLength().longValue());
    assertEquals(1L, log.getResponseTime().longValue());
    assertEquals(LOG_SECURITY_TOKEN, log.getSecurityToken());
    assertEquals(LOG_SECURITY_TYPE, log.getSecurityType());
    assertEquals(1, log.getStatus().intValue());
    assertEquals(1L, log.getTimestamp().longValue());
    assertEquals(LOG_TRANSACTION, log.getTransactionId());
    assertEquals(LOG_USER, log.getUser());
    
}