Search in sources :

Example 1 with HttpResponseBody

use of org.zaproxy.zap.network.HttpResponseBody in project zaproxy by zaproxy.

the class HttpMessageUnitTest method shouldSetContentEncodingsWhenSettingResponseBodyString.

@Test
void shouldSetContentEncodingsWhenSettingResponseBodyString() {
    // Given
    HttpResponseHeader header = mock(HttpResponseHeader.class);
    given(header.getHeader(HttpHeader.CONTENT_ENCODING)).willReturn(HttpHeader.GZIP);
    HttpResponseBody body = mock(HttpResponseBody.class);
    HttpMessage message = new HttpMessage(mock(HttpRequestHeader.class), mock(HttpRequestBody.class), header, body);
    // When
    message.setResponseBody("Body");
    // Then
    assertThat(encodings(body), is(not(empty())));
}
Also used : HttpRequestBody(org.zaproxy.zap.network.HttpRequestBody) HttpResponseBody(org.zaproxy.zap.network.HttpResponseBody) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HttpResponseBody

use of org.zaproxy.zap.network.HttpResponseBody in project zaproxy by zaproxy.

the class HttpMessageUnitTest method newHttpMessage.

private static HttpMessage newHttpMessage() throws Exception {
    HttpMessage message = new HttpMessage(new HttpRequestHeader("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"), new HttpRequestBody("Request Body"), new HttpResponseHeader("HTTP/1.1 200 OK\r\n"), new HttpResponseBody("Response Body"));
    message.setResponseFromTargetHost(true);
    message.setUserObject(new Object());
    message.setTimeSentMillis(1234L);
    message.setTimeElapsedMillis(50);
    message.setNote("Some Note");
    message.setHistoryRef(mock(HistoryReference.class));
    message.setHttpSession(mock(HttpSession.class));
    message.setRequestingUser(mock(User.class));
    message.setForceIntercept(true);
    message.setResponseFromTargetHost(true);
    return message;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) HttpRequestBody(org.zaproxy.zap.network.HttpRequestBody) User(org.zaproxy.zap.users.User) HttpSession(org.zaproxy.zap.extension.httpsessions.HttpSession) HttpResponseBody(org.zaproxy.zap.network.HttpResponseBody)

Example 3 with HttpResponseBody

use of org.zaproxy.zap.network.HttpResponseBody in project zaproxy by zaproxy.

the class HttpMessageUnitTest method shouldNotSetContentEncodingsWhenSettingHttpResponseBody.

@Test
void shouldNotSetContentEncodingsWhenSettingHttpResponseBody() {
    // Given
    HttpResponseHeader header = mock(HttpResponseHeader.class);
    given(header.getHeader(HttpHeader.CONTENT_ENCODING)).willReturn(HttpHeader.GZIP);
    HttpResponseBody body = mock(HttpResponseBody.class);
    HttpMessage message = new HttpMessage(mock(HttpRequestHeader.class), mock(HttpRequestBody.class), header, body);
    // When
    message.setResponseBody(body);
    // Then
    verify(body, times(0)).setContentEncodings(any());
}
Also used : HttpRequestBody(org.zaproxy.zap.network.HttpRequestBody) HttpResponseBody(org.zaproxy.zap.network.HttpResponseBody) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with HttpResponseBody

use of org.zaproxy.zap.network.HttpResponseBody in project zaproxy by zaproxy.

the class ProxyThreadUnitTest method shouldNotDecodeResponseIfNoContentEncodings.

@Test
void shouldNotDecodeResponseIfNoContentEncodings() {
    // Given
    HttpResponseHeader responseHeader = mock(HttpResponseHeader.class);
    given(responseHeader.getHeader(HttpHeader.CONTENT_LENGTH)).willReturn("1");
    HttpResponseBody responseBody = mock(HttpResponseBody.class);
    given(responseBody.getContentEncodings()).willReturn(Collections.emptyList());
    byte[] content = "ABC".getBytes(StandardCharsets.ISO_8859_1);
    given(responseBody.getContent()).willReturn(content);
    given(responseBody.length()).willReturn(content.length);
    HttpMessage message = createMessage(responseHeader, responseBody);
    // When
    ProxyThread.decodeResponseIfNeeded(message);
    // Then
    verify(responseBody, times(0)).setBody(content);
    verify(responseBody, times(0)).setContentEncodings(Collections.emptyList());
    verify(responseHeader, times(0)).setHeader(HttpHeader.CONTENT_ENCODING, null);
    verify(responseHeader, times(0)).setContentLength(content.length);
}
Also used : HttpResponseHeader(org.parosproxy.paros.network.HttpResponseHeader) HttpResponseBody(org.zaproxy.zap.network.HttpResponseBody) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 5 with HttpResponseBody

use of org.zaproxy.zap.network.HttpResponseBody in project zaproxy by zaproxy.

the class BasicAuthorizationDetectionMethodUnitTest method setUp.

@BeforeEach
void setUp() throws Exception {
    message = Mockito.mock(HttpMessage.class, withSettings().lenient());
    HttpResponseHeader mockedHeader = Mockito.mock(HttpResponseHeader.class, withSettings().lenient());
    HttpResponseBody mockedBody = Mockito.mock(HttpResponseBody.class, withSettings().lenient());
    Mockito.when(message.getResponseHeader()).thenReturn(mockedHeader);
    Mockito.when(message.getResponseBody()).thenReturn(mockedBody);
    Mockito.when(mockedBody.toString()).thenReturn(RESPONSE_BODY);
    Mockito.when(mockedHeader.getStatusCode()).thenReturn(STATUS_CODE);
    Mockito.when(mockedHeader.toString()).thenReturn(RESPONSE_HEADER);
}
Also used : HttpResponseHeader(org.parosproxy.paros.network.HttpResponseHeader) HttpResponseBody(org.zaproxy.zap.network.HttpResponseBody) HttpMessage(org.parosproxy.paros.network.HttpMessage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HttpResponseBody (org.zaproxy.zap.network.HttpResponseBody)11 Test (org.junit.jupiter.api.Test)8 HttpMessage (org.parosproxy.paros.network.HttpMessage)6 HttpResponseHeader (org.parosproxy.paros.network.HttpResponseHeader)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 HttpRequestBody (org.zaproxy.zap.network.HttpRequestBody)4 BeforeEach (org.junit.jupiter.api.BeforeEach)1 HistoryReference (org.parosproxy.paros.model.HistoryReference)1 HttpSession (org.zaproxy.zap.extension.httpsessions.HttpSession)1 User (org.zaproxy.zap.users.User)1