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 18:00:44 UTC
svn commit: r1357710 - in /incubator/jspwiki/trunk:
src/org/apache/wiki/plugin/IfPlugin.java
tests/org/apache/wiki/plugin/IfPluginTest.java
Author: juanpablo
Date: Thu Jul 5 16:00:43 2012
New Revision: 1357710
URL: http://svn.apache.org/viewvc?rev=1357710&view=rev
Log:
JSPWIKI-737: just realised that IP check was also suffering the same bug. Also, the fix for users wasn't taking into account the possibility of multiple users. No version bump as the last commit was some minutes ago and refers to the same functionality.
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/plugin/IfPlugin.java
incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java
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=1357710&r1=1357709&r2=1357710&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 16:00:43 2012
@@ -210,7 +210,10 @@ public class IfPlugin implements WikiPlu
boolean invert = false;
if( groupList[i].startsWith("!") )
{
- gname = groupList[i].substring(1);
+ if( groupList[i].length() > 1 )
+ {
+ gname = groupList[i].substring( 1 );
+ }
invert = true;
}
@@ -225,19 +228,20 @@ public class IfPlugin implements WikiPlu
{
if( user == null || context.getCurrentUser() == null ) return false;
- String userToCheck = user;
String[] list = StringUtils.split(user,'|');
boolean include = false;
for( int i = 0; i < list.length; i++ )
{
+ String userToCheck = list[i];
boolean invert = false;
if( list[i].startsWith("!") )
{
invert = true;
// strip !
- if( user.length() > 1 ) {
- userToCheck = user.substring( 1 );
+ if( user.length() > 1 )
+ {
+ userToCheck = list[i].substring( 1 );
}
}
@@ -251,18 +255,25 @@ public class IfPlugin implements WikiPlu
{
if( ipaddr == null || context.getHttpRequest() == null ) return false;
+
String[] list = StringUtils.split(ipaddr,'|');
boolean include = false;
for( int i = 0; i < list.length; i++ )
{
+ String ipaddrToCheck = list[i];
boolean invert = false;
if( list[i].startsWith("!") )
{
invert = true;
+ // strip !
+ if( list[i].length() > 1 )
+ {
+ ipaddrToCheck = list[i].substring( 1 );
+ }
}
- include |= ipaddr.equals( context.getHttpRequest().getRemoteAddr() ) ^ invert;
+ include |= ipaddrToCheck.equals( context.getHttpRequest().getRemoteAddr() ) ^ invert;
}
return include;
}
Modified: 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=1357710&r1=1357709&r2=1357710&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java (original)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/plugin/IfPluginTest.java Thu Jul 5 16:00:43 2012
@@ -97,6 +97,46 @@ public class IfPluginTest extends TestCa
assertEquals( expected, res );
}
+ /**
+ * Checks that IP address is granted.
+ *
+ * @throws WikiException test failing.
+ */
+ public void testIfPluginIPAllowed() throws WikiException
+ {
+ String src = "[{IfPlugin ip='127.0.0.1'\n" +
+ "\n" +
+ "Content visible for 127.0.0.1}]";
+ String expected = "<p>Content visible for 127.0.0.1</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 IP address is granted.
+ *
+ * @throws WikiException test failing.
+ */
+ public void testIfPluginIPNotAllowed() throws WikiException
+ {
+ String src = "[{IfPlugin ip='!127.0.0.1'\n" +
+ "\n" +
+ "Content NOT visible for 127.0.0.1}]";
+ 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 );