Author: tmortagne
Date: 2008-02-21 17:23:17 +0100 (Thu, 21 Feb 2008)
New Revision: 7904

Modified:
   
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
   
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/LDAPAuthTest.java
   
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
   
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
   
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
Log:
XWIKI-2139: Can't log in LDAP with user id containing space
XWIKI-2140: bind_DN and bind_pass are not correctly converted using 
MessageFormat
Also added integration tests for theses issues.

Modified: 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
===================================================================
--- 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
       2008-02-21 16:04:57 UTC (rev 7903)
+++ 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
       2008-02-21 16:23:17 UTC (rev 7904)
@@ -22,7 +22,6 @@
 import java.lang.reflect.Method;
 
 import com.xpn.xwiki.it.framework.XWikiLDAPTestSetup;
-import com.xpn.xwiki.test.XWikiTestSetup;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -63,7 +62,6 @@
         addTestCaseSuite(suite, LDAPAuthTest.class);
 
         return new XWikiLDAPTestSetup(suite);
-        //return new XWikiTestSetup(suite);
     }
 
     private static void addTestCase(TestSuite suite, Class testClass) throws 
Exception

Modified: 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/LDAPAuthTest.java
===================================================================
--- 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/LDAPAuthTest.java
   2008-02-21 16:04:57 UTC (rev 7903)
+++ 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/LDAPAuthTest.java
   2008-02-21 16:23:17 UTC (rev 7904)
@@ -38,7 +38,7 @@
 
         clickLogin();
     }
-    
+
     /**
      * Validate that it tries to log as "common" XWiki login if user is not 
found in LDAP.
      */
@@ -51,4 +51,19 @@
 
         assertTrue("Admin user has not been authenticated", isAuthenticated());
     }
+
+    /**
+     * Validate that it success to authenticate with LDAP user.
+     * Also the user id contains space character.
+     */
+    public void testLogAsLDAPUser()
+    {
+        setFieldValue("j_username", XWikiLDAPTestSetup.HORATIOHORNBLOWER_UID);
+        setFieldValue("j_password", XWikiLDAPTestSetup.HORATIOHORNBLOWER_PWD);
+        checkField("rememberme");
+        submit();
+
+        assertTrue(XWikiLDAPTestSetup.HORATIOHORNBLOWER_UID + " user has not 
been authenticated",
+            isAuthenticated());
+    }
 }

Modified: 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
===================================================================
--- 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
        2008-02-21 16:04:57 UTC (rev 7903)
+++ 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
        2008-02-21 16:23:17 UTC (rev 7904)
@@ -1,25 +1,48 @@
 package com.xpn.xwiki.it;
 
+import java.text.MessageFormat;
+
 import junit.framework.TestCase;
 
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiConfig;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.it.framework.XWikiLDAPTestSetup;
+import com.xpn.xwiki.plugin.ldap.XWikiLDAPConfig;
 import com.xpn.xwiki.plugin.ldap.XWikiLDAPConnection;
