use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class AbstractPluginUnitTest method shouldRaiseAlertWith13ParamsBingoDefaultingToMessageUriWhenGivenUriIsEmpty.
@Test
@SuppressWarnings("deprecation")
void shouldRaiseAlertWith13ParamsBingoDefaultingToMessageUriWhenGivenUriIsEmpty() {
// Given
AbstractPlugin plugin = createDefaultPlugin();
HostProcess hostProcess = mock(HostProcess.class);
plugin.init(mock(HttpMessage.class), hostProcess);
String uri = "";
String messageUri = "http://example.com/";
HttpMessage alertMessage = createAlertMessage(messageUri);
// When
plugin.bingo(Alert.RISK_LOW, Alert.CONFIDENCE_HIGH, "", "", uri, "", "", "", "", "", 0, 0, alertMessage);
// Then
Alert alert = getRaisedAlert(hostProcess);
assertThat(alert.getUri(), is(equalTo(messageUri)));
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class ProxyThreadUnitTest method createMessage.
private static HttpMessage createMessage(HttpResponseHeader header, HttpResponseBody body) {
HttpMessage message = mock(HttpMessage.class);
given(message.getResponseHeader()).willReturn(header);
given(message.getResponseBody()).willReturn(body);
return message;
}
use of org.parosproxy.paros.network.HttpMessage 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.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantAbstractQueryUnitTest method shouldNotCallGetEscapedValueForInjectedValueIfEscapedWhenSettingParameter.
@Test
void shouldNotCallGetEscapedValueForInjectedValueIfEscapedWhenSettingParameter() {
// Given
List<String> values = new ArrayList<>();
VariantAbstractQuery variantAbstractQuery = new VariantAbstractQueryImpl() {
@Override
protected String getEscapedValue(HttpMessage msg, String value) {
values.add(value);
return value;
}
};
List<org.zaproxy.zap.model.NameValuePair> parameters = parameters(parameter("a", "b"), parameter("c", "d"), parameter("e", "f"));
variantAbstractQuery.setParameters(NAME_VALUE_PAIR_TYPE, parameters);
HttpMessage message = createMessage();
// When
variantAbstractQuery.setEscapedParameter(message, param("a", "b", 0), "y", "escaped");
// Then
assertThat(values, contains("d", "f"));
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantAbstractQueryUnitTest method shouldCallGetEscapedNameForEachNameWhenSettingParameter.
@Test
void shouldCallGetEscapedNameForEachNameWhenSettingParameter() {
// Given
List<String> names = new ArrayList<>();
VariantAbstractQuery variantAbstractQuery = new VariantAbstractQueryImpl() {
@Override
protected String getEscapedName(HttpMessage msg, String name) {
names.add(name);
return name;
}
};
List<org.zaproxy.zap.model.NameValuePair> parameters = parameters(parameter("a", "b"), parameter("c", "d"), parameter("e", "f"));
variantAbstractQuery.setParameters(NAME_VALUE_PAIR_TYPE, parameters);
HttpMessage message = createMessage();
// When
variantAbstractQuery.setParameter(message, param("a", "b", 0), "y", "z");
// Then
assertThat(names, contains("y", "c", "e"));
}
Aggregations