Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,37 @@ public void testConversionErrorOnAliasedPropertyIsReported() throws Exception {
assertNull("aliasDest must remain unset after a failed conversion", action.getAliasDest());
}

// WW-3226: there is no 'overwrite' flag; whichever of 'alias' and 'params' runs last wins when the
// request carries both the source name and the alias target. The docs promise exactly this.
public void testDirectParameterWinsWhenAliasRunsBeforeParams() throws Exception {
SimpleAction action = executeWithBothNamesSubmitted("aliasBeforeParams");

assertEquals("from-source", action.getAliasSource());
assertEquals("direct", action.getAliasDest());
}

public void testAliasOverridesDirectParameterWhenAliasRunsAfterParams() throws Exception {
SimpleAction action = executeWithBothNamesSubmitted("aliasAfterParams");

assertEquals("from-source", action.getAliasSource());
assertEquals("from-source", action.getAliasDest());
}

private SimpleAction executeWithBothNamesSubmitted(String actionName) throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("aliasSource", "from-source");
params.put("aliasDest", "direct");
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());

XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("struts-alias-ordering.xml");
container.inject(provider);
loadConfigurationProviders(provider);

ActionProxy proxy = actionProxyFactory.createActionProxy("", actionName, null, extraContext.getContextMap());
proxy.execute();
return (SimpleAction) proxy.getAction();
}

public void testNameNotAccepted() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("aliasSource", "source here");
Expand Down
47 changes: 47 additions & 0 deletions core/src/test/resources/struts-alias-ordering.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
"https://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
<include file="xwork-test-default.xml"/>
<package name="alias-ordering" extends="xwork-test-default">

<!-- WW-3226: the order of 'alias' and 'params' decides which value wins when both names are submitted -->
<action name="aliasBeforeParams" class="org.apache.struts2.SimpleAction">
<param name="aliases">#{ "aliasSource" : "aliasDest" }</param>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<result name="success" type="mock"/>
<result name="error" type="mock"/>
</action>

<action name="aliasAfterParams" class="org.apache.struts2.SimpleAction">
<param name="aliases">#{ "aliasSource" : "aliasDest" }</param>
<interceptor-ref name="params"/>
<interceptor-ref name="alias"/>
<result name="success" type="mock"/>
<result name="error" type="mock"/>
</action>

</package>
</struts>
Loading