Branch 'dev/accountwizard_edit' - 2 commits - accountwizard/CMakeLists.txt accountwizard/ldap.cpp accountwizard/ldap.h accountwizard/page.cpp accountwizard/page.h accountwizard/setupmanager.cpp accountwizard/tests libkdepim/ldap

Sandro Knauß knauss at kolabsys.com
Tue Oct 28 13:16:18 CET 2014


 accountwizard/CMakeLists.txt              |    3 
 accountwizard/ldap.cpp                    |   49 +++++++++++++-
 accountwizard/ldap.h                      |   12 +++
 accountwizard/page.cpp                    |    6 +
 accountwizard/page.h                      |    2 
 accountwizard/setupmanager.cpp            |    3 
 accountwizard/tests/CMakeLists.txt        |   14 ++++
 accountwizard/tests/data/ldap.cfg         |   51 +++++++++++++++
 accountwizard/tests/ldaptest.cpp          |  102 ++++++++++++++++++++++++++++++
 libkdepim/ldap/ldapclientsearchconfig.cpp |    8 ++
 libkdepim/ldap/ldapclientsearchconfig.h   |    6 +
 11 files changed, 250 insertions(+), 6 deletions(-)

New commits:
commit 8a66602714829ba045505978ac687f9a85493de5
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue Oct 28 13:12:50 2014 +0100

    Accountwizard: Added destroy option for ldap object.
    
    ldapclientsearchconfig:
    * Do not show the question for storing passwords in KWallet for LDAP
      (need for tests)
    
    * Added test for ldap.destroy function

diff --git a/accountwizard/CMakeLists.txt b/accountwizard/CMakeLists.txt
index bf71af1..2b202ae 100644
--- a/accountwizard/CMakeLists.txt
+++ b/accountwizard/CMakeLists.txt
@@ -82,4 +82,5 @@ install(FILES accountwizard-mime.xml DESTINATION ${XDG_MIME_INSTALL_DIR})
 update_xdg_mimetypes(${XDG_MIME_INSTALL_DIR})
 
 add_subdirectory(wizards)
-add_subdirectory(ispdb)
\ No newline at end of file
+add_subdirectory(ispdb)
+add_subdirectory(tests)
\ No newline at end of file
diff --git a/accountwizard/ldap.cpp b/accountwizard/ldap.cpp
index c5af9af..bdd42cc 100644
--- a/accountwizard/ldap.cpp
+++ b/accountwizard/ldap.cpp
@@ -36,13 +36,21 @@ Ldap::Ldap( QObject *parent )
   , m_sizeLimit(0)
   , m_entry(-1)
   , m_editMode(false)
+  , m_clientSearchConfig(new KLDAP::LdapClientSearchConfig)
 {
 }
 
 Ldap::~Ldap()
 {
+    delete m_clientSearchConfig;
 }
 
