Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XWIKI-6936: Cannot save a class after creating a property named 'acti…
…on' (#1292) * Fixed by limiting the actions accepted in the filter to the one explicitly defined in the xaction parameters if it exists. * Added an ActionFilter unit test
- Loading branch information
1 parent
d8872c1
commit d7562e6
Showing
8 changed files
with
283 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
...latform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/web/ActionFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package com.xpn.xwiki.web;/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
import java.util.Collections; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.xwiki.component.manager.ComponentManager; | ||
import org.xwiki.configuration.ConfigurationSource; | ||
import org.xwiki.test.annotation.BeforeComponent; | ||
import org.xwiki.test.junit5.mockito.ComponentTest; | ||
import org.xwiki.test.mockito.MockitoComponentManager; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Tests of {@link ActionFilter}. | ||
* | ||
* @version $Id$ | ||
* @since 12.4RC1 | ||
*/ | ||
@ComponentTest | ||
public class ActionFilterTest | ||
{ | ||
private final ActionFilter filter = new ActionFilter(); | ||
|
||
@BeforeComponent | ||
public void setup(MockitoComponentManager componentManager) throws Exception | ||
{ | ||
Utils.setComponentManager(componentManager); | ||
componentManager.registerMockComponent(ConfigurationSource.class, "xwikicfg"); | ||
componentManager.registerComponent(ComponentManager.class, "context", componentManager); | ||
} | ||
|
||
@Test | ||
void doFilterNotAnHttpServletRequest() throws Exception | ||
{ | ||
ServletRequest request = mock(ServletRequest.class); | ||
ServletResponse response = mock(ServletResponse.class); | ||
FilterChain chain = mock(FilterChain.class); | ||
|
||
filter.doFilter(request, response, chain); | ||
|
||
verify(request, never()).getParameterValues("xaction"); | ||
verify(chain).doFilter(request, response); | ||
} | ||
|
||
@Test | ||
void doFilterActionDispatcherIsTrue() throws Exception | ||
{ | ||
ServletRequest request = mock(HttpServletRequest.class); | ||
ServletResponse response = mock(ServletResponse.class); | ||
FilterChain chain = mock(FilterChain.class); | ||
|
||
when(request.getAttribute(ActionFilter.class.getName() + ".actionDispatched")).thenReturn("true"); | ||
|
||
filter.doFilter(request, response, chain); | ||
|
||
verify(request, never()).getParameterValues("xaction"); | ||
verify(chain).doFilter(request, response); | ||
} | ||
|
||
@Test | ||
void doFilterXactionNull() throws Exception | ||
{ | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
ServletResponse response = mock(ServletResponse.class); | ||
FilterChain chain = mock(FilterChain.class); | ||
|
||
when(request.getParameterValues("xaction")).thenReturn(null); | ||
when(request.getParameterNames()).thenReturn(Collections.enumeration(Collections.singletonList("a"))); | ||
|
||
filter.doFilter(request, response, chain); | ||
|
||
verify(request).getParameterValues("xaction"); | ||
verify(chain).doFilter(request, response); | ||
verify(request, never()).getRequestDispatcher(any()); | ||
} | ||
|
||
@Test | ||
void doFilterXactionNullParamActionExist() throws Exception | ||
{ | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
ServletResponse response = mock(ServletResponse.class); | ||
FilterChain chain = mock(FilterChain.class); | ||
|
||
when(request.getParameterValues("xaction")).thenReturn(null); | ||
when(request.getParameterNames()).thenReturn(Collections.enumeration(Collections.singletonList("action_a"))); | ||
when(request.getRequestURI()).thenReturn("/segment1/segment2/segment3/"); | ||
when(request.getServletPath()).thenReturn("/serv"); | ||
when(request.getContextPath()).thenReturn("/ctx/"); | ||
|
||
filter.doFilter(request, response, chain); | ||
|
||
verify(request).getParameterValues("xaction"); | ||
verify(chain).doFilter(request, response); | ||
verify(request).getRequestDispatcher(any()); | ||
} | ||
|
||
@Test | ||
void doFilterXactionIsAction() throws Exception | ||
{ | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
ServletResponse response = mock(ServletResponse.class); | ||
FilterChain chain = mock(FilterChain.class); | ||
|
||
when(request.getParameterValues("xaction")).thenReturn(new String[] { | ||
"a" | ||
}); | ||
|
||
when(request.getParameterNames()).thenReturn(Collections.enumeration(Collections.singletonList("action_a"))); | ||
|
||
when(request.getRequestURI()).thenReturn("/segment1/segment2/segment3/"); | ||
when(request.getServletPath()).thenReturn("/serv"); | ||
when(request.getContextPath()).thenReturn("/ctx/"); | ||
|
||
filter.doFilter(request, response, chain); | ||
|
||
verify(request).getParameterValues("xaction"); | ||
verify(chain).doFilter(request, response); | ||
verify(request).getRequestDispatcher(any()); | ||
} | ||
|
||
@Test | ||
void doFilterXactionIsNotAction() throws Exception | ||
{ | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
ServletResponse response = mock(ServletResponse.class); | ||
FilterChain chain = mock(FilterChain.class); | ||
|
||
when(request.getParameterValues("xaction")).thenReturn(new String[] { | ||
"b" | ||
}); | ||
|
||
when(request.getParameterNames()).thenReturn(Collections.enumeration(Collections.singletonList("action_a"))); | ||
|
||
when(request.getRequestURI()).thenReturn("/segment1/segment2/segment3/"); | ||
when(request.getServletPath()).thenReturn("/serv"); | ||
when(request.getContextPath()).thenReturn("/ctx/"); | ||
|
||
filter.doFilter(request, response, chain); | ||
|
||
verify(request).getParameterValues("xaction"); | ||
verify(chain).doFilter(request, response); | ||
verify(request, never()).getRequestDispatcher(any()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ss-test/xwiki-platform-xclass-test-docker/src/test/it/org/xwiki/xclass/test/ui/AllIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.xclass.test.ui; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.xwiki.test.docker.junit5.UITest; | ||
|
||
/** | ||
* All UI tests for the XClasses. | ||
* | ||
* @version $Id$ | ||
* @since 12.4RC1 | ||
*/ | ||
@UITest | ||
public class AllIT | ||
{ | ||
@Nested | ||
@DisplayName("Class Sheet UI tests") | ||
class NestedClassSheetIT extends ClassSheetIT | ||
{ | ||
} | ||
} |
Oops, something went wrong.