use of com.opensymphony.xwork2.util.Foo 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.util.Foo in project struts by apache.
the class ValidateAction method testParametersNotAccessProtectedMethods.
public void testParametersNotAccessProtectedMethods() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("theSemiProtectedMap.foo", "This is blah");
params.put("theProtectedMap.boo", "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();
SimpleAction action = (SimpleAction) proxy.getAction();
assertEquals(1, action.getTheProtectedMap().size());
assertNotNull(action.getTheProtectedMap().get("boo"));
assertNull(action.getTheProtectedMap().get("foo"));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class XmlConfigurationProviderInterceptorsTest method testBasicInterceptors.
public void testBasicInterceptors() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-interceptors-basic.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// setup expectations
// the test interceptor with a parameter
Map<String, String> params = new HashMap<>();
params.put("foo", "expectedFoo");
InterceptorConfig paramsInterceptor = new InterceptorConfig.Builder("test", MockInterceptor.class.getName()).addParams(params).build();
// the default interceptor stack
InterceptorStackConfig defaultStack = new InterceptorStackConfig.Builder("defaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))).build();
// the derivative interceptor stack
InterceptorStackConfig derivativeStack = new InterceptorStackConfig.Builder("derivativeStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))).addInterceptor(new InterceptorMapping("logging", objectFactory.buildInterceptor(loggingInterceptor, new HashMap<String, String>()))).build();
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map interceptorConfigs = pkg.getInterceptorConfigs();
// assertions for size
assertEquals(5, interceptorConfigs.size());
// assertions for interceptors
assertEquals(noopInterceptor, interceptorConfigs.get("noop"));
assertEquals(loggingInterceptor, interceptorConfigs.get("logging"));
assertEquals(paramsInterceptor, interceptorConfigs.get("test"));
// assertions for interceptor stacks
assertEquals(defaultStack, interceptorConfigs.get("defaultStack"));
assertEquals(derivativeStack, interceptorConfigs.get("derivativeStack"));
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class NumberConverterTest method testStringToNumberConversionPL.
public void testStringToNumberConversionPL() throws Exception {
// given
NumberConverter converter = new NumberConverter();
Map<String, Object> context = createContextWithLocale(new Locale("pl", "PL"));
SimpleFooAction foo = new SimpleFooAction();
// when
Object value = converter.convertValue(context, foo, null, "id", "1234", Integer.class);
// then
assertEquals(1234, value);
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class ListAction method testStringToCustomTypeUsingCustomConverter.
public void testStringToCustomTypeUsingCustomConverter() {
// the converter needs to be registered as the Bar.class converter
// it won't be detected from the Foo-conversion.properties
// because the Foo-conversion.properties file is only used when converting a property of Foo
converter.registerConverter(Bar.class.getName(), new FooBarConverter());
Bar bar = (Bar) converter.convertValue(null, null, null, null, "blah:123", Bar.class);
assertNotNull("conversion failed", bar);
assertEquals(123, bar.getSomethingElse());
assertEquals("blah", bar.getTitle());
}
Aggregations