You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2011/05/05 22:59:16 UTC
svn commit: r1099966 - in /shiro/trunk/web/src:
main/java/org/apache/shiro/web/servlet/IniShiroFilter.java
test/groovy/org/apache/shiro/web/servlet/IniShiroFilterTest.groovy
Author: lhazlewood
Date: Thu May 5 20:59:16 2011
New Revision: 1099966
URL: http://svn.apache.org/viewvc?rev=1099966&view=rev
Log:
SHIRO-288 - removed the call to WebUtils.normalize - the value specified is done by a developer configuring Shiro, not an application end user - if the url the dev specifies is invalid, startup will fail fast showing what went wrong - no need to 'sanitize' developer configuration input in this case. Added test cases for verification.
Modified:
shiro/trunk/web/src/main/java/org/apache/shiro/web/servlet/IniShiroFilter.java
shiro/trunk/web/src/test/groovy/org/apache/shiro/web/servlet/IniShiroFilterTest.groovy
Modified: shiro/trunk/web/src/main/java/org/apache/shiro/web/servlet/IniShiroFilter.java
URL: http://svn.apache.org/viewvc/shiro/trunk/web/src/main/java/org/apache/shiro/web/servlet/IniShiroFilter.java?rev=1099966&r1=1099965&r2=1099966&view=diff
==============================================================================
--- shiro/trunk/web/src/main/java/org/apache/shiro/web/servlet/IniShiroFilter.java (original)
+++ shiro/trunk/web/src/main/java/org/apache/shiro/web/servlet/IniShiroFilter.java Thu May 5 20:59:16 2011
@@ -174,11 +174,7 @@ public class IniShiroFilter extends Abst
* not specified via the {@link #getConfig() config} attribute.
*/
public void setConfigPath(String configPath) {
- String path = StringUtils.clean(configPath);
- if (path != null) {
- path = WebUtils.normalize(path);
- }
- this.configPath = path;
+ this.configPath = StringUtils.clean(configPath);
}
public void init() throws Exception {
Modified: shiro/trunk/web/src/test/groovy/org/apache/shiro/web/servlet/IniShiroFilterTest.groovy
URL: http://svn.apache.org/viewvc/shiro/trunk/web/src/test/groovy/org/apache/shiro/web/servlet/IniShiroFilterTest.groovy?rev=1099966&r1=1099965&r2=1099966&view=diff
==============================================================================
--- shiro/trunk/web/src/test/groovy/org/apache/shiro/web/servlet/IniShiroFilterTest.groovy (original)
+++ shiro/trunk/web/src/test/groovy/org/apache/shiro/web/servlet/IniShiroFilterTest.groovy Thu May 5 20:59:16 2011
@@ -2,6 +2,7 @@ package org.apache.shiro.web.servlet
import javax.servlet.FilterConfig
import javax.servlet.ServletContext
+import javax.servlet.ServletException
import org.apache.shiro.io.ResourceUtils
import static org.easymock.EasyMock.*
@@ -11,15 +12,34 @@ import static org.easymock.EasyMock.*
class IniShiroFilterTest extends GroovyTestCase {
void testDefaultWebInfConfig() {
- def filterConfig = createStrictMock(FilterConfig)
+ def filterConfig = createMock(FilterConfig)
def servletContext = createStrictMock(ServletContext)
- def inputStream = ResourceUtils.getResourceAsStream("classpath:IniShiroFilterTest.ini")
+ InputStream inputStream = ResourceUtils.getInputStreamForPath("classpath:IniShiroFilterTest.ini")
+ assertNotNull inputStream
- expect(filterConfig.getServletContext()).andReturn servletContext
+ expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes()
expect(filterConfig.getInitParameter(eq(AbstractShiroFilter.STATIC_INIT_PARAM_NAME))).andReturn null
- expect(filterConfig.getInitParameter(IniShiroFilter.CONFIG_INIT_PARAM_NAME)).andReturn null
- expect(filterConfig.getInitParameter(IniShiroFilter.CONFIG_PATH_INIT_PARAM_NAME)).andReturn null
- expect(servletContext.getResourceAsStream(IniShiroFilter.DEFAULT_WEB_INI_RESOURCE_PATH)).andReturn inputStream
+ expect(filterConfig.getInitParameter(eq(IniShiroFilter.CONFIG_INIT_PARAM_NAME))).andReturn null
+ expect(filterConfig.getInitParameter(eq(IniShiroFilter.CONFIG_PATH_INIT_PARAM_NAME))).andReturn null
+ //simulate the servlet context resource of /WEB-INF/shiro.ini to be our test file above:
+ expect(servletContext.getResourceAsStream(eq(IniShiroFilter.DEFAULT_WEB_INI_RESOURCE_PATH))).andReturn(inputStream)
+
+ replay filterConfig, servletContext
+
+ IniShiroFilter filter = new IniShiroFilter()
+ filter.init(filterConfig)
+
+ verify filterConfig, servletContext
+ }
+
+ void testResourceConfig() {
+ def filterConfig = createMock(FilterConfig)
+ def servletContext = createStrictMock(ServletContext)
+
+ expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes()
+ expect(filterConfig.getInitParameter(eq(AbstractShiroFilter.STATIC_INIT_PARAM_NAME))).andReturn null
+ expect(filterConfig.getInitParameter(eq(IniShiroFilter.CONFIG_INIT_PARAM_NAME))).andReturn null
+ expect(filterConfig.getInitParameter(eq(IniShiroFilter.CONFIG_PATH_INIT_PARAM_NAME))).andReturn "classpath:IniShiroFilterTest.ini"
replay filterConfig, servletContext
@@ -29,6 +49,29 @@ class IniShiroFilterTest extends GroovyT
verify filterConfig, servletContext
}
+ void testResourceConfigWithoutResource() {
+ def filterConfig = createMock(FilterConfig)
+ def servletContext = createStrictMock(ServletContext)
+ def nonExistentResource = "/WEB-INF/foo.ini"
+
+ expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes()
+ expect(filterConfig.getInitParameter(eq(AbstractShiroFilter.STATIC_INIT_PARAM_NAME))).andReturn null
+ expect(filterConfig.getInitParameter(eq(IniShiroFilter.CONFIG_INIT_PARAM_NAME))).andReturn null
+ expect(filterConfig.getInitParameter(eq(IniShiroFilter.CONFIG_PATH_INIT_PARAM_NAME))).andReturn nonExistentResource
+ expect(servletContext.getResourceAsStream(eq(nonExistentResource))).andReturn(null)
+
+ replay filterConfig, servletContext
+
+ IniShiroFilter filter = new IniShiroFilter()
+ try {
+ filter.init(filterConfig)
+ fail "Filter init should have failed due to specified nonexisting resource path."
+ } catch (ServletException expected) {
+ }
+
+ verify filterConfig, servletContext
+ }
+
void testDefaultClasspathConfig() {
def filterConfig = createStrictMock(FilterConfig)