Skip to content

Commit

Permalink
Extract method for CsfrCountermeasuresScanRuleUnitTest
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavocovas committed Sep 8, 2023
1 parent 92667c7 commit 95a09aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion addOns/pscanrules/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- The alerts of the Hash Disclosure scan rule no longer have the evidence duplicated in the Other Info field.

### Fixed
- The Absence of Anti-CSRF Tokens Scan Rule now skips responses that are not HTML (Issue 7890)
- The Absence of Anti-CSRF Tokens Scan Rule now skips responses that are not HTML (Issue 7890).

## [50] - 2023-07-11
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ void shouldReturnExpectedMappings() {
@Test
void shouldNotRaiseAlertIfContentTypeIsNotHTML() {
// Given
HttpMessage msg = new HttpMessage();
msg.getResponseHeader().addHeader(HttpHeader.CONTENT_TYPE, "application/json");
msg.setResponseBody("no html");
msg.getResponseHeader().setHeader(HttpHeader.CONTENT_TYPE, "application/json");
formWithoutAntiCsrfToken();
// When
scanHttpResponseReceive(msg);
// Then
Expand Down Expand Up @@ -158,8 +157,7 @@ void shouldNotRaiseAlertIfFormHasNoParent() {
@Test
void shouldRaiseAlertIfThereIsNoCSRFTokenFound() {
// Given
msg.setResponseBody(
"<html><head></head><body><form id=\"no_csrf_token\"><input type=\"text\"/><input type=\"submit\"/></form></body></html>");
formWithoutAntiCsrfToken();
// When
scanHttpResponseReceive(msg);
// Then
Expand Down Expand Up @@ -432,6 +430,11 @@ void shouldRaiseAlertWhenThresholdLowAndMessageOutOfScope() throws URIException
assertEquals(1, alertsRaised.size());
}

void formWithoutAntiCsrfToken() {
msg.setResponseBody(
"<html><head></head><body><form id=\"no_csrf_token\"><input type=\"text\"/><input type=\"submit\"/></form></body></html>");
}

private HttpMessage createScopedMessage(boolean isInScope) throws URIException {
HttpMessage newMsg =
new HttpMessage() {
Expand Down

0 comments on commit 95a09aa

Please sign in to comment.