+import com.xpn.xwiki.web.XWikiEngineContext;
 
 /**
- * Tests [EMAIL PROTECTED] XWikiLDAPConnectionTest}.
+ * Tests [EMAIL PROTECTED] XWikiLDAPConnection}.
  * 
  * @version $Id: $
  */
 public class XWikiLDAPConnectionTest extends TestCase
 {
     /**
+     * The XWiki context.
+     */
+    private XWikiContext context;
+
+    /**
      * [EMAIL PROTECTED]
-     *
+     * 
      * @see junit.framework.TestCase#setUp()
      */
     public void setUp() throws Exception
     {
+        this.context = new XWikiContext();
 
+        new XWiki(XWikiLDAPTestSetup.CURRENTXWIKICONF, this.context)
+        {
+            public void initXWiki(XWikiConfig config, XWikiContext context,
+                XWikiEngineContext enginecontext, boolean noupdate) throws 
XWikiException
+            {
+                context.setWiki(this);
+                setConfig(config);
+            }
+        };
     }
 
     /**
@@ -39,8 +62,22 @@
     }
 
     /**
+     * Test open and close of the LDAP connection using xwiki.cfg parameters.
+     */
+    public void testOpen2Close()
+    {
+        XWikiLDAPConnection connection = new XWikiLDAPConnection();
+
+        assertTrue("LDAP connection failed", connection.open(
+            XWikiLDAPTestSetup.HORATIOHORNBLOWER_UID, 
XWikiLDAPTestSetup.HORATIOHORNBLOWER_PWD,
+            this.context));
+
+        connection.close();
+    }
+
+    /**
      * [EMAIL PROTECTED]
-     *
+     * 
      * @see junit.framework.TestCase#tearDown()
      */
     public void tearDown() throws Exception

Modified: 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
===================================================================
--- 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
     2008-02-21 16:04:57 UTC (rev 7903)
+++ 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
     2008-02-21 16:23:17 UTC (rev 7904)
@@ -53,7 +53,7 @@
     {
         this.context = new XWikiContext();
 
-        new XWiki(new XWikiConfig(), this.context)
+        new XWiki(XWikiLDAPTestSetup.CURRENTXWIKICONF, this.context)
         {
             private XWikiCacheService cacheService;
 

Modified: 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
===================================================================
--- 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
   2008-02-21 16:04:57 UTC (rev 7903)
+++ 
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
   2008-02-21 16:23:17 UTC (rev 7904)
@@ -18,6 +18,7 @@
 
 import junit.framework.Test;
 
+import com.xpn.xwiki.XWikiConfig;
 import com.xpn.xwiki.test.XWikiTestSetup;
 
 /**
@@ -39,7 +40,7 @@
     /**
      * The name of the LDAP property containing user unique id.
      */
-    public static final String LDAP_USERUID_FIELD = "uid";
+    public static final String LDAP_USERUID_FIELD = "cn";
 
     /**
      * The name of the system property containing the LDAP embedded server 
port.
@@ -74,7 +75,7 @@
     /**
      * The LDAP unique id of user Horatio Hornblower.
      */
-    public static final String HORATIOHORNBLOWER_UID = "hhornblo";
+    public static final String HORATIOHORNBLOWER_UID = "Horatio Hornblower";
 
     /**
      * The LDAP DN of group HMS Lydia.
@@ -93,6 +94,11 @@
         HMSLYDIA_MEMBERS.add("cn=Moultrie Crystal,ou=people,o=sevenSeas");
     }
 
+    /**
+     * The xwiki.cfg properties modified for the test.
+     */
+    public static XWikiConfig CURRENTXWIKICONF;
+    
     // ///
 
     /**
@@ -106,11 +112,6 @@
     private Properties initialXWikiConf;
 
     /**
-     * The xwiki.cfg properties modified for the test.
-     */
-    private Properties currentXWikiConf;
-
-    /**
      * @return return the port of the current instance of LDAP server.
      */
     public static int getLDAPPort()
@@ -130,35 +131,35 @@
         fis.close();
 
         fis = new FileInputStream(XWIKI_CFG_FILE);
-        this.currentXWikiConf = new Properties();
-        this.currentXWikiConf.load(fis);
+        CURRENTXWIKICONF = new XWikiConfig();
+        CURRENTXWIKICONF.load(fis);
         fis.close();
 
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap", "1");
-        this.currentXWikiConf.setProperty("xwiki.authentication.authclass",
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap", "1");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.authclass",
             "com.xpn.xwiki.user.impl.LDAP.XWikiLDAPAuthServiceImpl");
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap.server", 
"localhost");
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap.base_DN", 
"o=sevenSeas");
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap.bind_DN",
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.server", 
"localhost");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.base_DN", 
"o=sevenSeas");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.bind_DN",
             "cn={0},ou=people,o=sevenSeas");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.bind_pass", "{1}");
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap.UID_attr",
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.bind_pass", 
"{1}");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.UID_attr",
             LDAP_USERUID_FIELD);
-        this.currentXWikiConf
-            .setProperty("xwiki.authentication.ldap.fields_mapping",
-                
"name=uid,last_name=sn,first_name=givenname,fullname=description,email=mail,ldap_dn=dn");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.group_mapping",
+        
CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.fields_mapping", "name="
+            + LDAP_USERUID_FIELD
+            + 
",last_name=sn,first_name=givenname,fullname=description,email=mail,ldap_dn=dn");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.group_mapping",
             "XWiki.XWikiAdminGroup=cn=HMS 
Lydia,ou=crews,ou=groups,o=sevenSeas");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.groupcache_expiration",
+        
CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.groupcache_expiration",
             "21800");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.user_group",
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.user_group",
             "cn=HMS Lydia,ou=crews,ou=groups,o=sevenSeas");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.validate_password",
 "0");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.update_user", "1");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.trylocal", "1");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.mode_group_sync", 
"always");
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap.ssl", 
"0");
-        
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.ssl.keystore", "");
+        
CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.validate_password", 
"0");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.update_user", 
"1");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.trylocal", 
"1");
+        
CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.mode_group_sync", 
"always");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.ssl", "0");
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.ssl.keystore", 
"");
     }
 
     /**
@@ -171,10 +172,10 @@
         this.ldap.start();
 
         System.setProperty(SYSPROPNAME_LDAPPORT, "" + ldap.getPort());
-        this.currentXWikiConf.setProperty("xwiki.authentication.ldap.port", "" 
+ ldap.getPort());
+        CURRENTXWIKICONF.setProperty("xwiki.authentication.ldap.port", "" + 
ldap.getPort());
 
         FileOutputStream fos = new FileOutputStream(XWIKI_CFG_FILE);
-        this.currentXWikiConf.store(fos, null);
+        CURRENTXWIKICONF.store(fos, null);
         fos.close();
 
         super.setUp();

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to