1. opensymphony
  2. xwork

Commits

mrdon  committed 4e2d0f8

Adding tests to ensure protected methods and private variables are not accessed by parameters interceptor

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1660e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits fe7cbdb
  • Branches master

Comments (0)

Files changed (2)

File src/test/com/opensymphony/xwork2/SimpleAction.java

View file
 
     private String aliasSource;
     private String aliasDest;
+    private Map<String,String> protectedMap = new HashMap<String,String>();
     
     public static boolean resultCalled;
 
     public SimpleAction() {
         resultCalled = false;
     }
+    
+    public Map<String,String> getTheProtectedMap() {
+        return protectedMap;
+    }
+    
+    protected Map<String,String> getTheSemiProtectedMap() {
+        return protectedMap;
+    }
 
 
     public void setBar(int bar) {

File src/test/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java

View file
         proxy.execute();
         assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
     }
+    
+    public void testParametersNotAccessPrivateVariables() throws Exception {
+        Map params = new HashMap();
+        params.put("protectedMap.foo", "This is blah");
+        params.put("theProtectedMap.boo", "This is blah");
+
+        HashMap extraContext = new HashMap();
+        extraContext.put(ActionContext.PARAMETERS, params);
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, extraContext);
+        proxy.execute();
+        SimpleAction action = (SimpleAction) proxy.getAction();
+        assertEquals(1, action.getTheProtectedMap().size());
+        assertNotNull(action.getTheProtectedMap().get("boo"));
+        assertNull(action.getTheProtectedMap().get("foo"));
+    }
+    
+    public void testParametersNotAccessProtectedMethods() throws Exception {
+        Map params = new HashMap();
+        params.put("theSemiProtectedMap.foo", "This is blah");
+        params.put("theProtectedMap.boo", "This is blah");
+
+        HashMap extraContext = new HashMap();
+        extraContext.put(ActionContext.PARAMETERS, params);
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, extraContext);
+        proxy.execute();
+        SimpleAction action = (SimpleAction) proxy.getAction();
+        assertEquals(1, action.getTheProtectedMap().size());
+        assertNotNull(action.getTheProtectedMap().get("boo"));
+        assertNull(action.getTheProtectedMap().get("foo"));
+    }
 
     public void testNonexistentParametersGetLoggedInDevMode() throws Exception {
         loadConfigurationProviders(new XmlConfigurationProvider("xwork-test-beans.xml"),