Search in sources :

Example 1 with IdentityAsserterHttpServletRequestWrapper

use of org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper in project knox by apache.

the class IdentityAssertionHttpServletRequestWrapperTest method testParameterWithNullValueInQueryString.

@Test
public void testParameterWithNullValueInQueryString() {
    String input = "paramWithNullValue&param2=abc";
    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, containsString("paramWithNullValue"));
    assertThat(output, containsString("param2=abc"));
}
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 2 with IdentityAsserterHttpServletRequestWrapper

use of org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper in project knox by apache.

the class IdentityAssertionHttpServletRequestWrapperTest method testInsertUserNameInPostMethodWithoutEncoding.

@Test
public void testInsertUserNameInPostMethodWithoutEncoding() throws IOException {
    String inputBody = "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.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"));
}
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 3 with IdentityAsserterHttpServletRequestWrapper

use of org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper in project knox by apache.

the class IdentityAssertionHttpServletRequestWrapperTest method testInsertUserNameInQueryString.

@Test
public void testInsertUserNameInQueryString() {
    String input = "param=value";
    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)

Example 4 with IdentityAsserterHttpServletRequestWrapper

use of org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper in project knox by apache.

the class IdentityAssertionHttpServletRequestWrapperTest method testInsertUserNameInPostMethod.

@Test
public void testInsertUserNameInPostMethod() throws IOException {
    String inputBody = "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"));
}
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 5 with IdentityAsserterHttpServletRequestWrapper

use of org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper in project knox by apache.

the class IdentityAssertionHttpServletRequestWrapperTest method testInsertDoAsInQueryString.

@Test
public void testInsertDoAsInQueryString() {
    System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "true");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setQueryString("op=LISTSTATUS&user.name=jack&User.Name=jill&DOas=admin&doas=root");
    IdentityAsserterHttpServletRequestWrapper wrapper = new IdentityAsserterHttpServletRequestWrapper(request, "output-user");
    String output = wrapper.getQueryString();
    assertThat(output, is("op=LISTSTATUS&doAs=output-user"));
}
Also used : MockHttpServletRequest(org.apache.knox.test.mock.MockHttpServletRequest) IdentityAsserterHttpServletRequestWrapper(org.apache.knox.gateway.identityasserter.common.filter.IdentityAsserterHttpServletRequestWrapper) Matchers.containsString(org.hamcrest.Matchers.containsString) 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