Search in sources :

Example 1 with ParseException

use of ognl.ParseException in project struts by apache.

the class OgnlValueStackTest method testNotFailOnTooLongExpressionWithDefaultProperties.

public void testNotFailOnTooLongExpressionWithDefaultProperties() {
    loadConfigurationProviders(new DefaultPropertiesProvider());
    Object defaultMaxLengthFromConfiguration = container.getInstance(String.class, StrutsConstants.STRUTS_OGNL_EXPRESSION_MAX_LENGTH);
    if (defaultMaxLengthFromConfiguration != null) {
        assertTrue("non-null defaultMaxLengthFromConfiguration not a String ?", defaultMaxLengthFromConfiguration instanceof String);
        assertTrue("non-null defaultMaxLengthFromConfiguration not empty string by default ?", ((String) defaultMaxLengthFromConfiguration).length() == 0);
    } else {
        assertNull("defaultMaxLengthFromConfiguration not null ?", defaultMaxLengthFromConfiguration);
    }
    // Original test logic was to confirm failure of exceeding the default value.  Now the feature should be disabled by default,
    // so this test's expectations are now changed.
    // Since maxlength is disabled by default, just choose an arbitrary value for test
    Integer repeat = Integer.valueOf(256);
    OgnlValueStack vs = createValueStack();
    try {
        vs.findValue(StringUtils.repeat('.', repeat + 1), true);
        fail("findValue did not throw any exception (should either fail as invalid expression syntax or security exception) ?");
    } catch (Exception ex) {
        // If STRUTS_OGNL_EXPRESSION_MAX_LENGTH feature is disabled (default), the parse should fail due to a reason of invalid expression syntax
        // with ParseException.  Previously when it was enabled the reason for the failure would have been SecurityException.
        assertTrue(ex.getCause() instanceof OgnlException);
        assertTrue(((OgnlException) ex.getCause()).getReason() instanceof ParseException);
    }
}
Also used : OgnlException(ognl.OgnlException) ParseException(ognl.ParseException) DefaultPropertiesProvider(org.apache.struts2.config.DefaultPropertiesProvider) ParseException(ognl.ParseException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) StrutsException(org.apache.struts2.StrutsException) OgnlException(ognl.OgnlException)

Aggregations

ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)1 OgnlException (ognl.OgnlException)1 ParseException (ognl.ParseException)1 StrutsException (org.apache.struts2.StrutsException)1 DefaultPropertiesProvider (org.apache.struts2.config.DefaultPropertiesProvider)1