+KConfig *Ldap::config() const
+{
+    return m_clientSearchConfig->config();
+}
+
+
 void Ldap::create()
 {
   //TODO: use ldapclientsearchconfig to write config
@@ -82,8 +90,8 @@ void Ldap::create()
   basedn.prepend( QLatin1String("dc=") );
 
   // Set the changes
-  KConfig c( QLatin1String("kabldaprc") );
-  KConfigGroup group = c.group( "LDAP" );
+  KConfig *c = config();
+  KConfigGroup group = c->group( "LDAP" );
   bool hasMyServer = false;
   uint selHosts = group.readEntry( "NumSelectedHosts", 0 );
   for ( uint i = 0 ; i < selHosts && !hasMyServer; ++i ) {
@@ -121,7 +129,7 @@ void Ldap::create()
       group.writeEntry( QString::fromLatin1( "SelectedUser%1" ).arg( selHosts ), m_user );
       group.writeEntry( QString::fromLatin1( "SelectedMech%1" ).arg( selHosts ), m_mech );
     }
-    c.sync();
+    c->sync();
   }
   if (m_editMode) {
       edit();
@@ -145,7 +153,40 @@ QString Ldap::securityString()
 void Ldap::destroy()
 {
   if (m_entry >= 0 ) {
-      //TODO: delete ldap entry
+      KConfig *c = config();
+      KConfigGroup group = c->group( "LDAP" );
+      int cSelHosts = group.readEntry( "NumSelectedHosts", 0 );
+      int cHosts = group.readEntry( "NumHosts", 0 );
+      QList<KLDAP::LdapServer> selHosts;
+      QList<KLDAP::LdapServer> hosts;
+      for(int i=0; i < cSelHosts; i++) {
+          if (i != m_entry) {
+              KLDAP::LdapServer server;
+              m_clientSearchConfig->readConfig(server, group, i, true);
+              selHosts.append(server);
+          }
+      }
+      for(int i=0; i < cHosts; i++) {
+          KLDAP::LdapServer server;
+          m_clientSearchConfig->readConfig(server, group, i, false);
+          hosts.append(server);
+      }
+
+      c->deleteGroup("LDAP");
+      group = KConfigGroup (c, "LDAP");
+
+      for(int i=0; i < cSelHosts - 1; i++) {
+          m_clientSearchConfig->writeConfig(selHosts.at(i), group, i, true);
+      }
+
+      for(int i=0; i < cHosts; i++) {
+          m_clientSearchConfig->writeConfig(hosts.at(i), group, i, false);
+      }
+
+      group.writeEntry( "NumSelectedHosts", cSelHosts - 1);
+      group.writeEntry( "NumHosts", cHosts );
+      c->sync();
+
       emit info(i18n("Removed LDAP entry."));
   }
 }
diff --git a/accountwizard/ldap.h b/accountwizard/ldap.h
index d1f6ab3..fdfd223 100644
--- a/accountwizard/ldap.h
+++ b/accountwizard/ldap.h
@@ -23,6 +23,13 @@
 #include "setupobject.h"
 #include <KLDAP/LdapServer>
 
+class LdapTest;
+class KConfig;
+
+namespace KLDAP {
+    class LdapClientSearchConfig;
+}
+
 class Ldap : public SetupObject
 {
   Q_OBJECT
@@ -49,7 +56,12 @@ class Ldap : public SetupObject
     Q_SCRIPTABLE void setSizeLimit(const int sizeLimit);
     Q_SCRIPTABLE void setEditMode(const bool editMode);
 
+  protected:
+    virtual KConfig *config() const;
+
+    KLDAP::LdapClientSearchConfig *m_clientSearchConfig;
   private:
+    friend LdapTest;
     QString securityString();
 
     QString m_user;
diff --git a/accountwizard/tests/CMakeLists.txt b/accountwizard/tests/CMakeLists.txt
new file mode 100644
index 0000000..5e376a7
--- /dev/null
+++ b/accountwizard/tests/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. )
+add_definitions (-DTEST_DATA_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\"")
+add_definitions (-DCURRENT_SOURCE_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}\\"")
+
+kde4_add_unit_test(ldaptest ldaptest.cpp ../ldap.cpp ../setupobject.cpp)
+
+target_link_libraries(ldaptest
+    ${KDE4_KDECORE_LIBS}
+    ${KDE4_KIO_LIBS}
+    ${KDEPIMLIBS_KMIME_LIBS}
+    ${KDEPIMLIBS_KLDAP_LIBS}
+    ${QT_QTTEST_LIBRARY}
+    kdepim
+  )
\ No newline at end of file
diff --git a/accountwizard/tests/data/ldap.cfg b/accountwizard/tests/data/ldap.cfg
new file mode 100644
index 0000000..dcd43ea
--- /dev/null
+++ b/accountwizard/tests/data/ldap.cfg
@@ -0,0 +1,51 @@
+[LDAP]
+Auth0=Simple
+Base0=dc=example,dc=com
+Bind0=cn=Directory Manager
+Host0=kolab.example.com
+Mech0=DIGEST-MD5
+NumHosts=1
+NumSelectedHosts=3
+PageSize0=0
+Port0=389
+Security0=None
+SelectedAuth0=Simple
+SelectedAuth1=Anonymous
+SelectedAuth2=SASL
+SelectedBase0=dc=lhm,dc=klab,dc=cc
+SelectedBase1=dc=example,dc=com
+SelectedBase2=dc=ldap2,dc=example,dc=com
+SelectedBind0=uid=gotthold.scholz,ou=People,ou=IT,dc=lhm,dc=klab,dc=cc
+SelectedBind1=
+SelectedBind2=cn=Directory
+SelectedHost0=ldap.lhm.klab.cc
+SelectedHost1=example.com
+SelectedHost2=ldap2.example.com
+SelectedMech0=ANONYMOUS
+SelectedMech1=DIGEST-MD5
+SelectedMech2=XXX
+SelectedPageSize0=0
+SelectedPageSize1=0
+SelectedPageSize2=9999999
+SelectedPort0=389
+SelectedPort1=389
+SelectedPort2=387
+SelectedPwdBind2=XXXXXXXXXXXXXXX
+SelectedRealm2=realm.example.com
+SelectedSecurity0=None
+SelectedSecurity1=None
+SelectedSecurity2=SSL
+SelectedSizeLimit0=0
+SelectedSizeLimit1=0
+SelectedTimeLimit0=0
+SelectedTimeLimit1=0
+SelectedUser0=
+SelectedUser1=
+SelectedUser2=john.doe
+SelectedVersion0=3
+SelectedVersion1=3
+SelectedVersion2=3
+SizeLimit0=0
+TimeLimit0=0
+User0=
+Version0=3
diff --git a/accountwizard/tests/ldaptest.cpp b/accountwizard/tests/ldaptest.cpp
new file mode 100644
index 0000000..e06ea2b
--- /dev/null
+++ b/accountwizard/tests/ldaptest.cpp
@@ -0,0 +1,102 @@
+/*
+    Copyright (c) 2014 Sandro Knauß <knauss at kolabsys.com>
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    This library 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 Library General Public
+    License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to the
+    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA.
+*/
+
+#include <QObject>
+#include <QDir>
+#include <qtest_kde.h>
+
+#include <KDebug>
+#include <KConfig>
+#include <KConfigGroup>
+#include <boost/graph/graph_concepts.hpp>
+
+#include <libkdepim/ldap/ldapclientsearchconfig.h>
+#include "../ldap.h"
+
+class TLdap : public Ldap
+{
+public:
+    explicit TLdap(QObject *parent = 0)
+    : Ldap(parent)
+    , fname(QFileInfo(QLatin1String("ldap.cfg")).absoluteFilePath())
+    {
+        s_config = new KConfig(fname, KConfig::SimpleConfig);
+        m_clientSearchConfig->askForWallet(false);
+    }
+
+    virtual KConfig* config() const
+    {
+        s_config->reparseConfiguration();
+        return s_config;
+    }
+
+    QString fname;
+    KConfig *s_config;
+};
+
+class LdapTest : public QObject
+{
+    Q_OBJECT
+private slots:
+    void testDestroy()
+    {
+        TLdap l;
+        QFile::remove(l.fname);
+        QFile::copy(QLatin1String(TEST_DATA_DIR)+QLatin1String("/ldap.cfg"), l.fname);
+        KLDAP::LdapClientSearchConfig csc;
+        csc.askForWallet(false);
+
+        KConfigGroup group = l.config()->group("LDAP");
+        int cSelHosts = group.readEntry( "NumSelectedHosts", 0 );
+        int cHosts = group.readEntry( "NumHosts", 0 );
+        QCOMPARE(cSelHosts, 3);
+        QCOMPARE(cHosts, 1);
+        QList<KLDAP::LdapServer> selHosts;
+        QList<KLDAP::LdapServer> hosts;
+        for(int i=0; i < cSelHosts; i++) {
+            KLDAP::LdapServer server;
+            csc.readConfig(server, group, i, true);
+            selHosts.append(server);
+        }
+        for(int i=0; i < cHosts; i++) {
+          KLDAP::LdapServer server;
+          csc.readConfig(server, group, i, false);
+          hosts.append(server);
+        }
+
+        l.m_entry = 0;
+        l.destroy();
+        group = l.config()->group("LDAP");
+
+        QCOMPARE(group.readEntry( "NumSelectedHosts", 0 ), 2);
+        QCOMPARE(group.readEntry( "NumHosts", 0 ), 1);
+        KLDAP::LdapServer server;
+        csc.readConfig(server, group, 0, false);
+        QCOMPARE(server.host(), hosts.at(0).host());
+
+        csc.readConfig(server, group, 0, true);
+        QCOMPARE(server.host(), selHosts.at(1).host());
+        csc.readConfig(server, group, 1, true);
+        QCOMPARE(server.host(), selHosts.at(2).host());
+    }
+};
+
+QTEST_KDEMAIN(LdapTest, GUI)
+
+#include "ldaptest.moc"
diff --git a/libkdepim/ldap/ldapclientsearchconfig.cpp b/libkdepim/ldap/ldapclientsearchconfig.cpp
index d54ddbc..92c0f7c 100644
--- a/libkdepim/ldap/ldapclientsearchconfig.cpp
+++ b/libkdepim/ldap/ldapclientsearchconfig.cpp
@@ -36,6 +36,7 @@ class LdapClientSearchConfig::Private
 public:
     Private()
         : useWallet( false ),
