Search in sources :

Example 51 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class ConversionErrorInterceptorTest method testWithPreResultListenerAgainstMaliciousCode.

/**
 * See WW-3668
 */
public void testWithPreResultListenerAgainstMaliciousCode() throws Exception {
    conversionErrors.put("foo", new ConversionData("\" + #root + \"", int.class));
    ActionContext ac = createActionContext();
    MockActionInvocation mai = createActionInvocation(ac);
    SimpleAction action = createAction(mai);
    assertNull(action.getFieldErrors().get("foo"));
    assertEquals(55, stack.findValue("foo"));
    interceptor.doIntercept(mai);
    assertTrue(action.hasFieldErrors());
    assertNotNull(action.getFieldErrors().get("foo"));
    assertEquals("\" + #root + \"", stack.findValue("foo"));
}
Also used : MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) ConversionData(com.opensymphony.xwork2.conversion.impl.ConversionData)

Example 52 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class ConversionErrorInterceptorTest method testWithPreResultListener.

public void testWithPreResultListener() throws Exception {
    conversionErrors.put("foo", new ConversionData("Hello", int.class));
    ActionContext ac = createActionContext();
    MockActionInvocation mai = createActionInvocation(ac);
    SimpleAction action = createAction(mai);
    assertNull(action.getFieldErrors().get("foo"));
    assertEquals(55, stack.findValue("foo"));
    interceptor.doIntercept(mai);
    assertTrue(action.hasFieldErrors());
    assertNotNull(action.getFieldErrors().get("foo"));
    // assume that the original value is reset
    assertEquals("Hello", stack.findValue("foo"));
}
Also used : MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) ConversionData(com.opensymphony.xwork2.conversion.impl.ConversionData)

Aggregations

SimpleAction (com.opensymphony.xwork2.SimpleAction)32 ActionProxy (com.opensymphony.xwork2.ActionProxy)24 HashMap (java.util.HashMap)23 LinkedHashMap (java.util.LinkedHashMap)17 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)14 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)8 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)7 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)7 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)6 Action (com.opensymphony.xwork2.Action)5 TestBean (com.opensymphony.xwork2.TestBean)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)5 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)4 ModelDrivenAction (com.opensymphony.xwork2.ModelDrivenAction)3 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)3 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)3 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)2 MockResult (com.opensymphony.xwork2.mock.MockResult)2