Search in sources :

Example 6 with MockHttpServletRequest

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")));
}
Also used : MockHttpServletRequest(org.apache.knox.test.mock.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityAsserterHttpServletRequestWrapper(org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper) Test(org.junit.Test)

Example 7 with MockHttpServletRequest

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")));
}
Also used : MockServletInputStream(org.apache.knox.test.mock.MockServletInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.apache.knox.test.mock.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityAsserterHttpServletRequestWrapper(org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper) Test(org.junit.Test)

Example 8 with MockHttpServletRequest

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")));
}
Also used : MockServletInputStream(org.apache.knox.test.mock.MockServletInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.apache.knox.test.mock.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityAsserterHttpServletRequestWrapper(org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper) Test(org.junit.Test)

Example 9 with MockHttpServletRequest

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"));
}
Also used : MockHttpServletRequest(org.apache.knox.test.mock.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityAsserterHttpServletRequestWrapper(org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper) Test(org.junit.Test)

Example 10 with MockHttpServletRequest

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"));
}
Also used : MockHttpServletRequest(org.apache.knox.test.mock.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityAsserterHttpServletRequestWrapper(org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper) Test(org.junit.Test)

Aggregations

IdentityAsserterHttpServletRequestWrapper (org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper)12 MockHttpServletRequest (org.apache.knox.test.mock.MockHttpServletRequest)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 Test (org.junit.Test)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 MockServletInputStream (org.apache.knox.test.mock.MockServletInputStream)5