Browse Source

Merge pull request #3602 from nextcloud/bugfix/crashInAccountDavPath

prevent crash in Accont::davPath without credentials
Matthieu Gallien 4 years ago
parent
commit
0569b2bab3
3 changed files with 36 additions and 1 deletions
  1. 1 1
      src/libsync/account.cpp
  2. 1 0
      test/CMakeLists.txt
  3. 34 0
      test/testaccount.cpp

+ 1 - 1
src/libsync/account.cpp

@@ -99,7 +99,7 @@ AccountPtr Account::sharedFromThis()
 
 QString Account::davUser() const
 {
-    return _davUser.isEmpty() ? _credentials->user() : _davUser;
+    return _davUser.isEmpty() && _credentials ? _credentials->user() : _davUser;
 }
 
 void Account::setDavUser(const QString &newDavUser)

+ 1 - 0
test/CMakeLists.txt

@@ -75,6 +75,7 @@ endif()
 
 nextcloud_add_benchmark(LargeSync)
 
+nextcloud_add_test(Account)
 nextcloud_add_test(FolderMan)
 nextcloud_add_test(RemoteWipe)
 

+ 34 - 0
test/testaccount.cpp

@@ -0,0 +1,34 @@
+/*
+ *    This software is in the public domain, furnished "as is", without technical
+ *    support, and with no warranty, express or implied, as to its usefulness for
+ *    any purpose.
+ *
+ */
+
+#include <qglobal.h>
+#include <QTemporaryDir>
+#include <QtTest>
+
+#include "common/utility.h"
+#include "folderman.h"
+#include "account.h"
+#include "accountstate.h"
+#include "configfile.h"
+#include "testhelper.h"
+
+using namespace OCC;
+
+class TestAccount: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void testAccountDavPath_unitialized_noCrash()
+    {
+        AccountPtr account = Account::create();
+        account->davPath();
+    }
+};
+
+QTEST_APPLESS_MAIN(TestAccount)
+#include "testaccount.moc"