mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
Compare commits
51 Commits
feat/add-t
...
refactorin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25a02ebbda | ||
|
|
f7cba6dd2c | ||
|
|
132c836777 | ||
|
|
1238920b60 | ||
|
|
8fc9fb87fb | ||
|
|
b6407e049e | ||
|
|
a1b7a98ae1 | ||
|
|
37b8c03e33 | ||
|
|
473a968d75 | ||
|
|
c3ea4f5ee6 | ||
|
|
c965aba61d | ||
|
|
2f9f0ee50d | ||
|
|
4c6cf9f2d4 | ||
|
|
ae763187b9 | ||
|
|
a5deb30abb | ||
|
|
a3cff2099f | ||
|
|
d37c616d3d | ||
|
|
3885013829 | ||
|
|
63f33bff83 | ||
|
|
562858c9df | ||
|
|
a58b05214f | ||
|
|
703384445b | ||
|
|
a02419e229 | ||
|
|
ea5e76e8c8 | ||
|
|
72a8b15ac8 | ||
|
|
eb6f7a5870 | ||
|
|
3b8adf3b6a | ||
|
|
5a7c7c9df9 | ||
|
|
3426ea4e26 | ||
|
|
ffb1e556b1 | ||
|
|
b2d7b3e686 | ||
|
|
93e70e8d9f | ||
|
|
e9ec3d6734 | ||
|
|
e2944b1794 | ||
|
|
6c7d414a64 | ||
|
|
631d4c7fd0 | ||
|
|
fbde1aab00 | ||
|
|
ee09913cea | ||
|
|
a51b073692 | ||
|
|
f6ca964ff8 | ||
|
|
545e751d33 | ||
|
|
87c5f2a284 | ||
|
|
23f993e2e5 | ||
|
|
ddb522a8d3 | ||
|
|
2ee792d088 | ||
|
|
bccf9f5fbf | ||
|
|
7a84f42d5c | ||
|
|
40a3f61532 | ||
|
|
4253272154 | ||
|
|
fb402eb9c8 | ||
|
|
0c9b3d5fbe |
186
.github/workflows/deploy.yml
vendored
186
.github/workflows/deploy.yml
vendored
@@ -894,3 +894,189 @@ jobs:
|
||||
run: |
|
||||
echo "Pull request:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "[[#${{ fromJSON(steps.pull_request.outputs.data)[0].number }}] ${{ fromJSON(steps.pull_request.outputs.data)[0].title }}](${{ fromJSON(steps.pull_request.outputs.data)[0].html_url }})" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Test-Linux:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'desktop'
|
||||
arch: 'linux_gcc_64'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
set-env: 'true'
|
||||
|
||||
- name: 'Install dependencies'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
cmake \
|
||||
ninja-build \
|
||||
libsecret-1-dev \
|
||||
libxcb-cursor0 \
|
||||
libxkbcommon-x11-0 \
|
||||
libxcb-xinerama0 \
|
||||
libxcb-icccm4 \
|
||||
libxcb-image0 \
|
||||
libxcb-keysyms1 \
|
||||
libxcb-randr0 \
|
||||
libxcb-render-util0 \
|
||||
libxcb-xfixes0 \
|
||||
libxcb-shape0 \
|
||||
libxcb-sync1 \
|
||||
libxcb-xkb1 \
|
||||
libgl1 \
|
||||
libglib2.0-0
|
||||
|
||||
- name: 'Configure'
|
||||
run: |
|
||||
cmake -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_TESTING=ON
|
||||
|
||||
- name: 'Build'
|
||||
run: cmake --build build
|
||||
|
||||
- name: 'Run tests'
|
||||
run: |
|
||||
QT_ROOT=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/gcc_64
|
||||
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\
|
||||
$QT_ROOT/lib:\
|
||||
$PWD/client/3rd-prebuilt/deploy-prebuilt/linux/x64
|
||||
|
||||
export QT_QPA_PLATFORM=offscreen
|
||||
|
||||
ctest --test-dir build/client --output-on-failure
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Test-Windows:
|
||||
runs-on: windows-latest
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'windows'
|
||||
target: 'desktop'
|
||||
arch: 'win64_msvc2022_64'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
set-env: 'true'
|
||||
|
||||
- name: 'Setup MSVC'
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
with:
|
||||
arch: 'x64'
|
||||
|
||||
- name: 'Install dependencies'
|
||||
shell: bash
|
||||
run: |
|
||||
choco install ninja -y
|
||||
|
||||
- name: 'Configure'
|
||||
shell: cmd
|
||||
run: |
|
||||
cmake -B build -G Ninja ^
|
||||
-DCMAKE_BUILD_TYPE=Release ^
|
||||
-DBUILD_TESTING=ON
|
||||
|
||||
- name: 'Build'
|
||||
shell: cmd
|
||||
run: cmake --build build --config Release
|
||||
|
||||
- name: 'Deploy Qt dependencies'
|
||||
shell: cmd
|
||||
run: |
|
||||
for %%f in (build\client\test_*.exe) do (windeployqt %%f)
|
||||
|
||||
- name: 'Run tests'
|
||||
shell: cmd
|
||||
run: |
|
||||
set PATH=%PATH%;%CD%\client\3rd-prebuilt\deploy-prebuilt\windows\x64
|
||||
set PATH=%PATH%;%Qt6_DIR%\..\..\..\bin
|
||||
ctest --test-dir build\client --output-on-failure
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Test-MacOS:
|
||||
runs-on: macos-latest
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
|
||||
steps:
|
||||
- name: 'Setup xcode'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: '16.2.0'
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'mac'
|
||||
target: 'desktop'
|
||||
arch: 'clang_64'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
set-env: 'true'
|
||||
|
||||
- name: 'Install dependencies'
|
||||
run: |
|
||||
brew update
|
||||
brew install cmake ninja
|
||||
|
||||
- name: 'Configure'
|
||||
run: |
|
||||
cmake -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_TESTING=ON
|
||||
|
||||
- name: 'Build'
|
||||
run: cmake --build build
|
||||
|
||||
- name: 'Run tests'
|
||||
run: |
|
||||
QT_ROOT=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos
|
||||
|
||||
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:\
|
||||
$QT_ROOT/lib:\
|
||||
$PWD/client/3rd-prebuilt/deploy-prebuilt/macos
|
||||
|
||||
export QT_QPA_PLATFORM=offscreen
|
||||
|
||||
ctest --test-dir build/client --output-on-failure
|
||||
|
||||
|
||||
@@ -193,6 +193,8 @@ elseif(APPLE)
|
||||
include(cmake/macos.cmake)
|
||||
endif()
|
||||
|
||||
include(CTest)
|
||||
|
||||
if(NOT IOS AND NOT ANDROID AND NOT MACOS_NE)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
@@ -89,6 +89,14 @@ class TestComplexOperations;
|
||||
class TestSettingsSignals;
|
||||
class TestUiServersModelAndController;
|
||||
class TestSelfHostedServerSetup;
|
||||
class TestMultipleExports;
|
||||
class TestSerialization;
|
||||
class TestUiLanguageModelAndController;
|
||||
class TestUiSitesModelAndController;
|
||||
class TestUiAppSTModelAndController;
|
||||
class TestUiAllowedDnsModelAndController;
|
||||
class TestUiNewsModelAndController;
|
||||
class TestUiApiServicesModelAndController;
|
||||
|
||||
class CoreController : public QObject
|
||||
{
|
||||
@@ -106,6 +114,14 @@ class CoreController : public QObject
|
||||
friend class TestSettingsSignals;
|
||||
friend class TestUiServersModelAndController;
|
||||
friend class TestSelfHostedServerSetup;
|
||||
friend class TestMultipleExports;
|
||||
friend class TestSerialization;
|
||||
friend class TestUiLanguageModelAndController;
|
||||
friend class TestUiSitesModelAndController;
|
||||
friend class TestUiAppSTModelAndController;
|
||||
friend class TestUiAllowedDnsModelAndController;
|
||||
friend class TestUiNewsModelAndController;
|
||||
friend class TestUiApiServicesModelAndController;
|
||||
|
||||
public:
|
||||
explicit CoreController(const QSharedPointer<VpnConnection> &vpnConnection, SecureQSettings* settings,
|
||||
|
||||
@@ -4,8 +4,11 @@ project(AmneziaVPN_Tests)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Test)
|
||||
|
||||
include(CTest)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
|
||||
qt6_add_resources(TEST_QRC
|
||||
${CLIENT_ROOT_DIR}/server_scripts/serverScripts.qrc
|
||||
@@ -140,6 +143,69 @@ target_link_libraries(test_self_hosted_server_setup PRIVATE
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_exports
|
||||
testMultipleExports.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_exports PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_serialization
|
||||
testSerialization.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_serialization PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_ui_language_model_and_controller
|
||||
testUiLanguageModelAndController.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ui_language_model_and_controller PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_ui_sites_model_and_controller
|
||||
testUiSitesModelAndController.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ui_sites_model_and_controller PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_ui_app_st_model_and_controller
|
||||
testUiAppSTModelAndController.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ui_app_st_model_and_controller PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_ui_allowed_dns_model_and_controller
|
||||
testUiAllowedDnsModelAndController.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ui_allowed_dns_model_and_controller PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
add_executable(test_ui_api_services_model_and_controller
|
||||
api/testUiApiServicesModelAndController.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ui_api_services_model_and_controller PRIVATE
|
||||
Qt6::Test
|
||||
test_common
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME ImportExportTest COMMAND test_import_export)
|
||||
add_test(NAME MultipleImportsTest COMMAND test_multiple_imports)
|
||||
@@ -153,3 +219,9 @@ add_test(NAME ComplexOperationsTest COMMAND test_complex_operations)
|
||||
add_test(NAME SettingsSignalsTest COMMAND test_settings_signals)
|
||||
add_test(NAME UiServersModelAndControllerTest COMMAND test_ui_servers_model_and_controller)
|
||||
add_test(NAME SelfHostedServerSetupTest COMMAND test_self_hosted_server_setup)
|
||||
add_test(NAME MultipleExportsTest COMMAND test_exports)
|
||||
add_test(NAME SerializationTest COMMAND test_serialization)
|
||||
add_test(NAME UiLanguageModelAndControllerTest COMMAND test_ui_language_model_and_controller)
|
||||
add_test(NAME UiSitesModelAndControllerTest COMMAND test_ui_sites_model_and_controller)
|
||||
add_test(NAME UiAppSTModelAndControllerTest COMMAND test_ui_app_st_model_and_controller)
|
||||
add_test(NAME UiAllowedDnsModelAndControllerTest COMMAND test_ui_allowed_dns_model_and_controller)
|
||||
|
||||
97
client/tests/api/testUiApiServicesModelAndController.cpp
Normal file
97
client/tests/api/testUiApiServicesModelAndController.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
#include <QUuid>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestUiApiServicesModelAndController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
// TODO: add env vars for api
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testRolesAndSignals()
|
||||
{
|
||||
QSignalSpy errorOccurredSpy(m_coreController->m_servicesCatalogUiController, &ServicesCatalogUiController::errorOccurred);
|
||||
|
||||
/* TODO:
|
||||
m_coreController->m_servicesCatalogUiController->fillAvailableServices();
|
||||
QVERIFY(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
|
||||
QModelIndex serviceModelIndex = m_coreController->m_apiServicesModel->index(0, 0);
|
||||
QVERIFY2(serviceModelIndex.isValid(), "Service model index should be valid");
|
||||
|
||||
auto serviceName = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::NameRole);
|
||||
QCOMPARE(serviceName, );
|
||||
|
||||
auto serviceCardDescription = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::CardDescriptionRole);
|
||||
QCOMPARE(serviceCardDescription, );
|
||||
|
||||
auto isServiceAvailable = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::IsServiceAvailableRole);
|
||||
QCOMPARE(isServiceAvailable, );
|
||||
|
||||
auto serviceSpeed = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::SpeedRole);
|
||||
QCOMPARE(serviceSpeed, );
|
||||
|
||||
auto serviceTimeLimit = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::TimeLimitRole);
|
||||
QCOMPARE(serviceTimeLimit, );
|
||||
|
||||
auto serviceRegion = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::RegionRole);
|
||||
QCOMPARE(serviceRegion, );
|
||||
|
||||
auto serviceFeatures = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::FeaturesRole);
|
||||
QCOMPARE(serviceFeatures, );
|
||||
|
||||
auto servicePrice = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::PriceRole);
|
||||
QCOMPARE(servicePrice, );
|
||||
|
||||
auto serviceEndDate = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::EndDateRole);
|
||||
QCOMPARE(serviceEndDate, );
|
||||
|
||||
auto serviceOrder = m_coreController->m_apiServicesModel->data(serviceModelIndex, ApiServicesModel::OrderRole);
|
||||
QCOMPARE(serviceOrder, );
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestUiApiServicesModelAndController)
|
||||
#include "testUiApiServicesModelAndController.moc"
|
||||
97
client/tests/api/testUiNewsModelAndController.cpp
Normal file
97
client/tests/api/testUiNewsModelAndController.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
#include <QUuid>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestUiNewsModelAndController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
// TODO: add env vars for api
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testRolesAndSignals()
|
||||
{
|
||||
QSignalSpy fetchNewsFinishedSpy(m_coreController->m_apiNewsUiController, &ApiNewsUiController::fetchNewsFinished);
|
||||
QSignalSpy errorOccurredSpy(m_coreController->m_apiNewsUiController, &ApiNewsUiController::errorOccurred);
|
||||
QSignalSpy processedIndexChangedSpy(m_coreController->m_newsModel, &NewsModel::processedIndexChanged);
|
||||
QSignalSpy hasUnreadChangedSpy(m_coreController->m_newsModel, &NewsModel::hasUnreadChanged);
|
||||
|
||||
/* TODO:
|
||||
m_coreController->m_apiNewsUiController->fetchNews(false);
|
||||
QVERIFY(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
QVERIFY(fetchNewsFinishedSpy.count() == 1, "fetchNewsFinished signal should be emitted");
|
||||
|
||||
m_coreController->m_newsModel->updateModel();
|
||||
QVERIFY(hasUnreadChangedSpy.count() == 1, "hasUnreadChanged signal should be emitted");
|
||||
|
||||
QModelIndex newsModelIndex = m_coreController->m_newsModel->index(0, 0);
|
||||
QVERIFY2(newsModelIndex.isValid(), "News model index should be valid");
|
||||
|
||||
auto newsId = m_coreController->m_newsModel->data(newsModelIndex, NewsModel::IdRole);
|
||||
QCOMPARE(newsId, );
|
||||
|
||||
auto newsTitle = m_coreController->m_newsModel->data(newsModelIndex, NewsModel::TitleRole);
|
||||
QCOMPARE(newsTitle, );
|
||||
|
||||
auto newsContent = m_coreController->m_newsModel->data(newsModelIndex, NewsModel::ContentRole);
|
||||
QCOMPARE(newsContent, );
|
||||
|
||||
auto newsTimestamp = m_coreController->m_newsModel->data(newsModelIndex, NewsModel::TimestampRole);
|
||||
QCOMPARE(newsTimestamp, );
|
||||
|
||||
auto newsIsRead = m_coreController->m_newsModel->data(newsModelIndex, NewsModel::IsReadRole);
|
||||
QCOMPARE(newsIsRead, false);
|
||||
|
||||
auto newsIsProcessed = m_coreController->m_newsModel->data(newsModelIndex, NewsModel::IsProcessedRole);
|
||||
QCOMPARE(newsIsProcessed, );
|
||||
|
||||
m_coreController->m_newsModel->markAsRead(0);
|
||||
? m_coreController->m_newsModel->updateModel(); ?
|
||||
QVERIFY(hasUnreadChangedSpy.count() == 2, "hasUnreadChanged signal should be emitted");
|
||||
QCOMPARE(newsIsRead, true);
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestUiNewsModelAndController)
|
||||
#include "testUiNewsModelAndController.moc"
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
@@ -6,6 +5,7 @@
|
||||
#include <QDebug>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -20,6 +20,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
QJsonObject decodeVpnKey(const QString &vpnKey) {
|
||||
QString key = vpnKey;
|
||||
key.replace("vpn://", "");
|
||||
@@ -97,7 +103,7 @@ private slots:
|
||||
}
|
||||
|
||||
void testAdminSelfHostedExport() {
|
||||
QString vpnKey = "vpn://AAABTXjarZIxT8MwEIX_Cro5jbDjQunKUhhYyoZQZZKjRGpsy3baQtT_zp2bJh3oACLLPfvz3bOe00FpTdS1QR9g_tKB3q1h3sFCwBzEdf9N5ElBBgtJqBiQOkcFoemAbs6RInQ7oNkZemAvrrKvRV9VX6fH-lhSVSwavU9GSdcmXZX0UqSbseJRMqlioDxuSsJZH1mKWTrhvI22tJvVljKoLU-TtB3aN4NxpavKYwhpSD7LRc4t0WsTeMwqNRNsKweHbAyTtnRj8KvWE0pUEut-hNah2TpDM0-Kwu8vKMSd-ttFLrntao_rVvuKWkc9OnIk4n8t915_Ulcqo5FSxa9tYsk2rxlU-K7bTby_lDWfCKWvXTy-5jOGeLVET-9L7MOG-KQbJEBx57jXjdtgXtqG_wUdws5yJhCpa1iefhopM2gD-n4An-ElHL4BvzD6nw";
|
||||
QString vpnKey = getValueFromIni("configs/TEST_CONFIG_ANY");
|
||||
|
||||
QSignalSpy importFinishedSpy(m_coreController->m_importCoreController, &ImportController::importFinished);
|
||||
QSignalSpy defaultServerChangedSpy(m_coreController->m_serversRepository, &SecureServersRepository::defaultServerChanged);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -19,6 +19,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -42,9 +48,9 @@ private slots:
|
||||
}
|
||||
|
||||
void testComplexOperationSequence() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString wgKey = "vpn://AAAAwXjahY89a8NADIb_StDsHLFDIHjt0C1LhgwlBNWnpgfx3SHp6hDj_15dacnYTS_Po68ZhhQVQyQW6N_mZ4QecIz0CLieAtO1IHto4Fn3M-TEat6u3XetMSnvkfSC3jOJjYN24_audRtjyhil-pfMSZPB4jMsy7kBTx9Ybvryz2ZPMnDIGlI042TktZLVkfjLmhr4TKIHHMnodHV0xzHfyA1pNJZRZEr1alAS_Yvbin6e6LoGihD_DqhSjbB8AyB_ZI8";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_WG");
|
||||
QString wgKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
QSignalSpy importFinishedSpy(m_coreController->m_importCoreController, &ImportController::importFinished);
|
||||
QSignalSpy serverAddedSpy(m_coreController->m_serversRepository, &SecureServersRepository::serverAdded);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -20,6 +20,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -44,9 +50,9 @@ private slots:
|
||||
}
|
||||
|
||||
void testSetDefaultServerIndex() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString wgKey = "vpn://AAAAwXjahY89a8NADIb_StDsHLFDIHjt0C1LhgwlBNWnpgfx3SHp6hDj_15dacnYTS_Po68ZhhQVQyQW6N_mZ4QecIz0CLieAtO1IHto4Fn3M-TEat6u3XetMSnvkfSC3jOJjYN24_audRtjyhil-pfMSZPB4jMsy7kBTx9Ybvryz2ZPMnDIGlI042TktZLVkfjLmhr4TKIHHMnodHV0xzHfyA1pNJZRZEr1alAS_Yvbin6e6LoGihD_DqhSjbB8AyB_ZI8";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_WG");
|
||||
QString wgKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
auto importResult1 = m_coreController->m_importCoreController->extractConfigFromData(awgKey);
|
||||
m_coreController->m_importCoreController->importConfig(importResult1.config);
|
||||
@@ -77,9 +83,9 @@ private slots:
|
||||
}
|
||||
|
||||
void testDefaultServerChangeOnRemoveEdgeCases() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString wgKey = "vpn://AAAAwXjahY89a8NADIb_StDsHLFDIHjt0C1LhgwlBNWnpgfx3SHp6hDj_15dacnYTS_Po68ZhhQVQyQW6N_mZ4QecIz0CLieAtO1IHto4Fn3M-TEat6u3XetMSnvkfSC3jOJjYN24_audRtjyhil-pfMSZPB4jMsy7kBTx9Ybvryz2ZPMnDIGlI042TktZLVkfjLmhr4TKIHHMnodHV0xzHfyA1pNJZRZEr1alAS_Yvbin6e6LoGihD_DqhSjbB8AyB_ZI8";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_WG");
|
||||
QString wgKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
auto importResult1 = m_coreController->m_importCoreController->extractConfigFromData(awgKey);
|
||||
m_coreController->m_importCoreController->importConfig(importResult1.config);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -19,6 +19,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -42,7 +48,7 @@ private slots:
|
||||
}
|
||||
|
||||
void testGatewayStacksRecomputeOnServerOperations() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
|
||||
QSignalSpy gatewayStacksExpandedSpy(m_coreController->m_serversController, &ServersController::gatewayStacksExpanded);
|
||||
QSignalSpy serverAddedSpy(m_coreController->m_serversRepository, &SecureServersRepository::serverAdded);
|
||||
|
||||
130
client/tests/testMultipleExports.cpp
Normal file
130
client/tests/testMultipleExports.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QSignalSpy>
|
||||
#include <QUuid>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestMultipleExports : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
|
||||
QString vpnKey = getValueFromIni("configs/TEST_SELF_HOSTED_CONFIG");
|
||||
QJsonObject importedConfig = m_coreController->m_importCoreController->extractConfigFromData(vpnKey).config;
|
||||
|
||||
m_coreController->m_importCoreController->importConfig(importedConfig);
|
||||
|
||||
qDebug() << "SELF-HOSTED ADMIN SERVER IMPORTED\n";
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
int serverIndex = m_coreController->m_serversRepository->defaultServerIndex();
|
||||
|
||||
for (int containerIndex = 1; containerIndex < 7; ++containerIndex)
|
||||
m_coreController->m_installUiController->clearCachedProfile(serverIndex, containerIndex);
|
||||
|
||||
m_coreController->m_serversController->removeServer(serverIndex);
|
||||
|
||||
qDebug() << "SERVER REMOVED\n";
|
||||
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testMultipleExports()
|
||||
{
|
||||
int serverIndex = m_coreController->m_serversRepository->defaultServerIndex();
|
||||
|
||||
QString clientName = "MultipleExports Test Client";
|
||||
|
||||
for (int containerIndex = 1; containerIndex < 7; ++containerIndex) {
|
||||
|
||||
QString containerName;
|
||||
|
||||
switch (containerIndex) {
|
||||
case 1: containerName = "AwgLegacy"; break;
|
||||
case 2: containerName = "Awg2"; break;
|
||||
case 3: containerName = "WireGuard"; break;
|
||||
case 4: containerName = "OpenVPN"; break;
|
||||
case 5: continue; break; // skipping IPsec
|
||||
case 6: containerName = "XRay"; break;
|
||||
}
|
||||
|
||||
if (!m_coreController->m_containersModel->data(containerIndex, ContainersModel::Roles::IsInstalledRole).toBool()) {
|
||||
qDebug() << QStringLiteral("%1: Not installed").arg(containerName).toUtf8().constData();
|
||||
continue;
|
||||
}
|
||||
|
||||
auto exportResult = m_coreController->m_exportController->generateConnectionConfig(serverIndex, containerIndex, clientName);
|
||||
|
||||
QVERIFY2(exportResult.errorCode == ErrorCode::NoError,
|
||||
QStringLiteral("\n%1: Export should succeed").arg(containerName).toUtf8().constData());
|
||||
QVERIFY2(!exportResult.config.isEmpty(),
|
||||
QStringLiteral("%1: Exported config should not be empty\n").arg(containerName).toUtf8().constData());
|
||||
}
|
||||
}
|
||||
|
||||
void testMultipleExportsNative()
|
||||
{
|
||||
int serverIndex = m_coreController->m_serversRepository->defaultServerIndex();
|
||||
|
||||
QString clientName = "MultipleExports Test Client";
|
||||
|
||||
auto exportResultAwg = m_coreController->m_exportController->generateAwgConfig(serverIndex, clientName);
|
||||
auto exportResultWg = m_coreController->m_exportController->generateWireGuardConfig(serverIndex, clientName);
|
||||
auto exportResultOvpn = m_coreController->m_exportController->generateOpenVpnConfig(serverIndex, clientName);
|
||||
auto exportResultXray = m_coreController->m_exportController->generateXrayConfig(serverIndex, clientName);
|
||||
|
||||
QVERIFY2(exportResultAwg.errorCode == ErrorCode::NoError, "\nAwg (native): Export should succeed");
|
||||
QVERIFY2(exportResultWg.errorCode == ErrorCode::NoError, "\nWg (native): Export should succeed");
|
||||
QVERIFY2(exportResultOvpn.errorCode == ErrorCode::NoError, "\nOvpn (native): Export should succeed");
|
||||
QVERIFY2(exportResultXray.errorCode == ErrorCode::NoError, "\nXray (native): Export should succeed");
|
||||
|
||||
QVERIFY2(!exportResultAwg.config.isEmpty(), "Awg (native): Exported config should not be empty\n");
|
||||
QVERIFY2(!exportResultWg.config.isEmpty(), "Wg (native): Exported config should not be empty\n");
|
||||
QVERIFY2(!exportResultOvpn.config.isEmpty(), "Ovpn (native): Exported config should not be empty\n");
|
||||
QVERIFY2(!exportResultXray.config.isEmpty(), "Xray (native): Exported config should not be empty\n");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestMultipleExports)
|
||||
#include "testMultipleExports.moc"
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QDebug>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -20,6 +20,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -45,9 +51,9 @@ private slots:
|
||||
}
|
||||
|
||||
void testMultipleImports() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString wgKey = "vpn://AAAAwXjahY89a8NADIb_StDsHLFDIHjt0C1LhgwlBNWnpgfx3SHp6hDj_15dacnYTS_Po68ZhhQVQyQW6N_mZ4QecIz0CLieAtO1IHto4Fn3M-TEat6u3XetMSnvkfSC3jOJjYN24_audRtjyhil-pfMSZPB4jMsy7kBTx9Ybvryz2ZPMnDIGlI042TktZLVkfjLmhr4TKIHHMnodHV0xzHfyA1pNJZRZEr1alAS_Yvbin6e6LoGihD_DqhSjbB8AyB_ZI8";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_WG");
|
||||
QString wgKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
QSignalSpy importFinishedSpy(m_coreController->m_importCoreController, &ImportController::importFinished);
|
||||
QSignalSpy defaultServerChangedSpy(m_coreController->m_serversRepository, &SecureServersRepository::defaultServerChanged);
|
||||
@@ -125,8 +131,8 @@ private slots:
|
||||
}
|
||||
|
||||
void testMultipleImportsRemoval() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
QSignalSpy importFinishedSpy(m_coreController->m_importCoreController, &ImportController::importFinished);
|
||||
QSignalSpy defaultServerChangedSpy(m_coreController->m_serversRepository, &SecureServersRepository::defaultServerChanged);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -31,13 +31,19 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
ServerCredentials getCredentialsFromEnv() {
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
QString hostName = env.value("TEST_SERVER_HOST");
|
||||
QString userName = env.value("TEST_SERVER_USER");
|
||||
QString password = env.value("TEST_SERVER_PASSWORD");
|
||||
QString portStr = env.value("TEST_SERVER_PORT", "22");
|
||||
QString hostName = getValueFromIni("secrets/TEST_SERVER_HOST");
|
||||
QString userName = getValueFromIni("secrets/TEST_SERVER_USER");
|
||||
QString password = getValueFromIni("secrets/TEST_SERVER_PASSWORD");
|
||||
QString portStr = getValueFromIni("secrets/TEST_SERVER_PORT");
|
||||
int port = portStr.toInt();
|
||||
|
||||
ServerCredentials credentials;
|
||||
|
||||
285
client/tests/testSerialization.cpp
Normal file
285
client/tests/testSerialization.cpp
Normal file
@@ -0,0 +1,285 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QUuid>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "core/utils/serialization/serialization.h"
|
||||
#include "core/utils/utilities.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestSerialization : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
QJsonObject extractXrayConfig(const QString &data, ConfigTypes configType, const QString &description = "") const
|
||||
{
|
||||
QJsonParseError parserErr;
|
||||
QJsonDocument jsonConf = QJsonDocument::fromJson(data.toLocal8Bit(), &parserErr);
|
||||
|
||||
QJsonObject xrayVpnConfig;
|
||||
xrayVpnConfig[configKey::config] = jsonConf.toJson().constData();
|
||||
QJsonObject lastConfig;
|
||||
lastConfig[configKey::lastConfig] = jsonConf.toJson().constData();
|
||||
lastConfig[configKey::isThirdPartyConfig] = true;
|
||||
|
||||
QJsonObject containers;
|
||||
if (configType == ConfigTypes::ShadowSocks) {
|
||||
containers.insert(configKey::ssxray, QJsonValue(lastConfig));
|
||||
containers.insert(configKey::container, QJsonValue(configKey::amneziaSsxray));
|
||||
} else {
|
||||
containers.insert(configKey::container, QJsonValue(configKey::amneziaXray));
|
||||
containers.insert(configKey::xray, QJsonValue(lastConfig));
|
||||
}
|
||||
|
||||
QJsonArray arr;
|
||||
arr.push_back(containers);
|
||||
|
||||
QString hostName;
|
||||
|
||||
const static QRegularExpression hostNameRegExp("\"address\":\\s*\"([^\"]+)");
|
||||
QRegularExpressionMatch hostNameMatch = hostNameRegExp.match(data);
|
||||
if (hostNameMatch.hasMatch()) {
|
||||
hostName = hostNameMatch.captured(1);
|
||||
}
|
||||
|
||||
QJsonObject config;
|
||||
config[configKey::containers] = arr;
|
||||
config[configKey::defaultContainer] =
|
||||
(configType == ConfigTypes::ShadowSocks) ? configKey::amneziaSsxray : configKey::amneziaXray;
|
||||
if (description.isEmpty()) {
|
||||
config[configKey::description] = m_coreController->m_appSettingsRepository->nextAvailableServerName();
|
||||
} else {
|
||||
config[configKey::description] = description;
|
||||
}
|
||||
config[configKey::hostName] = hostName;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
|
||||
QString vpnKey = getValueFromIni("configs/TEST_SELF_HOSTED_CONFIG");
|
||||
QJsonObject importedConfig = m_coreController->m_importCoreController->extractConfigFromData(vpnKey).config;
|
||||
|
||||
m_coreController->m_importCoreController->importConfig(importedConfig);
|
||||
|
||||
qDebug() << "SELF-HOSTED ADMIN SERVER IMPORTED\n";
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
int serverIndex = m_coreController->m_serversRepository->defaultServerIndex();
|
||||
|
||||
for (int containerIndex = 1; containerIndex < 7; ++containerIndex)
|
||||
m_coreController->m_installUiController->clearCachedProfile(serverIndex, containerIndex);
|
||||
|
||||
m_coreController->m_serversController->removeServer(serverIndex);
|
||||
|
||||
qDebug() << "SERVER REMOVED\n";
|
||||
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testVless()
|
||||
{
|
||||
int serverIndex = m_coreController->m_serversRepository->defaultServerIndex();
|
||||
|
||||
QString clientName = "Test Client (vless (de)serialization)";
|
||||
|
||||
ExportController::ExportResult exportResult = m_coreController->m_exportController->generateXrayConfig(serverIndex, clientName);
|
||||
|
||||
ImportController::ImportResult importResult;
|
||||
|
||||
QString config = exportResult.config;
|
||||
QString prefix;
|
||||
QString errormsg;
|
||||
ConfigTypes configType = ConfigTypes::Invalid;
|
||||
|
||||
if (config.startsWith("vless://")) {
|
||||
configType = ConfigTypes::Xray;
|
||||
importResult.config = extractXrayConfig(
|
||||
Utils::JsonToString(serialization::vless::Deserialize(config, &prefix, &errormsg), QJsonDocument::JsonFormat::Compact),
|
||||
configType, prefix);
|
||||
QVERIFY2(!importResult.config.empty(), "Config shouldn't be empty");
|
||||
} else {
|
||||
QSKIP("Config not starts with vless://");
|
||||
}
|
||||
|
||||
QCOMPARE(importResult.config, config);
|
||||
}
|
||||
|
||||
void testVmessNew()
|
||||
{
|
||||
QString clientName = "Test Client (vmess_new deserialization)";
|
||||
|
||||
ImportController::ImportResult importResult;
|
||||
|
||||
m_coreController->m_importController->extractConfigFromData(getValueFromIni("configs/TEST_CONFIG_VMESS_NEW"));
|
||||
|
||||
QString config = m_coreController->m_importController->getConfig();
|
||||
QString prefix;
|
||||
QString errormsg;
|
||||
ConfigTypes configType = ConfigTypes::Invalid;
|
||||
|
||||
if (config.startsWith("vmess://") && config.contains("@")) {
|
||||
configType = ConfigTypes::Xray;
|
||||
importResult.config = extractXrayConfig(
|
||||
Utils::JsonToString(serialization::vmess_new::Deserialize(config, &prefix, &errormsg), QJsonDocument::JsonFormat::Compact),
|
||||
configType, prefix);
|
||||
QVERIFY2(!importResult.config.empty(), "Config shouldn't be empty");
|
||||
} else {
|
||||
QSKIP("Config not starts with vmess:// or not contain @");
|
||||
}
|
||||
|
||||
QCOMPARE(importResult.config, config);
|
||||
}
|
||||
|
||||
void testVmess()
|
||||
{
|
||||
QString clientName = "Test Client (vmess deserialization)";
|
||||
|
||||
ImportController::ImportResult importResult;
|
||||
|
||||
m_coreController->m_importController->extractConfigFromData(getValueFromIni("configs/TEST_CONFIG_VMESS"));
|
||||
|
||||
QString config = m_coreController->m_importController->getConfig();
|
||||
QString prefix;
|
||||
QString errormsg;
|
||||
ConfigTypes configType = ConfigTypes::Invalid;
|
||||
|
||||
if (config.startsWith("vmess://")) {
|
||||
configType = ConfigTypes::Xray;
|
||||
importResult.config = extractXrayConfig(
|
||||
Utils::JsonToString(serialization::vmess::Deserialize(config, &prefix, &errormsg), QJsonDocument::JsonFormat::Compact),
|
||||
configType, prefix);
|
||||
QVERIFY2(!importResult.config.empty(), "Config shouldn't be empty");
|
||||
} else {
|
||||
QSKIP("Config not starts with vmess://");
|
||||
}
|
||||
|
||||
QCOMPARE(importResult.config, config);
|
||||
}
|
||||
|
||||
void testTrojan()
|
||||
{
|
||||
QString clientName = "Test Client (trojan deserialization)";
|
||||
|
||||
ImportController::ImportResult importResult;
|
||||
|
||||
m_coreController->m_importController->extractConfigFromData(getValueFromIni("configs/TEST_CONFIG_TROJAN"));
|
||||
|
||||
QString config = m_coreController->m_importController->getConfig();
|
||||
QString prefix;
|
||||
QString errormsg;
|
||||
ConfigTypes configType = ConfigTypes::Invalid;
|
||||
|
||||
if (config.startsWith("trojan://")) {
|
||||
configType = ConfigTypes::Xray;
|
||||
importResult.config = extractXrayConfig(
|
||||
Utils::JsonToString(serialization::trojan::Deserialize(config, &prefix, &errormsg), QJsonDocument::JsonFormat::Compact),
|
||||
configType, prefix);
|
||||
QVERIFY2(!importResult.config.empty(), "Config shouldn't be empty");
|
||||
} else {
|
||||
QSKIP("Config not starts with trojan://");
|
||||
}
|
||||
|
||||
QCOMPARE(importResult.config, config);
|
||||
}
|
||||
|
||||
void testSS()
|
||||
{
|
||||
QString clientName = "Test Client (ss deserialization)";
|
||||
|
||||
ImportController::ImportResult importResult;
|
||||
|
||||
m_coreController->m_importController->extractConfigFromData(getValueFromIni("configs/TEST_CONFIG_SS"));
|
||||
|
||||
QString config = m_coreController->m_importController->getConfig();
|
||||
QString prefix;
|
||||
QString errormsg;
|
||||
ConfigTypes configType = ConfigTypes::Invalid;
|
||||
|
||||
if (config.startsWith("ss://") && !config.contains("plugin=")) {
|
||||
configType = ConfigTypes::ShadowSocks;
|
||||
importResult.config = extractXrayConfig(
|
||||
Utils::JsonToString(serialization::ss::Deserialize(config, &prefix, &errormsg), QJsonDocument::JsonFormat::Compact),
|
||||
configType, prefix);
|
||||
QVERIFY2(!importResult.config.empty(), "Config shouldn't be empty");
|
||||
} else {
|
||||
QSKIP("Config not starts with ss:// or contain plugin=");
|
||||
}
|
||||
|
||||
QCOMPARE(importResult.config, config);
|
||||
}
|
||||
|
||||
void testSSd()
|
||||
{
|
||||
QString clientName = "Test Client (ssd deserialization)";
|
||||
|
||||
ImportController::ImportResult importResult;
|
||||
|
||||
m_coreController->m_importController->extractConfigFromData(getValueFromIni("configs/TEST_CONFIG_SSD"));
|
||||
|
||||
QString config = m_coreController->m_importController->getConfig();
|
||||
QString prefix;
|
||||
QString errormsg;
|
||||
ConfigTypes configType = ConfigTypes::Invalid;
|
||||
|
||||
if (config.startsWith("ssd://")) {
|
||||
QStringList tmp;
|
||||
QList<std::pair<QString, QJsonObject>> servers = serialization::ssd::Deserialize(config, &prefix, &tmp);
|
||||
configType = ConfigTypes::ShadowSocks;
|
||||
// Took only first config from list
|
||||
if (!servers.isEmpty()) {
|
||||
importResult.config = extractXrayConfig(servers.first().first, configType);
|
||||
}
|
||||
if (!importResult.config.empty()) {
|
||||
importResult.configType = configType;
|
||||
}
|
||||
QVERIFY2(!importResult.config.empty(), "Config shouldn't be empty");
|
||||
} else {
|
||||
QSKIP("Config not starts with ssd://");
|
||||
}
|
||||
|
||||
QCOMPARE(importResult.config, config);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestSerialization)
|
||||
#include "testSerialization.moc"
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -19,6 +19,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -43,7 +49,7 @@ private slots:
|
||||
}
|
||||
|
||||
void testInvalidIndexOperations() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
|
||||
auto importResult = m_coreController->m_importCoreController->extractConfigFromData(awgKey);
|
||||
m_coreController->m_importCoreController->importConfig(importResult.config);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -20,6 +20,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -44,7 +50,7 @@ private slots:
|
||||
}
|
||||
|
||||
void testServerEditTriggersHandlers() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
|
||||
QSignalSpy importFinishedSpy(m_coreController->m_importCoreController, &ImportController::importFinished);
|
||||
auto importResult = m_coreController->m_importCoreController->extractConfigFromData(awgKey);
|
||||
@@ -75,8 +81,8 @@ private slots:
|
||||
}
|
||||
|
||||
void testServerEditPreservesDefault() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
auto importResult1 = m_coreController->m_importCoreController->extractConfigFromData(awgKey);
|
||||
m_coreController->m_importCoreController->importConfig(importResult1.config);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
@@ -20,6 +20,12 @@ private:
|
||||
CoreController* m_coreController;
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
@@ -43,7 +49,7 @@ private slots:
|
||||
}
|
||||
|
||||
void testServersModelSyncOnOperations() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
|
||||
if (!m_coreController->m_serversModel) {
|
||||
QSKIP("ServersModel not available");
|
||||
@@ -72,9 +78,9 @@ private slots:
|
||||
}
|
||||
|
||||
void testServersModelDefaultIndexSync() {
|
||||
QString awgKey = "vpn://AAABFHjadZBBT4QwEIX_ipkzS2wBJdyMB1cPXvbgwRgyQnclgZa0RTYS_rszXRa52Mt77TfzOu0EldEeG62sg-J9AhxPUEywF1CAuF3WTl4dRLCXhJIVpVuUEMpWdLdFKaH7FeUb9Mx3scpFk0XTRbOLvlSkKZsOz-Gi4BsdRiV_EGEydhwlg0tWynEZmd5Yz1bkoaK3xpvKtOU3_UFjOE3SsRs-tfIl1rVVzoWQOI9FzC3eonYcU4ZmgkPdwxz9fSYdYafVT4M7-lEJ80cEtTri0PrH_2q4wlW26f1lioe3p5uDsjQWoS_j_Ct2ipvGU6zO2PWtiivT8RPQudHYmqBXzl-3Yn2slBEMTtklgYt4C_Mv3ROMwA";
|
||||
QString xrayKey = "vpn://AAAAtXjadY7NCsJADIRfRXKui1YP0qt3L14EkRK7EQt2d0lS_0rf3awonjyFmW-YyQBNDIptIBao9sNPQgXYBXq2OL0zPqCA96kGSJHV6HK5MFP6YyCt0XsmsQqYz9zKzd3MmDIGyek6cdRoUJsE43gowNMJ-4uu_695kobbpG0MBndmTrbEV4sWcI6iG-zIQE47umOXLuSa2BlNKHKL7PMeiX5lmdH79bIsoBfiT0UOZQnjCw_AXRQ";
|
||||
QString wgKey = "vpn://AAAAwXjahY89a8NADIb_StDsHLFDIHjt0C1LhgwlBNWnpgfx3SHp6hDj_15dacnYTS_Po68ZhhQVQyQW6N_mZ4QecIz0CLieAtO1IHto4Fn3M-TEat6u3XetMSnvkfSC3jOJjYN24_audRtjyhil-pfMSZPB4jMsy7kBTx9Ybvryz2ZPMnDIGlI042TktZLVkfjLmhr4TKIHHMnodHV0xzHfyA1pNJZRZEr1alAS_Yvbin6e6LoGihD_DqhSjbB8AyB_ZI8";
|
||||
QString awgKey = getValueFromIni("configs/TEST_CONFIG_AWG");
|
||||
QString xrayKey = getValueFromIni("configs/TEST_CONFIG_WG");
|
||||
QString wgKey = getValueFromIni("configs/TEST_CONFIG_XRAY");
|
||||
|
||||
if (!m_coreController->m_serversModel) {
|
||||
QSKIP("ServersModel not available");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QLocale>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
|
||||
95
client/tests/testUiAllowedDnsModelAndController.cpp
Normal file
95
client/tests/testUiAllowedDnsModelAndController.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QUuid>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestUiAllowedDnsModelAndController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testRolesAndSignals()
|
||||
{
|
||||
QSignalSpy finishedSpy(m_coreController->m_allowedDnsUiController, &AllowedDnsUiController::finished);
|
||||
QSignalSpy errorOccurredSpy(m_coreController->m_allowedDnsUiController, &AllowedDnsUiController::errorOccurred);
|
||||
|
||||
QString ip = "188.40.167.81";
|
||||
|
||||
m_coreController->m_allowedDnsUiController->addDns(ip);
|
||||
m_coreController->m_allowedDnsUiController->updateModel();
|
||||
QVERIFY2(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
QVERIFY2(finishedSpy.count() == 1, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_allowedDnsModel->rowCount() == 1, "AllowedDnsModel should have 1 row");
|
||||
|
||||
QModelIndex allowedDnsModelIndex = m_coreController->m_allowedDnsModel->index(0, 0);
|
||||
QVERIFY2(allowedDnsModelIndex.isValid(), "Site model index should be valid");
|
||||
|
||||
auto dnsIp = m_coreController->m_allowedDnsModel->data(allowedDnsModelIndex, AllowedDnsModel::IpRole);
|
||||
QString msg = QString("dns ip should be %1, got %2").arg(ip, dnsIp.toString());
|
||||
QVERIFY2(dnsIp == ip, msg.toLocal8Bit().constData());
|
||||
|
||||
m_coreController->m_allowedDnsUiController->importDns(getValueFromIni("paths/TEST_DNS_LIST_PATH"), true);
|
||||
m_coreController->m_allowedDnsUiController->updateModel();
|
||||
QVERIFY2(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
QVERIFY2(finishedSpy.count() == 2, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_allowedDnsModel->rowCount() > 1, "AllowedDnsModel should have more than 1 row");
|
||||
|
||||
m_coreController->m_allowedDnsUiController->exportDns(getValueFromIni("paths/TEST_EXPORT_PATH") + "test_dns_export.json");
|
||||
QVERIFY2(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
QVERIFY2(finishedSpy.count() == 3, "finished signal should be emitted");
|
||||
|
||||
m_coreController->m_allowedDnsUiController->removeDns(0);
|
||||
m_coreController->m_allowedDnsUiController->updateModel();
|
||||
QVERIFY2(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
QVERIFY2(finishedSpy.count() == 4, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_allowedDnsModel->rowCount() == 0, "AllowedDnsModel should have 0 rows");
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestUiAllowedDnsModelAndController)
|
||||
#include "testUiAllowedDnsModelAndController.moc"
|
||||
103
client/tests/testUiAppSTModelAndController.cpp
Normal file
103
client/tests/testUiAppSTModelAndController.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QUuid>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestUiAppSTModelAndController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testRolesAndSignals()
|
||||
{
|
||||
QSignalSpy finishedSpy(m_coreController->m_appSplitTunnelingUiController, &AppSplitTunnelingUiController::finished);
|
||||
QSignalSpy errorOccurredSpy(m_coreController->m_appSplitTunnelingUiController, &AppSplitTunnelingUiController::errorOccurred);
|
||||
QSignalSpy isSplitTunnelingChangedSpy(m_coreController->m_appSplitTunnelingUiController, &AppSplitTunnelingUiController::isTunnelingEnabledChanged);
|
||||
|
||||
m_coreController->m_appSplitTunnelingUiController->toggleSplitTunneling(true);
|
||||
QVERIFY2(isSplitTunnelingChangedSpy.count() == 1, "isSplitTunnelingChangedSpy signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_appSplitTunnelingUiController->isTunnelingEnabled() == true, "AppSplitTunneling should be enabled");
|
||||
|
||||
m_coreController->m_appSplitTunnelingUiController->toggleSplitTunneling(false);
|
||||
QVERIFY2(isSplitTunnelingChangedSpy.count() == 2, "isSplitTunnelingChangedSpy signal should be emitted 2nd time");
|
||||
QVERIFY2(m_coreController->m_appSplitTunnelingUiController->isTunnelingEnabled() == false, "AppSplitTunneling should be disabled");
|
||||
|
||||
QString app = getValueFromIni("paths/TEST_APP_PATH");
|
||||
|
||||
m_coreController->m_appSplitTunnelingUiController->addApp(app);
|
||||
m_coreController->m_appSplitTunnelingUiController->updateModel();
|
||||
QVERIFY2(finishedSpy.count() == 1, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_appSplitTunnelingModel->rowCount() == 1, "AppSplitTunnelingModel should have 1 row");
|
||||
|
||||
QModelIndex appSTModelIndex = m_coreController->m_appSplitTunnelingModel->index(0, 0);
|
||||
QVERIFY2(appSTModelIndex.isValid(), "Site model index should be valid");
|
||||
|
||||
auto appPath = m_coreController->m_appSplitTunnelingModel->data(appSTModelIndex, AppSplitTunnelingModel::AppPathRole);
|
||||
QString msg = QString("app path should be %1, got %2").arg(app, appPath.toString());
|
||||
QVERIFY2(app.contains(appPath.toString()) == true, msg.toLocal8Bit().constData());
|
||||
|
||||
auto pkgAppName = m_coreController->m_appSplitTunnelingModel->data(appSTModelIndex, AppSplitTunnelingModel::PackageAppNameRole);
|
||||
QVERIFY2(pkgAppName == true, "app name should be set");
|
||||
|
||||
auto pkgAppIcon = m_coreController->m_appSplitTunnelingModel->data(appSTModelIndex, AppSplitTunnelingModel::PackageAppIconRole);
|
||||
QVERIFY2(pkgAppIcon == true, "app image should be set");
|
||||
|
||||
m_coreController->m_appSplitTunnelingUiController->addApp(app);
|
||||
m_coreController->m_appSplitTunnelingUiController->updateModel();
|
||||
QVERIFY2(errorOccurredSpy.count() == 1, "errorOccurred signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_appSplitTunnelingModel->rowCount() == 1, "AppSplitTunnelingModel should have 3 rows (same app should not be added)");
|
||||
|
||||
m_coreController->m_appSplitTunnelingUiController->removeApp(0);
|
||||
m_coreController->m_appSplitTunnelingUiController->updateModel();
|
||||
QVERIFY2(finishedSpy.count() == 2, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_appSplitTunnelingModel->rowCount() == 0, "AppSplitTunnelingModel should have 0 rows");
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestUiAppSTModelAndController)
|
||||
#include "testUiAppSTModelAndController.moc"
|
||||
91
client/tests/testUiLanguageModelAndController.cpp
Normal file
91
client/tests/testUiLanguageModelAndController.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QUuid>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestUiLanguageModelAndController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testChangeLanguage()
|
||||
{
|
||||
QVERIFY2(m_coreController->m_languageModel->rowCount() > 0, "Language model should not be empty");
|
||||
|
||||
QSignalSpy updateTranslationsSpy(m_coreController->m_languageUiController, &LanguageUiController::updateTranslations);
|
||||
QSignalSpy translationsUpdatedSpy(m_coreController->m_languageUiController, &LanguageUiController::translationsUpdated);
|
||||
|
||||
m_coreController->m_languageUiController->changeLanguage(LanguageSettings::AvailableLanguageEnum::China_cn);
|
||||
QVERIFY2(updateTranslationsSpy.count() == 1, "updateTranslations signal should be emitted");
|
||||
QVERIFY2(translationsUpdatedSpy.count() == 1, "translationsUpdated signal should be emitted");
|
||||
|
||||
m_coreController->m_languageUiController->changeLanguage(LanguageSettings::AvailableLanguageEnum::English);
|
||||
QVERIFY2(updateTranslationsSpy.count() == 2, "updateTranslations signal should be emitted");
|
||||
QVERIFY2(translationsUpdatedSpy.count() == 2, "translationsUpdated signal should be emitted");
|
||||
}
|
||||
|
||||
void testUrl()
|
||||
{
|
||||
m_coreController->m_languageUiController->changeLanguage(LanguageSettings::AvailableLanguageEnum::Russian);
|
||||
QString siteRU = m_coreController->m_languageUiController->getCurrentSiteUrl("test_path");
|
||||
QString docsRU = m_coreController->m_languageUiController->getCurrentDocsUrl("test_path");
|
||||
|
||||
m_coreController->m_languageUiController->changeLanguage(LanguageSettings::AvailableLanguageEnum::English);
|
||||
QString siteEN = m_coreController->m_languageUiController->getCurrentSiteUrl("test_path");
|
||||
QString docsEN = m_coreController->m_languageUiController->getCurrentDocsUrl("test_path");
|
||||
|
||||
QVERIFY2(siteRU != siteEN, "site url's should not be same");
|
||||
QVERIFY2(docsRU != docsEN, "docs url's should not be same");
|
||||
}
|
||||
|
||||
void testLineHeight()
|
||||
{
|
||||
m_coreController->m_languageUiController->changeLanguage(LanguageSettings::AvailableLanguageEnum::Burmese);
|
||||
QVERIFY2(m_coreController->m_languageUiController->getLineHeightAppend() == 10, "line height should be 10");
|
||||
|
||||
m_coreController->m_languageUiController->changeLanguage(LanguageSettings::AvailableLanguageEnum::English);
|
||||
QVERIFY2(m_coreController->m_languageUiController->getLineHeightAppend() == 0, "line height should be 0");
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestUiLanguageModelAndController)
|
||||
#include "testUiLanguageModelAndController.moc"
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <QTest>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
@@ -6,6 +5,7 @@
|
||||
#include <QUuid>
|
||||
#include <QSignalSpy>
|
||||
#include <QModelIndex>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
|
||||
119
client/tests/testUiSitesModelAndController.cpp
Normal file
119
client/tests/testUiSitesModelAndController.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSignalSpy>
|
||||
#include <QUuid>
|
||||
#include <QTest>
|
||||
|
||||
#include "core/controllers/coreController.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "secureQSettings.h"
|
||||
#include "vpnConnection.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class TestUiSitesModelAndController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CoreController *m_coreController;
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
QString getValueFromIni(const QString &key)
|
||||
{
|
||||
QSettings settings("test_vars.ini", QSettings::IniFormat);
|
||||
return settings.value(key).toString();
|
||||
}
|
||||
|
||||
QString normalizeHostname(const QString &hostname) const
|
||||
{
|
||||
QString normalized = hostname;
|
||||
normalized.replace("https://", "");
|
||||
normalized.replace("http://", "");
|
||||
normalized.replace("ftp://", "");
|
||||
normalized = normalized.split("/", Qt::SkipEmptyParts).first();
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
||||
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
||||
|
||||
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
||||
|
||||
m_coreController = new CoreController(vpnConnection, m_settings, nullptr, this);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
delete m_coreController;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
if (m_coreController->m_serversModel) {
|
||||
m_coreController->m_serversModel->updateModel(QVector<ServerConfig>(), -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void testRolesAndSignals()
|
||||
{
|
||||
QSignalSpy finishedSpy(m_coreController->m_sitesUiController, &SitesUiController::finished);
|
||||
QSignalSpy errorOccurredSpy(m_coreController->m_sitesUiController, &SitesUiController::errorOccurred);
|
||||
QSignalSpy isSplitTunnelingChangedSpy(m_coreController->m_sitesUiController, &SitesUiController::isTunnelingEnabledChanged);
|
||||
|
||||
m_coreController->m_sitesUiController->toggleSplitTunneling(true);
|
||||
QVERIFY2(isSplitTunnelingChangedSpy.count() == 1, "isSplitTunnelingChangedSpy signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_sitesUiController->isTunnelingEnabled() == true, "SiteSplitTunneling should be enabled");
|
||||
|
||||
m_coreController->m_sitesUiController->toggleSplitTunneling(false);
|
||||
QVERIFY2(isSplitTunnelingChangedSpy.count() == 2, "isSplitTunnelingChangedSpy signal should be emitted 2nd time");
|
||||
QVERIFY2(m_coreController->m_sitesUiController->isTunnelingEnabled() == false, "SiteSplitTunneling should be disabled");
|
||||
|
||||
QString site = "2ip.io";
|
||||
|
||||
m_coreController->m_sitesUiController->addSite(site);
|
||||
m_coreController->m_sitesUiController->addSite("whatismyipaddress.com");
|
||||
m_coreController->m_sitesUiController->updateModel();
|
||||
QVERIFY2(finishedSpy.count() == 2, "finished signal should be emitted 2 times");
|
||||
QVERIFY2(m_coreController->m_sitesModel->rowCount() == 2, "SitesModel should have 2 rows");
|
||||
|
||||
QModelIndex siteModelIndex = m_coreController->m_sitesModel->index(0, 0);
|
||||
QVERIFY2(siteModelIndex.isValid(), "Site model index should be valid");
|
||||
|
||||
auto siteUrl = m_coreController->m_sitesModel->data(siteModelIndex, SitesModel::UrlRole);
|
||||
QCOMPARE(siteUrl, normalizeHostname(site));
|
||||
|
||||
auto siteIp = m_coreController->m_sitesModel->data(siteModelIndex, SitesModel::IpRole);
|
||||
QVERIFY2(siteIp.isNull() == false, "site ip should not be empty");
|
||||
|
||||
m_coreController->m_sitesUiController->removeSite(0);
|
||||
m_coreController->m_sitesUiController->updateModel();
|
||||
QVERIFY2(finishedSpy.count() == 3, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_sitesModel->rowCount() == 1, "SitesModel should have 1 row");
|
||||
|
||||
m_coreController->m_sitesUiController->importSites(getValueFromIni("paths/TEST_SITES_LIST_PATH"), true);
|
||||
m_coreController->m_sitesUiController->updateModel();
|
||||
QVERIFY2(errorOccurredSpy.count() == 0, "errorOccurred signal should not be emitted");
|
||||
QVERIFY2(finishedSpy.count() == 4, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_sitesModel->rowCount() > 1, "SitesModel should have more than 1 row");
|
||||
|
||||
m_coreController->m_sitesUiController->exportSites(getValueFromIni("paths/TEST_EXPORT_PATH") + "test_sites_export.json");
|
||||
QVERIFY2(finishedSpy.count() == 5, "finished signal should be emitted");
|
||||
|
||||
m_coreController->m_sitesUiController->removeSites();
|
||||
m_coreController->m_sitesUiController->updateModel();
|
||||
QVERIFY2(finishedSpy.count() == 6, "finished signal should be emitted");
|
||||
QVERIFY2(m_coreController->m_sitesModel->rowCount() == 0, "SitesModel should have 0 rows");
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestUiSitesModelAndController)
|
||||
#include "testUiSitesModelAndController.moc"
|
||||
23
client/tests/test_vars.ini
Normal file
23
client/tests/test_vars.ini
Normal file
@@ -0,0 +1,23 @@
|
||||
[configs]
|
||||
TEST_SELF_HOSTED_CONFIG = self-hosted_config_string
|
||||
TEST_CONFIG_ANY = any_config_string
|
||||
TEST_CONFIG_AWG = awg_config_string
|
||||
TEST_CONFIG_WG = wg_config_string
|
||||
TEST_CONFIG_XRAY = xray_config_string
|
||||
TEST_CONFIG_VMESS_NEW = vmess_new_config_string
|
||||
TEST_CONFIG_VMESS = vmess_config_string
|
||||
TEST_CONFIG_TROJAN = trojan_config_string
|
||||
TEST_CONFIG_SS = ss_config_string
|
||||
TEST_CONFIG_SSD = ssd_config_string
|
||||
|
||||
[paths]
|
||||
TEST_APP_PATH = path/to/app
|
||||
TEST_SITES_LIST_PATH = path/to/file/with/sites_list
|
||||
TEST_DNS_LIST_PATH = path/to/file/with/dns_list
|
||||
TEST_EXPORT_PATH = path/to/export_directory
|
||||
|
||||
[secrets]
|
||||
TEST_SERVER_HOST = server_host
|
||||
TEST_SERVER_USER = server_user
|
||||
TEST_SERVER_PASSWORD = server_password
|
||||
TEST_SERVER_PORT = 22
|
||||
Reference in New Issue
Block a user