jayendrap commented on code in PR #335: URL: https://github.com/apache/atlas/pull/335#discussion_r2055374606
########## webapp/src/test/java/org/apache/atlas/web/servlets/AtlasHttpServletTest.java: ########## @@ -0,0 +1,152 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.web.servlets; + +import org.apache.atlas.ApplicationProperties; +import org.apache.atlas.web.filters.HeadersUtil; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationConverter; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.testng.AssertJUnit.assertTrue; + +public class AtlasHttpServletTest { + private AtlasHttpServlet servlet; + + private Map<String, String> originalHeaders; + + @Before + public void beforeSetUp() throws NoSuchFieldException, IllegalAccessException { + servlet = new AtlasHttpServlet(); + + Field headerMapField = HeadersUtil.class.getDeclaredField("HEADER_MAP"); + headerMapField.setAccessible(true); + originalHeaders = new HashMap<>((Map<String, String>) headerMapField.get(null)); + + Map<String, String> headerMap = (Map<String, String>) headerMapField.get(null); + headerMap.clear(); + } + + @After + public void cleanUp() throws IllegalAccessException, NoSuchFieldException { + Field headerMapField = HeadersUtil.class.getDeclaredField("HEADER_MAP"); + headerMapField.setAccessible(true); + Map<String, String> headerMap = (Map<String, String>) headerMapField.get(null); + headerMap.clear(); + headerMap.putAll(originalHeaders); + } + + @Test + public void loadsConfiguration() { Review Comment: Consider renaming loadsConfiguration => testLoadConfiguration ########## webapp/src/main/java/org/apache/atlas/web/servlets/AtlasHttpServlet.java: ########## @@ -17,34 +17,69 @@ */ package org.apache.atlas.web.servlets; +import org.apache.atlas.ApplicationProperties; +import org.apache.atlas.web.filters.AtlasResponseRequestWrapper; +import org.apache.atlas.web.filters.HeadersUtil; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; +import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.Optional; +import java.util.Properties; + public class AtlasHttpServlet extends HttpServlet { public static final Logger LOG = LoggerFactory.getLogger(AtlasHttpServlet.class); - public static final String TEXT_HTML = "text/html"; - public static final String XFRAME_OPTION = "X-Frame-Options"; - public static final String DENY = "DENY"; - public static final String ALLOW = "ALLOW"; + public static final String TEXT_HTML = "text/html"; + public static final String HEADER_CONFIG_KEY = "atlas.headers"; + public static final String ALLOW = "ALLOW"; + + private Configuration configuration; + private Properties headerProperties; Review Comment: Consider moving this to `HeaderUtils`. We have similar properties in `AtlasAuthenticationFilter`, so moving this to a central location will help duplicating the code related to header properties -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@atlas.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org