use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class ValidateAction method doTestParameterNameLengthRestriction.
private void doTestParameterNameLengthRestriction(ParametersInterceptor parametersInterceptor, int paramNameMaxLength) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < paramNameMaxLength + 1; i++) {
sb.append("x");
}
Map<String, Object> actual = new LinkedHashMap<>();
parametersInterceptor.setValueStackFactory(createValueStackFactory(actual));
ValueStack stack = createStubValueStack(actual);
Map<String, Object> parameters = new HashMap<>();
parameters.put(sb.toString(), "");
parameters.put("huuhaa", "");
Action action = new SimpleAction();
parametersInterceptor.setParameters(action, stack, HttpParameters.create(parameters).build());
assertEquals(1, actual.size());
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class ValidateAction method testParametersDoesNotAffectSession.
public void testParametersDoesNotAffectSession() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("blah", "This is blah");
params.put("#session.foo", "Foo");
params.put("\u0023session['user']", "0wn3d");
params.put("\\u0023session['user']", "0wn3d");
params.put("\u0023session.user2", "0wn3d");
params.put("\\u0023session.user2", "0wn3d");
params.put("('\u0023'%20%2b%20'session['user3']')(unused)", "0wn3d");
params.put("('\\u0023' + 'session[\\'user4\\']')(unused)", "0wn3d");
params.put("('\u0023'%2b'session['user5']')(unused)", "0wn3d");
params.put("('\\u0023'%2b'session['user5']')(unused)", "0wn3d");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ValueStack stack = proxy.getInvocation().getStack();
HashMap<String, Object> session = new HashMap<>();
stack.getContext().put("session", session);
proxy.execute();
assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
assertNull(session.get("foo"));
assertNull(session.get("user"));
assertNull(session.get("user2"));
assertNull(session.get("user3"));
assertNull(session.get("user4"));
assertNull(session.get("user5"));
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class ValidateAction method testNonexistentParametersGetLoggedInDevMode.
public void testNonexistentParametersGetLoggedInDevMode() throws Exception {
XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-test-beans.xml");
container.inject(provider);
loadConfigurationProviders(provider, new MockConfigurationProvider(Collections.singletonMap("struts.devMode", "true")));
Map<String, Object> params = new HashMap<>();
params.put("not_a_property", "There is no action property named like this");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
container.inject(config.getInterceptors().get(0).getInterceptor());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
proxy.execute();
final String actionMessage = "" + ((SimpleAction) proxy.getAction()).getActionMessages().toArray()[0];
assertTrue(actionMessage.contains("Error setting expression 'not_a_property' with value 'There is no action property named like this'"));
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class ValidateAction method testParameters.
public void testParameters() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("blah", "This is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
proxy.execute();
assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class ValidateAction method testOrdered.
public void testOrdered() throws Exception {
ParametersInterceptor pi = new ParametersInterceptor();
pi.setOrdered(true);
container.inject(pi);
final Map<String, Object> actual = new LinkedHashMap<>();
pi.setValueStackFactory(createValueStackFactory(actual));
ValueStack stack = createStubValueStack(actual);
Map<String, Object> parameters = new HashMap<>();
parameters.put("user.address.city", "London");
parameters.put("user.address['postal']", "QJR387");
parameters.put("user.name", "Superman");
Action action = new SimpleAction();
pi.setParameters(action, stack, HttpParameters.create(parameters).build());
assertEquals(true, pi.isOrdered());
assertEquals(3, actual.size());
assertEquals("London", actual.get("user.address.city"));
assertEquals("QJR387", actual.get("user.address['postal']"));
assertEquals("Superman", actual.get("user.name"));
// should be ordered so user.name should be first
List<Object> values = new ArrayList<Object>(actual.values());
assertEquals("Superman", values.get(0));
assertEquals("London", values.get(1));
assertEquals("QJR387", values.get(2));
}
Aggregations