File: testupdatechannel.cpp

package info (click to toggle)
nextcloud-desktop 4.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,740 kB
  • sloc: cpp: 119,301; objc: 752; python: 606; ansic: 389; sh: 377; makefile: 44; javascript: 32; xml: 6
file content (115 lines) | stat: -rw-r--r-- 4,115 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * 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 <QStandardPaths>
#include <QTest>

#include "account.h"
#include "accountmanager.h"
#include "configfile.h"
#include "logger.h"
#include "syncenginetestutils.h"
#include "theme.h"

// The goal of this test is to check whether the correct update channel is used when
// multiple accounts are set up.
//
// Note: The behaviour for a branded client isn't tested, because there is no
//       sane way, to have that reported (yet).
//
class TestUpdateChannel : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase()
    {
        OCC::Logger::instance()->setLogFlush(true);
        OCC::Logger::instance()->setLogDebug(true);

        QStandardPaths::setTestModeEnabled(true);
    }

    void testUpdateChannel()
    {
        QScopedPointer<FakeQNAM> fakeQnam(new FakeQNAM({}));

        // Set override for delete operation. This is needed, because by default FakeQNAM results in an
        // error reply, and also requires a filename in the url (which we don't have here).
        fakeQnam->setOverride([this](QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *device) {
            Q_UNUSED(req);
            Q_UNUSED(device);
            QNetworkReply *reply = nullptr;

            if (op == QNetworkAccessManager::DeleteOperation) {
                reply = new FakePayloadReply(op, req, QByteArray(), this);
                return reply;
            }

            return reply;
        });

        {
            auto config = OCC::ConfigFile();
            config.setUpdateChannel(UpdateChannel::Beta.toString());
        }

        {
            auto fakeCreds = new FakeCredentials{fakeQnam.data()};
            fakeCreds->setUserName("Beta");

            auto account = OCC::Account::create();
            account->setCredentials(fakeCreds);
            account->setServerHasValidSubscription(false);
            OCC::AccountManager::instance()->addAccount(account);
        }
        QCOMPARE(OCC::ConfigFile().currentUpdateChannel(), UpdateChannel::Beta.toString());

        {
            auto fakeCreds = new FakeCredentials{fakeQnam.data()};
            fakeCreds->setUserName("EnterpriseStable");

            auto account = OCC::Account::create();
            account->setCredentials(fakeCreds);
            account->setServerHasValidSubscription(true);
            account->setEnterpriseUpdateChannel(UpdateChannel::Stable);
            OCC::AccountManager::instance()->addAccount(account);
        }
        QCOMPARE(OCC::ConfigFile().currentUpdateChannel(), UpdateChannel::Stable.toString());

        {
            auto fakeCreds = new FakeCredentials{fakeQnam.data()};
            fakeCreds->setUserName("EnterpriseEnterprise");

            auto account = OCC::Account::create();
            account->setCredentials(fakeCreds);
            account->setServerHasValidSubscription(true);
            account->setEnterpriseUpdateChannel(UpdateChannel::Enterprise);
            OCC::AccountManager::instance()->addAccount(account);
        }
        QCOMPARE(OCC::ConfigFile().currentUpdateChannel(), UpdateChannel::Enterprise.toString());

        {
            auto account = OCC::AccountManager::instance()->account("EnterpriseEnterprise@");
            QVERIFY(account);
            OCC::AccountManager::instance()->deleteAccount(account.get());
        }
        QCOMPARE(OCC::ConfigFile().currentUpdateChannel(), UpdateChannel::Stable.toString());

        {
            auto account = OCC::AccountManager::instance()->account("EnterpriseStable@");
            QVERIFY(account);
            OCC::AccountManager::instance()->deleteAccount(account.get());
        }
        QCOMPARE(OCC::ConfigFile().currentUpdateChannel(), UpdateChannel::Beta.toString());
    }
};

QTEST_GUILESS_MAIN(TestUpdateChannel)
#include "testupdatechannel.moc"