BAEL-6848: Set a Parameter in a HttpServletRequest in Java
This commit is contained in:
parent
8c54cce5d1
commit
6cb7a375cc
@ -12,7 +12,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
|||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class LanguageServletIntegrationTest {
|
public class LanguageServletLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenGetRequestUsingHttpClient_thenResponseBodyContainsDefaultLanguage() throws Exception {
|
public void whenGetRequestUsingHttpClient_thenResponseBodyContainsDefaultLanguage() throws Exception {
|
@ -14,7 +14,7 @@ import org.apache.http.util.EntityUtils;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SanitizeParametersRequestIntegrationTest {
|
public class SanitizeParametersRequestLiveTest {
|
||||||
|
|
||||||
private static String PARAM_INPUT;
|
private static String PARAM_INPUT;
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
package com.baeldung.setparam;
|
package com.baeldung.setparam;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -18,7 +18,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SanitizeParametersRequestWrapperUnitTest {
|
public class SanitizeParametersRequestWrapperUnitTest {
|
||||||
|
|
||||||
private String NEW_VALUE = "NEW VALUE";
|
private static final String NEW_VALUE = "NEW VALUE";
|
||||||
|
|
||||||
private Map<String, String[]> parameterMap;
|
private Map<String, String[]> parameterMap;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public class SanitizeParametersRequestWrapperUnitTest {
|
|||||||
SanitizeParametersRequestWrapper wrapper = new SanitizeParametersRequestWrapper(request);
|
SanitizeParametersRequestWrapper wrapper = new SanitizeParametersRequestWrapper(request);
|
||||||
String actualValue = wrapper.getParameter("input");
|
String actualValue = wrapper.getParameter("input");
|
||||||
|
|
||||||
assertEquals(actualValue, "<script>alert('Hello');</script>");
|
assertEquals("<script>alert('Hello');</script>", actualValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
@ -54,7 +54,7 @@ public class SanitizeParametersRequestWrapperUnitTest {
|
|||||||
|
|
||||||
firstCallValues[0] = NEW_VALUE;
|
firstCallValues[0] = NEW_VALUE;
|
||||||
String[] secondCallValues = wrapper.getParameterValues("input");
|
String[] secondCallValues = wrapper.getParameterValues("input");
|
||||||
assertNotEquals(firstCallValues, secondCallValues);
|
assertThat(secondCallValues).doesNotContain(NEW_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.baeldung.setparam;
|
package com.baeldung.setparam;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -18,7 +18,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SetParameterRequestWrapperUnitTest {
|
public class SetParameterRequestWrapperUnitTest {
|
||||||
|
|
||||||
private String NEW_VALUE = "NEW VALUE";
|
private static final String NEW_VALUE = "NEW VALUE";
|
||||||
|
|
||||||
private Map<String, String[]> parameterMap;
|
private Map<String, String[]> parameterMap;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public class SetParameterRequestWrapperUnitTest {
|
|||||||
wrapper.setParameter("newInput", "newInputValue");
|
wrapper.setParameter("newInput", "newInputValue");
|
||||||
String actualValue = wrapper.getParameter("newInput");
|
String actualValue = wrapper.getParameter("newInput");
|
||||||
|
|
||||||
assertEquals(actualValue, "newInputValue");
|
assertEquals("newInputValue", actualValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
@ -55,7 +55,7 @@ public class SetParameterRequestWrapperUnitTest {
|
|||||||
|
|
||||||
firstCallValues[0] = NEW_VALUE;
|
firstCallValues[0] = NEW_VALUE;
|
||||||
String[] secondCallValues = wrapper.getParameterValues("input");
|
String[] secondCallValues = wrapper.getParameterValues("input");
|
||||||
assertNotEquals(firstCallValues, secondCallValues);
|
assertThat(secondCallValues).doesNotContain(NEW_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ import org.apache.http.util.EntityUtils;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class UnsanitizedParametersRequestIntegrationTest {
|
public class UnsanitizedParametersRequestLiveTest {
|
||||||
|
|
||||||
private static final String TAG_SCRIPT = "<script>alert('Hello');</script>";
|
private static final String TAG_SCRIPT = "<script>alert('Hello');</script>";
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user