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