+          askWallet( true ),
           wallet( 0 )
     {
 
@@ -48,6 +49,7 @@ public:
         }
     }
     bool useWallet;
+    bool askWallet;
     KWallet::Wallet* wallet;
 };
 
@@ -104,7 +106,7 @@ void LdapClientSearchConfig::readConfig( KLDAP::LdapServer &server, KConfigGroup
     const QString pwdBindBNEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j );
     QString pwdBindDN = config.readEntry( pwdBindBNEntry, QString() );
     if ( !pwdBindDN.isEmpty() ) {
-        if ( KMessageBox::Yes == KMessageBox::questionYesNo(0, i18n("LDAP password is stored as clear text, do you want to store it in kwallet?"),
+        if ( d->askWallet && KMessageBox::Yes == KMessageBox::questionYesNo(0, i18n("LDAP password is stored as clear text, do you want to store it in kwallet?"),
                                                             i18n("Store clear text password in KWallet"),
                                                             KStandardGuiItem::yes(),
                                                             KStandardGuiItem::no(),
@@ -229,4 +231,8 @@ void LdapClientSearchConfig::slotWalletClosed()
     d->wallet = 0;
 }
 
+void LdapClientSearchConfig::askForWallet(bool askForWallet)
+{
+    d->askWallet = askForWallet;
+}
 
diff --git a/libkdepim/ldap/ldapclientsearchconfig.h b/libkdepim/ldap/ldapclientsearchconfig.h
index 6725820..456587b 100644
--- a/libkdepim/ldap/ldapclientsearchconfig.h
+++ b/libkdepim/ldap/ldapclientsearchconfig.h
@@ -59,6 +59,12 @@ public:
      */
     void writeConfig( const KLDAP::LdapServer &server, KConfigGroup &group,
                       int clientNumber, bool active );
+
+    /**
+     * Should LdapClientSearchConfig ask, if it should use the KWallet to store passwords
+     */
+    void askForWallet(bool askForWallet);
+
 private Q_SLOTS:
     void slotWalletClosed();
 


commit 6d8a5a0ed8e7d3b2a04fe116a038381be908dd6f
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue Oct 28 12:08:04 2014 +0100

    Accountwizard: Disable back button in last step.

diff --git a/accountwizard/page.cpp b/accountwizard/page.cpp
index 78437d9..ef1f9a4 100644
--- a/accountwizard/page.cpp
+++ b/accountwizard/page.cpp
@@ -50,6 +50,12 @@ void Page::nextPage()
   m_parent->next();
 }
 
+KAssistantDialog * Page::assistantDialog() const
+{
+  return m_parent;
+}
+
+
 void Page::enterPageBack() {}
 void Page::enterPageNext() {}
 void Page::leavePageBack() {}
diff --git a/accountwizard/page.h b/accountwizard/page.h
index 1d229f0..307b3af 100644
--- a/accountwizard/page.h
+++ b/accountwizard/page.h
@@ -40,6 +40,8 @@ class Page : public QWidget
     virtual void leavePageNextRequested();
     virtual void leavePageBackRequested();
 
+    KAssistantDialog *assistantDialog() const;
+
   signals:
     Q_SCRIPTABLE void pageEnteredNext();
     Q_SCRIPTABLE void pageEnteredBack();
diff --git a/accountwizard/setupmanager.cpp b/accountwizard/setupmanager.cpp
index 421362d..1edb126 100644
--- a/accountwizard/setupmanager.cpp
+++ b/accountwizard/setupmanager.cpp
@@ -31,6 +31,7 @@
 
 #include <kemailsettings.h>
 #include <kwallet.h>
+#include <KAssistantDialog>
 
 SetupManager::SetupManager( QWidget* parent) :
   QObject(parent),
@@ -92,6 +93,7 @@ void SetupManager::execute()
 {
   m_page->setStatus( i18n( "Setting up account..." ) );
   m_page->setValid( false );
+  m_page->assistantDialog()->enableButton(KDialog::User3, false);
 
   // ### FIXME this is a bad over-simplification and would need a real topological sort
   // but for current usage it is good enough
@@ -139,6 +141,7 @@ void SetupManager::setupNext()
     m_page->setStatus( i18n( "Setup complete." ) );
     m_page->setProgress( 100 );
     m_page->setValid( true );
+    m_page->assistantDialog()->enableButton(KDialog::User3, false);
   } else {
     const int setupObjectCount = m_objectToSetup.size() + m_setupObjects.size();
     const int remainingObjectCount = setupObjectCount - m_objectToSetup.size();




More information about the commits mailing list