Search in sources :

Example 1 with FilterContainer

use of org.apache.hadoop.http.FilterContainer in project hadoop by apache.

the class TestTimelineAuthenticationFilterInitializer method testProxyUserConfiguration.

@Test
public void testProxyUserConfiguration() {
    FilterContainer container = Mockito.mock(FilterContainer.class);
    for (int i = 0; i < 3; ++i) {
        Configuration conf = new YarnConfiguration();
        switch(i) {
            case 0:
                // hadoop.proxyuser prefix
                conf.set("hadoop.proxyuser.foo.hosts", "*");
                conf.set("hadoop.proxyuser.foo.users", "*");
                conf.set("hadoop.proxyuser.foo.groups", "*");
                break;
            case 1:
                // yarn.timeline-service.http-authentication.proxyuser prefix
                conf.set(PREFIX + "proxyuser.foo.hosts", "*");
                conf.set(PREFIX + "proxyuser.foo.users", "*");
                conf.set(PREFIX + "proxyuser.foo.groups", "*");
                break;
            case 2:
                // hadoop.proxyuser prefix has been overwritten by
                // yarn.timeline-service.http-authentication.proxyuser prefix
                conf.set("hadoop.proxyuser.foo.hosts", "bar");
                conf.set("hadoop.proxyuser.foo.users", "bar");
                conf.set("hadoop.proxyuser.foo.groups", "bar");
                conf.set(PREFIX + "proxyuser.foo.hosts", "*");
                conf.set(PREFIX + "proxyuser.foo.users", "*");
                conf.set(PREFIX + "proxyuser.foo.groups", "*");
                break;
            default:
                break;
        }
        TimelineAuthenticationFilterInitializer initializer = new TimelineAuthenticationFilterInitializer();
        initializer.initFilter(container, conf);
        Assert.assertEquals("*", initializer.filterConfig.get("proxyuser.foo.hosts"));
        Assert.assertEquals("*", initializer.filterConfig.get("proxyuser.foo.users"));
        Assert.assertEquals("*", initializer.filterConfig.get("proxyuser.foo.groups"));
    }
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) FilterContainer(org.apache.hadoop.http.FilterContainer) Test(org.junit.Test)

Example 2 with FilterContainer

use of org.apache.hadoop.http.FilterContainer in project hadoop by apache.

the class TestAuthenticationFilter method testConfiguration.

@SuppressWarnings("unchecked")
public void testConfiguration() throws Exception {
    Configuration conf = new Configuration();
    conf.set("hadoop.http.authentication.foo", "bar");
    conf.set(HttpServer2.BIND_ADDRESS, "barhost");
    FilterContainer container = Mockito.mock(FilterContainer.class);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            assertEquals("authentication", args[0]);
            Map<String, String> conf = (Map<String, String>) args[2];
            assertEquals("/", conf.get("cookie.path"));
            assertEquals("simple", conf.get("type"));
            assertEquals("36000", conf.get("token.validity"));
            assertNull(conf.get("cookie.domain"));
            assertEquals("true", conf.get("simple.anonymous.allowed"));
            assertEquals("HTTP/barhost@LOCALHOST", conf.get("kerberos.principal"));
            assertEquals(System.getProperty("user.home") + "/hadoop.keytab", conf.get("kerberos.keytab"));
            assertEquals("bar", conf.get("foo"));
            return null;
        }
    }).when(container).addFilter(Mockito.<String>anyObject(), Mockito.<String>anyObject(), Mockito.<Map<String, String>>anyObject());
    new AuthenticationFilterInitializer().initFilter(container, conf);
}
Also used : Answer(org.mockito.stubbing.Answer) Configuration(org.apache.hadoop.conf.Configuration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FilterContainer(org.apache.hadoop.http.FilterContainer) Map(java.util.Map)

Example 3 with FilterContainer

use of org.apache.hadoop.http.FilterContainer in project hadoop by apache.

the class TestAuthenticationWithProxyUserFilter method testConfiguration.

@SuppressWarnings("unchecked")
public void testConfiguration() throws Exception {
    Configuration conf = new Configuration();
    conf.set("hadoop.http.authentication.foo", "bar");
    conf.set(HttpServer2.BIND_ADDRESS, "barhost");
    FilterContainer container = Mockito.mock(FilterContainer.class);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            assertEquals("authentication", args[0]);
            assertEquals(AuthenticationWithProxyUserFilter.class.getName(), args[1]);
            Map<String, String> conf = (Map<String, String>) args[2];
            assertEquals("/", conf.get("cookie.path"));
            assertEquals("simple", conf.get("type"));
            assertEquals("36000", conf.get("token.validity"));
            assertNull(conf.get("cookie.domain"));
            assertEquals("true", conf.get("simple.anonymous.allowed"));
            assertEquals("HTTP/barhost@LOCALHOST", conf.get("kerberos.principal"));
            assertEquals(System.getProperty("user.home") + "/hadoop.keytab", conf.get("kerberos.keytab"));
            assertEquals("bar", conf.get("foo"));
            return null;
        }
    }).when(container).addFilter(Mockito.<String>anyObject(), Mockito.<String>anyObject(), Mockito.<Map<String, String>>anyObject());
    new AuthenticationFilterInitializer().initFilter(container, conf);
}
Also used : Answer(org.mockito.stubbing.Answer) Configuration(org.apache.hadoop.conf.Configuration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FilterContainer(org.apache.hadoop.http.FilterContainer) Map(java.util.Map)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)3 FilterContainer (org.apache.hadoop.http.FilterContainer)3 Map (java.util.Map)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 Test (org.junit.Test)1