r1299 - xwiki/trunk/src/test/cactus/com/xpn/xwiki/test
Phung Hai Nam
namphunghai at users.forge.objectweb.org
Fri Sep 8 12:39:54 CEST 2006
Author: namphunghai
Date: 2006-09-08 12:39:53 +0200 (Fri, 08 Sep 2006)
New Revision: 1299
Added:
xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCaptchaTest.java
Removed:
xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCapchaTest.java
Log:
XWIKI-118. Update the ServletCaptchaTest.java
Deleted: xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCapchaTest.java
===================================================================
--- xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCapchaTest.java 2006-09-08 07:26:45 UTC (rev 1298)
+++ xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCapchaTest.java 2006-09-08 10:39:53 UTC (rev 1299)
@@ -1,111 +0,0 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * 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.
- *
- * @author Phung Hai Nam (phunghainam at xwiki.com)
- * @version 5 Sep 2006
- */
-package com.xpn.xwiki.test;
-
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.store.XWikiHibernateStore;
-import org.apache.cactus.WebRequest;
-import org.apache.cactus.WebResponse;
-import org.hibernate.HibernateException;
-
-public class ServletCapchaTest extends ServletTest {
- public void setUp() throws Exception {
- super.setUp();
- }
-
- public void cleanUp() {
- super.cleanUp();
- }
-
- public void beginShowCaptchaImageForAnonymousEdit(WebRequest webRequest) throws HibernateException, XWikiException {
- XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
- StoreHibernateTest.cleanUp(hibstore, context);
- clientSetUp(hibstore);
-
- Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "Image", context);
- Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
- setUrl(webRequest, "edit", "Main", "WebHome", "");
- }
-
- public void endShowCaptchaImageForAnonymousEdit(WebResponse webResponse) throws HibernateException {
- try {
- String result = webResponse.getText();
- assertTrue("Could not find captcha image form : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
- } finally {
- clientTearDown();
- }
- }
-
- public void testShowCaptchaImageForAnonymousEdit() throws Throwable {
- launchTest();
- }
-
- public void beginShowCaptchaTextForAnonymousEdit(WebRequest webRequest) throws HibernateException, XWikiException {
- XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
- StoreHibernateTest.cleanUp(hibstore, context);
- clientSetUp(hibstore);
-
- Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "Text", context);
- Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
- setUrl(webRequest, "edit", "Main", "WebHome", "");
- }
-
- public void endShowCaptchaTextForAnonymousEdit(WebResponse webResponse) throws HibernateException {
- try {
- String result = webResponse.getText();
- assertTrue("Could not find captcha text form : " + result, result.indexOf("Please answer this simple math question") != -1);
- } finally {
- clientTearDown();
- }
- }
-
- public void testShowCaptchaTextForAnonymousEdit() throws Throwable {
- launchTest();
- }
-
- public void beginCaptchaNotCorrectAnonymous(WebRequest webRequest) throws HibernateException, XWikiException {
- XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
- StoreHibernateTest.cleanUp(hibstore, context);
- clientSetUp(hibstore);
-
- Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "Image", context);
- Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
- setUrl(webRequest, "save", "Main", "WebHome", "");
- webRequest.addParameter("content", "This is modification");
- webRequest.addParameter("parent", "Main.WebHome");
- webRequest.addParameter("jcaptcha_response", "false");
- }
-
- public void endCaptchaNotCorrectAnonymous(WebResponse webResponse) throws HibernateException {
- try {
- String result = webResponse.getText();
- assertTrue("Could not find captcha form : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
- } finally {
- clientTearDown();
- }
- }
-
- public void testCaptchaNotCorrectAnonymous() throws Throwable {
- launchTest();
- }
-}
Copied: xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCaptchaTest.java (from rev 1297, xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCapchaTest.java)
===================================================================
--- xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCapchaTest.java 2006-09-07 15:54:31 UTC (rev 1297)
+++ xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletCaptchaTest.java 2006-09-08 10:39:53 UTC (rev 1299)
@@ -0,0 +1,276 @@
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author Phung Hai Nam (phunghainam at xwiki.com)
+ * @version 5 Sep 2006
+ */
+package com.xpn.xwiki.test;
+
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.store.XWikiHibernateStore;
+import org.apache.cactus.WebRequest;
+import org.apache.cactus.WebResponse;
+import org.hibernate.HibernateException;
+
+import java.util.HashMap;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+public class ServletCaptchaTest extends ServletTest {
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void cleanUp() {
+ super.cleanUp();
+ }
+
+ // ====================== Test show a jcaptcha image to confirm for edit by anonymous ==============================
+ public void beginShowCaptchaImageForAnonymousEdit(WebRequest webRequest) throws HibernateException, XWikiException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "Image", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
+ setUrl(webRequest, "edit", "Main", "WebHome", "");
+ }
+
+ public void endShowCaptchaImageForAnonymousEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ String result = webResponse.getText();
+ assertTrue("Could not find captcha image : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testShowCaptchaImageForAnonymousEdit() throws Throwable {
+ launchTest();
+ }
+
+ // ====================== Test show a simple question to confirm for edit by anonymous =============================
+ public void beginShowCaptchaTextForAnonymousEdit(WebRequest webRequest) throws HibernateException, XWikiException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "Text", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
+ setUrl(webRequest, "edit", "Main", "WebHome", "");
+ }
+
+ public void endShowCaptchaTextForAnonymousEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ String result = webResponse.getText();
+ assertTrue("Could not find simple math question : " + result, result.indexOf("Please answer this simple math question") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testShowCaptchaTextForAnonymousEdit() throws Throwable {
+ launchTest();
+ }
+
+ // ======================== Test don't show jcaptcha to confirm for edit by anonymous ==============================
+ public void beginNotShowCaptchaImageForAnonymousEdit(WebRequest webRequest) throws HibernateException, XWikiException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "---", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
+ setUrl(webRequest, "edit", "Main", "WebHome", "");
+ }
+
+ public void endNotShowCaptchaImageForAnonymousEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ String result = webResponse.getText();
+ assertFalse("Find out captcha image : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
+ assertFalse("Find out simple math question : " + result, result.indexOf("Please answer this simple math question") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testNotShowCaptchaImageForAnonymousEdit() throws Throwable {
+ launchTest();
+ }
+
+ // =================== Test for require captcha again when comfirm to edit is not correct ==========================
+ public void beginCaptchaNotCorrectForAnonymousEdit(WebRequest webRequest) throws HibernateException, XWikiException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_anonymous", "Image", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
+ setUrl(webRequest, "save", "Main", "WebHome", "");
+ webRequest.addParameter("content", "This is modification");
+ webRequest.addParameter("parent", "Main.WebHome");
+ webRequest.addParameter("jcaptcha_response", "false");
+ }
+
+ public void endCaptchaNotCorrectForAnonymousEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ String result = webResponse.getText();
+ assertTrue("Could not find captcha form : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testCaptchaNotCorrectForAnonymousEdit() throws Throwable {
+ launchTest();
+ }
+
+ // ====================== Test show a jcaptcha image to confirm for edit by registered user ========================
+ public void beginShowCaptchaImageForRegisteredUserEdit(WebRequest webRequest) throws HibernateException, XWikiException, MalformedURLException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_registered", "Image", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome1", context);
+ HashMap map = new HashMap();
+ map.put("password", "toto");
+ xwiki.createUser("PhungHaiNam", map, "", "", "view, edit", context);
+ Utils.updateRight(xwiki, context, "Main.WebHome1", "XWiki.PhungHaiNam", "", "edit", true, false);
+
+ MyFormAuthentication auth = new MyFormAuthentication("PhungHaiNam", "toto");
+ auth.setSecurityCheckURL(new URL("http://127.0.0.1:9080/xwiki/testbin/loginsubmit/XWiki/XWikiLogin"));
+ webRequest.setAuthentication(auth);
+ setUrl(webRequest, "edit", "Main", "WebHome1", "");
+ }
+
+ public void endShowCaptchaImageForRegisteredUserEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ assertEquals("Response status should be 200", 200, webResponse.getStatusCode());
+ String result = webResponse.getText();
+ assertTrue("Could not find WebHome1 Content: " + result, result.indexOf("Hello 1")!=-1);
+ assertTrue("Could not find captcha image : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testShowCaptchaImageForRegisteredUserEdit() throws Throwable {
+ launchTest();
+ }
+
+ // ====================== Test show a jcaptcha image to confirm for edit by registered user ========================
+ public void beginShowCaptchaTextForRegisteredUserEdit(WebRequest webRequest) throws HibernateException, XWikiException, MalformedURLException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_registered", "Text", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome1", context);
+ HashMap map = new HashMap();
+ map.put("password", "toto");
+ xwiki.createUser("PhungHaiNam", map, "", "", "view, edit", context);
+ Utils.updateRight(xwiki, context, "Main.WebHome1", "XWiki.PhungHaiNam", "", "edit", true, false);
+
+ MyFormAuthentication auth = new MyFormAuthentication("PhungHaiNam", "toto");
+ auth.setSecurityCheckURL(new URL("http://127.0.0.1:9080/xwiki/testbin/loginsubmit/XWiki/XWikiLogin"));
+ webRequest.setAuthentication(auth);
+ setUrl(webRequest, "edit", "Main", "WebHome1", "");
+ }
+
+ public void endShowCaptchaTextForRegisteredUserEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ assertEquals("Response status should be 200", 200, webResponse.getStatusCode());
+ String result = webResponse.getText();
+ assertTrue("Could not find WebHome1 Content: " + result, result.indexOf("Hello 1")!=-1);
+ assertTrue("Could not find simple math question : " + result, result.indexOf("Please answer this simple math question") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testShowCaptchaTextForRegisteredUserEdit() throws Throwable {
+ launchTest();
+ }
+
+ // ====================== Test don't show a jcaptcha to confirm for edit by Administrator =========================
+ public void beginNotShowCaptchaTextForAdminEdit(WebRequest webRequest) throws HibernateException, XWikiException, MalformedURLException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_registered", "Text", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome1", context);
+ HashMap map = new HashMap();
+ map.put("password", "toto");
+ xwiki.createUser("Admin", map, "", "", "view, edit, admin", context);
+ Utils.updateRight(xwiki, context, "Main.WebHome1", "XWiki.Admin", "", "edit", true, false);
+
+ MyFormAuthentication auth = new MyFormAuthentication("admin", "toto");
+ auth.setSecurityCheckURL(new URL("http://127.0.0.1:9080/xwiki/testbin/loginsubmit/XWiki/XWikiLogin"));
+ webRequest.setAuthentication(auth);
+ setUrl(webRequest, "edit", "Main", "WebHome1", "");
+ }
+
+ public void endNotShowCaptchaTextForAdminEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ assertEquals("Response status should be 200", 200, webResponse.getStatusCode());
+ String result = webResponse.getText();
+ assertTrue("Could not find WebHome1 Content: " + result, result.indexOf("Hello 1")!=-1);
+ assertFalse("Find out captcha image : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
+ assertFalse("Find out simple math question : " + result, result.indexOf("Please answer this simple math question") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testNotShowCaptchaTextForAdminEdit() throws Throwable {
+ launchTest();
+ }
+
+ // ====================== Test don't show a jcaptcha again to when admin save modifications ========================
+ public void beginNotShowCaptchaAgainForAdminEdit(WebRequest webRequest) throws HibernateException, XWikiException, MalformedURLException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+ Utils.setStringValue("XWiki.XWikiPreferences", "edit_registered", "Text", context);
+ Utils.createDoc(xwiki.getStore(), "Main", "WebHome", context);
+ HashMap map = new HashMap();
+ map.put("password", "toto");
+ xwiki.createUser("Admin", map, "", "", "view, edit, save", context);
+ Utils.updateRight(xwiki, context, "Main.WebHome", "XWiki.Admin", "", "save", true, false);
+
+ MyFormAuthentication auth = new MyFormAuthentication("admin", "toto");
+ auth.setSecurityCheckURL(new URL("http://127.0.0.1:9080/xwiki/testbin/loginsubmit/XWiki/XWikiLogin"));
+ webRequest.setAuthentication(auth);
+ setUrl(webRequest, "save", "Main", "WebHome", "");
+
+ }
+
+ public void endNotShowCaptchaAgainForAdminEdit(WebResponse webResponse) throws HibernateException {
+ try {
+ String result = webResponse.getText();
+ assertFalse("Find out captcha image : " + result, result.indexOf("<input type=\"text\" name=\"jcaptcha_response\"") != -1);
+ assertFalse("Find out simple math question : " + result, result.indexOf("Please answer this simple math question") != -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testNotShowCaptchaAgainForAdminEdit() throws Throwable {
+ launchTest();
+ }
+}
More information about the Xwiki-notifications
mailing list