Java Code Examples for io.vertx.core.http.impl.headers.VertxHttpHeaders#add()

The following examples show how to use io.vertx.core.http.impl.headers.VertxHttpHeaders#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: ClientBasicAuthProviderTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAuthenticateClient() throws Exception {
    Client client = mock(Client.class);
    when(client.getClientId()).thenReturn("my-client-id");
    when(client.getClientSecret()).thenReturn("my-client-secret");

    HttpServerRequest httpServerRequest = mock(HttpServerRequest.class);
    VertxHttpHeaders vertxHttpHeaders = new VertxHttpHeaders();
    vertxHttpHeaders.add(HttpHeaders.AUTHORIZATION, "Basic bXktY2xpZW50LWlkOm15LWNsaWVudC1zZWNyZXQ=");
    when(httpServerRequest.headers()).thenReturn(MultiMap.newInstance(vertxHttpHeaders));

    CountDownLatch latch = new CountDownLatch(1);
    authProvider.handle(client, httpServerRequest, clientAsyncResult -> {
        latch.countDown();
        Assert.assertNotNull(clientAsyncResult);
        Assert.assertNotNull(clientAsyncResult.result());
    });

    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
 
Example 2
Source File: ClientBasicAuthProviderTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotAuthenticateClient_badClientSecret() throws Exception {
    Client client = mock(Client.class);
    when(client.getClientId()).thenReturn("my-client-id");
    when(client.getClientSecret()).thenReturn("my-client-secret");

    HttpServerRequest httpServerRequest = mock(HttpServerRequest.class);
    VertxHttpHeaders vertxHttpHeaders = new VertxHttpHeaders();
    vertxHttpHeaders.add(HttpHeaders.AUTHORIZATION, "Basic bXktY2xpZW50LWlkOm15LW90aGVyLWNsaWVudC1zZWNyZXQ=");
    when(httpServerRequest.headers()).thenReturn(MultiMap.newInstance(vertxHttpHeaders));

    CountDownLatch latch = new CountDownLatch(1);
    authProvider.handle(client, httpServerRequest, userAsyncResult -> {
        latch.countDown();
        Assert.assertNotNull(userAsyncResult);
        Assert.assertTrue(userAsyncResult.failed());
        Assert.assertTrue(userAsyncResult.cause() instanceof InvalidClientException);
    });

    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
 
Example 3
Source File: RequestHeaderItemTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void serverFormattedElement() {
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String testValue = "testValue";
  headers.add(VAR_NAME, testValue);
  when(routingContext.request()).thenReturn(serverRequest);
  when(serverRequest.headers()).thenReturn(headers);

  ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
  assertEquals(testValue, strBuilder.toString());
  assertEquals(ELEMENT.getVarName(), VAR_NAME);
}
 
Example 4
Source File: RequestHeaderItemTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void serverFormattedElementIfNotFound() {
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String testValue = "testValue";
  headers.add("anotherKey", testValue);
  when(routingContext.request()).thenReturn(serverRequest);
  when(serverRequest.headers()).thenReturn(headers);

  ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
  assertEquals("-", strBuilder.toString());
}
 
Example 5
Source File: ResponseHeaderItemTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void serverFormattedElement() {
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String headerValue = "headerValue";
  headers.add(VAR_NAME, headerValue);
  when(routingContext.response()).thenReturn(serverResponse);
  when(serverResponse.headers()).thenReturn(headers);

  ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
  assertEquals(headerValue, strBuilder.toString());
  assertEquals(ELEMENT.getVarName(), VAR_NAME);
}
 
Example 6
Source File: ResponseHeaderItemTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void serverFormattedElementOnNotFound() {
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String headerValue = "headerValue";
  headers.add("anotherHeader", headerValue);
  when(routingContext.response()).thenReturn(serverResponse);
  when(serverResponse.headers()).thenReturn(headers);

  ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
  assertEquals("-", strBuilder.toString());
}