001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.http.lib; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNull; 022import static org.mockito.ArgumentMatchers.any; 023 024import java.util.Map; 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.hbase.http.FilterContainer; 027import org.apache.hadoop.hbase.http.HttpServer; 028import org.apache.hadoop.hbase.testclassification.MiscTests; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.apache.hadoop.security.authentication.server.AuthenticationFilter; 031import org.junit.jupiter.api.Tag; 032import org.junit.jupiter.api.Test; 033import org.mockito.Mockito; 034import org.mockito.invocation.InvocationOnMock; 035import org.mockito.stubbing.Answer; 036 037@Tag(MiscTests.TAG) 038@Tag(SmallTests.TAG) 039public class TestAuthenticationFilterInitializer { 040 041 @Test 042 public void testConfiguration() throws Exception { 043 Configuration conf = new Configuration(); 044 conf.set("hadoop.http.authentication.foo", "bar"); 045 046 conf.set(HttpServer.BIND_ADDRESS, "barhost"); 047 048 FilterContainer container = Mockito.mock(FilterContainer.class); 049 Mockito.doAnswer(new Answer() { 050 @Override 051 public Object answer(InvocationOnMock invocationOnMock) throws Throwable { 052 Object[] args = invocationOnMock.getArguments(); 053 054 assertEquals("authentication", args[0]); 055 056 assertEquals(AuthenticationFilter.class.getName(), args[1]); 057 058 Map<String, String> conf = (Map<String, String>) args[2]; 059 assertEquals("/", conf.get("cookie.path")); 060 061 assertEquals("simple", conf.get("type")); 062 assertEquals("36000", conf.get("token.validity")); 063 assertNull(conf.get("cookie.domain")); 064 assertEquals("true", conf.get("simple.anonymous.allowed")); 065 assertEquals("HTTP/barhost@LOCALHOST", conf.get("kerberos.principal")); 066 assertEquals(System.getProperty("user.home") + "/hadoop.keytab", 067 conf.get("kerberos.keytab")); 068 assertEquals("bar", conf.get("foo")); 069 070 return null; 071 } 072 }).when(container).addFilter(any(), any(), any()); 073 074 new AuthenticationFilterInitializer().initFilter(container, conf); 075 } 076 077}