Search in sources :

Example 6 with RequestInfo

use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.

the class BasicAuthSecurityValidatorTest method validateFirstTokenIsNotBasic.

@Test(expected = Unauthorized401Exception.class)
public void validateFirstTokenIsNotBasic() {
    RequestInfo mockRequest = mock(RequestInfo.class);
    doReturn(mock(HttpHeaders.class)).when(mockRequest).getHeaders();
    when(mockRequest.getHeaders().get("Authorization")).thenReturn(calcAuthHeader(USERNAME, PASSWORD).replaceFirst("Basic", "NotBasic"));
    underTest.validateSecureRequestForEndpoint(mockRequest, mockEndpoint1);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 7 with RequestInfo

use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.

the class BasicAuthSecurityValidatorTest method validateMissingPassword.

@Test(expected = Unauthorized401Exception.class)
public void validateMissingPassword() {
    RequestInfo mockRequest = mock(RequestInfo.class);
    doReturn(mock(HttpHeaders.class)).when(mockRequest).getHeaders();
    when(mockRequest.getHeaders().get("Authorization")).thenReturn(calcAuthHeader(USERNAME, null));
    underTest.validateSecureRequestForEndpoint(mockRequest, mockEndpoint1);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 8 with RequestInfo

use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.

the class BasicAuthSecurityValidatorTest method validateMissingColonSeparator.

@Test(expected = Unauthorized401Exception.class)
public void validateMissingColonSeparator() {
    RequestInfo mockRequest = mock(RequestInfo.class);
    doReturn(mock(HttpHeaders.class)).when(mockRequest).getHeaders();
    when(mockRequest.getHeaders().get("Authorization")).thenReturn("Basic " + Base64.encodeBase64String(USERNAME.getBytes()));
    underTest.validateSecureRequestForEndpoint(mockRequest, mockEndpoint1);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 9 with RequestInfo

use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.

the class BasicAuthSecurityValidatorTest method validateMissingUsername.

@Test(expected = Unauthorized401Exception.class)
public void validateMissingUsername() {
    RequestInfo mockRequest = mock(RequestInfo.class);
    doReturn(mock(HttpHeaders.class)).when(mockRequest).getHeaders();
    when(mockRequest.getHeaders().get("Authorization")).thenReturn(calcAuthHeader(null, PASSWORD));
    underTest.validateSecureRequestForEndpoint(mockRequest, mockEndpoint1);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 10 with RequestInfo

use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.

the class AllowAllTheThingsCORSFilterTest method filterRequestLastChunkWithOptionalShortCircuitResponse_always_returns_null.

@DataProvider(value = { "OPTIONS", "GET", "POST", "PUT" }, splitBy = "\\|")
@Test
public void filterRequestLastChunkWithOptionalShortCircuitResponse_always_returns_null(String httpMethodString) {
    // given
    HttpMethod method = HttpMethod.valueOf(httpMethodString);
    doReturn(method).when(requestMock).getMethod();
    // when
    Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestLastChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
    // then
    assertThat(result).isNull();
}
Also used : Optional(java.util.Optional) RequestInfo(com.nike.riposte.server.http.RequestInfo) HttpMethod(io.netty.handler.codec.http.HttpMethod) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

RequestInfo (com.nike.riposte.server.http.RequestInfo)39 Test (org.junit.Test)30 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)13 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)10 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)6 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 Pair (com.nike.internal.util.Pair)5 RequestInfoForLogging (com.nike.backstopper.handler.RequestInfoForLogging)4 Endpoint (com.nike.riposte.server.http.Endpoint)4 HttpMethod (io.netty.handler.codec.http.HttpMethod)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 Optional (java.util.Optional)4 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)3 ChannelAttributes (com.nike.riposte.server.channelpipeline.ChannelAttributes)2 BaseInboundHandlerWithTracingAndMdcSupport (com.nike.riposte.server.handler.base.BaseInboundHandlerWithTracingAndMdcSupport)2 ProxyRouterProcessingState (com.nike.riposte.server.http.ProxyRouterProcessingState)2