endtoendtestutils.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #pragma once
  15. #include <QObject>
  16. #include <QTemporaryDir>
  17. #include "gui/accountstate.h"
  18. #include "gui/folderman.h"
  19. #include "libsync/account.h"
  20. constexpr auto testUsername = "test";
  21. constexpr auto testPassword = "test";
  22. class QNetworkReply;
  23. namespace OCC
  24. {
  25. class Folder;
  26. class FolderMan;
  27. }
  28. class EndToEndTestCredentials : public OCC::AbstractCredentials
  29. {
  30. Q_OBJECT
  31. public:
  32. explicit EndToEndTestCredentials()
  33. : OCC::AbstractCredentials()
  34. , _user(testUsername)
  35. , _password(testPassword)
  36. {
  37. _wasFetched = true;
  38. };
  39. [[nodiscard]] QString authType() const override { return QStringLiteral("http"); }
  40. [[nodiscard]] QString user() const override { return _user; }
  41. [[nodiscard]] QString password() const override { return _password; }
  42. [[nodiscard]] bool ready() const override { return true; }
  43. bool stillValid(QNetworkReply *) override { return true; }
  44. void askFromUser() override {};
  45. void fetchFromKeychain() override { _wasFetched = true; Q_EMIT fetched(); };
  46. void persist() override {};
  47. void invalidateToken() override {};
  48. void forgetSensitiveData() override {};
  49. [[nodiscard]] QNetworkAccessManager *createQNAM() const override;
  50. private:
  51. QString _user;
  52. QString _password;
  53. };
  54. class EndToEndTestHelper : public QObject
  55. {
  56. Q_OBJECT
  57. public:
  58. EndToEndTestHelper() = default;
  59. ~EndToEndTestHelper() override;
  60. [[nodiscard]] OCC::AccountPtr account() const { return _account; }
  61. [[nodiscard]] OCC::AccountStatePtr accountState() const { return _accountState; }
  62. OCC::Folder *configureSyncFolder(const QString &targetPath = QStringLiteral(""));
  63. signals:
  64. void accountReady(const OCC::AccountPtr &account);
  65. public slots:
  66. void startAccountConfig();
  67. void removeConfiguredAccount();
  68. void removeConfiguredSyncFolder();
  69. private slots:
  70. void slotConnectToNCUrl(const QString &url);
  71. void setupFolderMan();
  72. private:
  73. OCC::AccountPtr _account;
  74. OCC::AccountStatePtr _accountState;
  75. QScopedPointer<OCC::FolderMan> _folderMan;
  76. QTemporaryDir _tempDir;
  77. OCC::Folder* _syncFolder = nullptr;
  78. };