use of org.apache.knox.test.mock.MockHttpServletRequest in project knox by apache.
the class IdentityAssertionHttpServletRequestWrapperTest method testOverwriteUserNameInQueryString.
@Test
public void testOverwriteUserNameInQueryString() {
String input = "user.name=input-user";
MockHttpServletRequest request = new MockHttpServletRequest();
request.setQueryString(input);
IdentityAsserterHttpServletRequestWrapper wrapper = new IdentityAsserterHttpServletRequestWrapper(request, "output-user");
String output = wrapper.getQueryString();
assertThat(output, containsString("user.name=output-user"));
assertThat(output, not(containsString("input-user")));
}
use of org.apache.knox.test.mock.MockHttpServletRequest in project knox by apache.
the class IdentityAssertionHttpServletRequestWrapperTest method testOverwriteUserNameInPostMethod.
@Test
public void testOverwriteUserNameInPostMethod() throws IOException {
String inputBody = "user.name=input-user&jar=%2Ftmp%2FGatewayWebHdfsFuncTest%2FtestJavaMapReduceViaWebHCat%2Fhadoop-examples.jar&class=org.apache.org.apache.hadoop.examples.WordCount&arg=%2Ftmp%2FGatewayWebHdfsFuncTest%2FtestJavaMapReduceViaTempleton%2Finput&arg=%2Ftmp%2FGatewayWebHdfsFuncTest%2FtestJavaMapReduceViaTempleton%2Foutput";
MockHttpServletRequest request = new MockHttpServletRequest();
request.setInputStream(new MockServletInputStream(new ByteArrayInputStream(inputBody.getBytes("UTF-8"))));
request.setCharacterEncoding("UTF-8");
request.setContentType("application/x-www-form-urlencoded");
request.setMethod("POST");
IdentityAsserterHttpServletRequestWrapper wrapper = new IdentityAsserterHttpServletRequestWrapper(request, "output-user");
String outputBody = IOUtils.toString(wrapper.getInputStream(), wrapper.getCharacterEncoding());
String output = wrapper.getQueryString();
assertThat(output, containsString("user.name=output-user"));
assertThat(output, not(containsString("input-user")));
}
use of org.apache.knox.test.mock.MockHttpServletRequest in project knox by apache.
the class IdentityAssertionHttpServletRequestWrapperTest method testIngoreNonFormBody.
@Test
public void testIngoreNonFormBody() throws IOException {
String inputBody = "user.name=input-user&jar=%2Ftmp%2FGatewayWebHdfsFuncTest%2FtestJavaMapReduceViaWebHCat%2Fhadoop-examples.jar&class=org.apache.org.apache.hadoop.examples.WordCount&arg=%2Ftmp%2FGatewayWebHdfsFuncTest%2FtestJavaMapReduceViaTempleton%2Finput&arg=%2Ftmp%2FGatewayWebHdfsFuncTest%2FtestJavaMapReduceViaTempleton%2Foutput";
MockHttpServletRequest request = new MockHttpServletRequest();
request.setInputStream(new MockServletInputStream(new ByteArrayInputStream(inputBody.getBytes("UTF-8"))));
request.setCharacterEncoding("UTF-8");
request.setContentType("text/plain");
IdentityAsserterHttpServletRequestWrapper wrapper = new IdentityAsserterHttpServletRequestWrapper(request, "output-user");
String outputBody = IOUtils.toString(wrapper.getInputStream(), wrapper.getCharacterEncoding());
assertThat(outputBody, containsString("user.name=input-user"));
assertThat(outputBody, not(containsString("output-user")));
}
use of org.apache.knox.test.mock.MockHttpServletRequest in project knox by apache.
the class IdentityAssertionHttpServletRequestWrapperTest method testInsertUserNameInQueryStringForPOST.
@Test
public void testInsertUserNameInQueryStringForPOST() {
String input = null;
MockHttpServletRequest request = new MockHttpServletRequest();
request.setQueryString(input);
request.setMethod("POST");
IdentityAsserterHttpServletRequestWrapper wrapper = new IdentityAsserterHttpServletRequestWrapper(request, "output-user");
String output = wrapper.getQueryString();
assertThat(output, containsString("user.name=output-user"));
}
use of org.apache.knox.test.mock.MockHttpServletRequest in project knox by apache.
the class IdentityAssertionHttpServletRequestWrapperTest method testInsertUserNameInNullQueryStringForGET.
@Test
public void testInsertUserNameInNullQueryStringForGET() {
String input = null;
MockHttpServletRequest request = new MockHttpServletRequest();
request.setQueryString(input);
IdentityAsserterHttpServletRequestWrapper wrapper = new IdentityAsserterHttpServletRequestWrapper(request, "output-user");
String output = wrapper.getQueryString();
assertThat(output, containsString("user.name=output-user"));
}
Aggregations