Search in sources :

Example 16 with ConversionData

use of com.opensymphony.xwork2.conversion.impl.ConversionData 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 17 with ConversionData

use of com.opensymphony.xwork2.conversion.impl.ConversionData 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

ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)14 ValueStack (com.opensymphony.xwork2.util.ValueStack)8 ActionSupport (com.opensymphony.xwork2.ActionSupport)3 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)3 HashMap (java.util.HashMap)3 ActionContext (com.opensymphony.xwork2.ActionContext)2 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)2 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)2 ValidationAwareSupport (com.opensymphony.xwork2.ValidationAwareSupport)1 PreResultListener (com.opensymphony.xwork2.interceptor.PreResultListener)1 ConversionErrorFieldValidator (com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1