You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2012/07/05 17:27:59 UTC

svn commit: r1357681 - in /incubator/jspwiki/trunk: ChangeLog src/org/apache/wiki/Release.java src/org/apache/wiki/plugin/IfPlugin.java tests/org/apache/wiki/plugin/AllTests.java tests/org/apache/wiki/plugin/IfPluginTest.java

Author: juanpablo
Date: Thu Jul  5 15:27:59 2012
New Revision: 1357681

URL: http://svn.apache.org/viewvc?rev=1357681&view=rev
Log:
* 2.9.0-incubating-5, fixed JSPWIKI-737 IfPlugin negation doesn't work

Added:
    incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/org/apache/wiki/plugin/IfPlugin.java
    incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/AllTests.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=1357681&r1=1357680&r2=1357681&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Thu Jul  5 15:27:59 2012
@@ -1,4 +1,8 @@
-2012-04-21  Juan Pablo Santos (juanpablo AT apache DOT org)
+2012-06-05  Juan Pablo Santos (juanpablo AT apache DOT org)
+
+       * 2.9.0-incubating-5, fixed JSPWIKI-737 IfPlugin negation doesn't work
+
+2012-06-04  Juan Pablo Santos (juanpablo AT apache DOT org)
 
        * 2.9.0-incubating-4, added support for cobertura reports and Sonar integration.
 

Modified: incubator/jspwiki/trunk/src/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/Release.java?rev=1357681&r1=1357680&r2=1357681&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/Release.java Thu Jul  5 15:27:59 2012
@@ -77,7 +77,7 @@ public final class Release
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "4";
+    public static final String     BUILD         = "5";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/org/apache/wiki/plugin/IfPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/plugin/IfPlugin.java?rev=1357681&r1=1357680&r2=1357681&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/plugin/IfPlugin.java (original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/plugin/IfPlugin.java Thu Jul  5 15:27:59 2012
@@ -225,6 +225,7 @@ public class IfPlugin implements WikiPlu
     {
         if( user == null || context.getCurrentUser() == null ) return false;
 
+        String userToCheck = user;
         String[] list = StringUtils.split(user,'|');
         boolean include = false;
 
@@ -234,9 +235,13 @@ public class IfPlugin implements WikiPlu
             if( list[i].startsWith("!") )
             {
                 invert = true;
+                // strip !
+                if(  user.length() > 1 ) {
+                    userToCheck = user.substring( 1 );
+                }
             }
 
-            include |= user.equals( context.getCurrentUser().getName() ) ^ invert;
+            include |= userToCheck.equals( context.getCurrentUser().getName() ) ^ invert;
         }
         return include;
     }

Modified: incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/AllTests.java?rev=1357681&r1=1357680&r2=1357681&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/AllTests.java Thu Jul  5 15:27:59 2012
@@ -40,6 +40,7 @@ public class AllTests extends TestCase
 
         suite.addTest( CounterPluginTest.suite() );
         suite.addTest( GroupsTest.suite() );
+        suite.addTest( IfPluginTest.suite() );
         suite.addTest( InsertPageTest.suite() );
         suite.addTest( PluginManagerTest.suite() );
         suite.addTest( ReferringPagesPluginTest.suite() );

Added: incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java?rev=1357681&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java (added)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java Thu Jul  5 15:27:59 2012
@@ -0,0 +1,105 @@
+package org.apache.wiki.plugin;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import net.sourceforge.stripes.mock.MockHttpServletRequest;
+
+import org.apache.wiki.*;
+import org.apache.wiki.auth.Users;
+import org.apache.wiki.providers.WikiPageProvider;
+
+public class IfPluginTest extends TestCase
+{
+    
+    TestEngine testEngine;
+    
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        Properties props = new Properties();
+        props.load( TestEngine.findTestProperties() );
+        testEngine = new TestEngine( props );
+    }
+
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        
+        testEngine.deletePage( "Test" );
+    }
+    
+    /**
+     * Returns a {@link WikiContext} for the given page, with user {@link Users#JANNE} logged in.
+     * 
+     * @param page given {@link WikiPage}.
+     * @return {@link WikiContext} associated to given {@link WikiPage}.
+     * @throws WikiException problems while logging in.
+     */
+    WikiContext getJanneBasedWikiContextFor( WikiPage page ) throws WikiException 
+    {
+        MockHttpServletRequest request = testEngine.newHttpRequest();
+        WikiSession session =  WikiSession.getWikiSession( testEngine, request );
+        testEngine.getAuthenticationManager().login( session, 
+                                                     request,
+                                                     Users.JANNE,
+                                                     Users.JANNE_PASS );
+        
+        return new WikiContext( testEngine, request, page );
+    }
+    
+    /**
+     * Checks that user access is granted.
+     * 
+     * @throws WikiException test failing.
+     */
+    public void testIfPluginUserAllowed() throws WikiException 
+    {
+        String src = "[{IfPlugin user='Janne Jalkanen'\n" +
+        		     "\n" +
+        		     "Content visible for Janne Jalkanen}]";
+        String expected = "<p>Content visible for Janne Jalkanen</p>\n";
+        
+        testEngine.saveText( "Test", src );
+        WikiPage page = testEngine.getPage( "Test", WikiPageProvider.LATEST_VERSION );
+        WikiContext context = getJanneBasedWikiContextFor( page );
+        
+        String res = testEngine.getHTML( context, page );
+        assertEquals( expected, res );
+    }
+    
+    /**
+     * Checks that user access is forbidden.
+     * 
+     * @throws WikiException test failing.
+     */
+    public void testIfPluginUserNotAllowed() throws WikiException 
+    {
+        String src = "[{IfPlugin user='!Janne Jalkanen'\n" +
+                     "\n" +
+                     "Content NOT visible for Janne Jalkanen}]";
+        String expected = "\n";
+        
+        testEngine.saveText( "Test", src );
+        WikiPage page = testEngine.getPage( "Test", WikiPageProvider.LATEST_VERSION );
+        WikiContext context = getJanneBasedWikiContextFor( page );
+        
+        String res = testEngine.getHTML( context, page );
+        assertEquals( expected, res );
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite( IfPluginTest.class );
+    }
+    
+}