-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage and remove code smells
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...re-structure-backend/src/test/java/org/guvnor/structure/backend/InputEscapeUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.guvnor.structure.backend; | ||
|
||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
|
||
import static org.guvnor.structure.backend.InputEscapeUtils.escapeHtmlInput; | ||
|
||
public class InputEscapeUtilsTest { | ||
|
||
@Test | ||
public void testEscapeHtmlInput() { | ||
final String xssString = "<img/src/onerror=alert(\"XSS\")>"; | ||
final String expectedResult = StringEscapeUtils.escapeHtml4(xssString).replace("'", ""); | ||
final String result = escapeHtmlInput(xssString); | ||
Assertions.assertThat(result).isEqualTo(expectedResult); | ||
} | ||
|
||
@Test | ||
public void testEscapeHtmlInputWithSingleQoutes() { | ||
final String xssString = "<img/src/onerror=alert('XSS')>"; | ||
final String expectedResult = StringEscapeUtils.escapeHtml4(xssString).replace("'", ""); | ||
final String result = escapeHtmlInput(xssString); | ||
Assertions.assertThat(result).isEqualTo(expectedResult); | ||
} | ||
|
||
@Test | ||
public void testEscapeHtmlInputNull() { | ||
final String xssString = null; | ||
final String result = escapeHtmlInput(xssString); | ||
Assertions.assertThat(result).isNull(); | ||
} | ||
} |