2019-03-08 21:12:39 +08:00
|
|
|
/*
|
|
|
|
Copyright © 2019 by The qTox Project Contributors
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
#include "mock/mockbootstraplistgenerator.h"
|
2019-03-08 21:12:39 +08:00
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/core/toxoptions.h"
|
|
|
|
#include "src/core/icoresettings.h"
|
|
|
|
#include "src/net/bootstrapnodeupdater.h"
|
2020-05-02 13:05:43 +08:00
|
|
|
#include "src/model/ibootstraplistgenerator.h"
|
2022-02-17 23:27:41 +08:00
|
|
|
#include "src/persistence/settings.h"
|
2022-02-27 12:02:40 +08:00
|
|
|
#include "mock/mockcoresettings.h"
|
2019-03-08 21:12:39 +08:00
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
2019-03-17 07:05:41 +08:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <limits>
|
2019-03-08 21:12:39 +08:00
|
|
|
#include <QSignalSpy>
|
2022-02-17 23:27:41 +08:00
|
|
|
|
2019-03-08 21:12:39 +08:00
|
|
|
#include <iostream>
|
2022-02-17 23:27:41 +08:00
|
|
|
#include <memory>
|
2019-03-08 21:12:39 +08:00
|
|
|
|
2020-04-13 16:06:30 +08:00
|
|
|
Q_DECLARE_METATYPE(QList<DhtServer>)
|
2019-03-08 21:12:39 +08:00
|
|
|
|
2022-02-26 06:11:01 +08:00
|
|
|
class TestCoreProxy : public QObject
|
2019-03-08 21:12:39 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
|
|
void startup_without_proxy();
|
2022-03-13 17:49:45 +08:00
|
|
|
void startup_with_invalid_socks5_proxy();
|
|
|
|
void startup_with_invalid_http_proxy();
|
2019-03-08 21:12:39 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/* Test Variables */
|
|
|
|
Core::ToxCoreErrors* err = nullptr;
|
2022-03-13 17:49:45 +08:00
|
|
|
MockSettings settings;
|
|
|
|
ToxCorePtr alice;
|
|
|
|
ToxCorePtr bob;
|
|
|
|
MockBootstrapListGenerator alicesNodes{};
|
|
|
|
MockBootstrapListGenerator bobsNodes{};
|
2019-03-08 21:12:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2022-03-13 17:49:45 +08:00
|
|
|
const int timeout = 15000;
|
2019-03-08 21:12:39 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
void bootstrapToxes(Core& alice, MockBootstrapListGenerator& alicesNodes,
|
|
|
|
Core& bob, MockBootstrapListGenerator& bobsNodes)
|
2019-03-08 21:12:39 +08:00
|
|
|
{
|
2022-03-13 17:49:45 +08:00
|
|
|
alicesNodes.setBootstrapNodes(MockBootstrapListGenerator::makeListFromSelf(bob));
|
|
|
|
bobsNodes.setBootstrapNodes(MockBootstrapListGenerator::makeListFromSelf(alice));
|
2019-03-08 21:12:39 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
QSignalSpy spyAlice(&alice, &Core::connected);
|
|
|
|
QSignalSpy spyBob(&bob, &Core::connected);
|
2019-03-08 21:12:39 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
alice.start();
|
|
|
|
bob.start();
|
2019-03-08 21:12:39 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(spyAlice.count() == 1 &&
|
|
|
|
spyBob.count() == 1, timeout);
|
2019-03-17 07:05:41 +08:00
|
|
|
}
|
2022-03-13 17:49:45 +08:00
|
|
|
} // namespace
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
void TestCoreProxy::startup_without_proxy()
|
2019-03-17 07:05:41 +08:00
|
|
|
{
|
2022-03-13 17:49:45 +08:00
|
|
|
// No proxy
|
|
|
|
settings.setProxyAddr("");
|
|
|
|
settings.setProxyPort(0);
|
|
|
|
settings.setProxyType(MockSettings::ProxyType::ptNone);
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
alice = Core::makeToxCore({}, settings, alicesNodes, err);
|
|
|
|
bob = Core::makeToxCore({}, settings, bobsNodes, err);
|
|
|
|
QVERIFY(!!alice);
|
|
|
|
QVERIFY(!!bob);
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
bootstrapToxes(*alice, alicesNodes, *bob, bobsNodes);
|
|
|
|
}
|
2020-05-02 13:05:43 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
void TestCoreProxy::startup_with_invalid_socks5_proxy()
|
|
|
|
{
|
|
|
|
settings.setProxyAddr("Test");
|
|
|
|
settings.setProxyPort(9985);
|
|
|
|
settings.setProxyType(MockSettings::ProxyType::ptSOCKS5);
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
alice = Core::makeToxCore({}, settings, alicesNodes, err);
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
QVERIFY(!alice);
|
|
|
|
}
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
void TestCoreProxy::startup_with_invalid_http_proxy()
|
|
|
|
{
|
|
|
|
settings.setProxyAddr("Test");
|
|
|
|
settings.setProxyPort(9985);
|
|
|
|
settings.setProxyType(MockSettings::ProxyType::ptHTTP);
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
alice = Core::makeToxCore({}, settings, alicesNodes, err);
|
2019-03-17 07:05:41 +08:00
|
|
|
|
2022-03-13 17:49:45 +08:00
|
|
|
QVERIFY(!alice);
|
2019-03-08 21:12:39 +08:00
|
|
|
}
|
|
|
|
|
2022-02-26 06:11:01 +08:00
|
|
|
QTEST_GUILESS_MAIN(TestCoreProxy)
|
2019-03-08 21:12:39 +08:00
|
|
|
#include "core_test.moc"
|