mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-12-04 06:01:26 +09:00
* basic tests adaptation * fix: ui servers model and controller test awg config * fix: platforms test builds * build dirs inspection * fix: changed paths for tests and tests artifacts * fix: 'deploy' parent dir * windows ctest configuration and macos dependencies inspection * windows check executable and macos copy openssl libs * windows test executables check and macos copy openssl * changed some path on windows * android apk list * fix: updated android apk path * Verify Android test files * fix: build tests only with AMNEZIA_BUILD_TESTS * fix: copy openssl runtime next to test_openssl_library * fix: awg2 test config and inverted description checks * chore: move run_android_tests.sh to client/tests and drop personal paths * chore: gate tests by option, scope secrets and drop global concurrency in ci * chore: serialized vps test job, scoped secrets, backup secret guard, test data lookup --------- Co-authored-by: MrMirDan <8mirdan8@gmail.com>
101 lines
4.0 KiB
C++
101 lines
4.0 KiB
C++
#include <QUuid>
|
|
#include <QSignalSpy>
|
|
#include <QTest>
|
|
|
|
#include "utils/testCoreController.h"
|
|
#include "core/models/serverDescription.h"
|
|
#include "ui/models/serversModel.h"
|
|
#include "utils/testUtils.h"
|
|
#include "vpnConnection.h"
|
|
#include "secureQSettings.h"
|
|
|
|
using namespace amnezia;
|
|
using namespace amnezia::test;
|
|
|
|
class TestServerRename : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private:
|
|
TestCoreController *m_coreController;
|
|
SecureQSettings *m_settings;
|
|
|
|
void importSingleServer()
|
|
{
|
|
const QString awgKey = getEnvValue("THIRD_PARTY_AWG_VPN_KEY");
|
|
const auto importResult = m_coreController->m_importCoreController->extractConfigFromData(awgKey);
|
|
QVERIFY2(importResult.errorCode == ErrorCode::NoError, "Import setup should succeed");
|
|
m_coreController->m_importCoreController->importConfig(importResult.config);
|
|
QVERIFY2(m_coreController->m_serversRepository->serversCount() == 1, "Should have one server");
|
|
}
|
|
|
|
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 TestCoreController(vpnConnection, m_settings, nullptr, this);
|
|
}
|
|
|
|
void cleanupTestCase()
|
|
{
|
|
m_settings->clearSettings();
|
|
delete m_coreController;
|
|
delete m_settings;
|
|
}
|
|
|
|
void init()
|
|
{
|
|
m_settings->clearSettings();
|
|
m_coreController->m_serversRepository->invalidateCache();
|
|
if (m_coreController->m_serversModel) {
|
|
m_coreController->m_serversModel->updateModel(QVector<ServerDescription>(), QString{});
|
|
}
|
|
}
|
|
|
|
void testRenameServerUpdatesRepositoryAndModel()
|
|
{
|
|
if (!isEnvValueConfigured(getEnvValue("THIRD_PARTY_AWG_VPN_KEY"))) {
|
|
QSKIP("Set THIRD_PARTY_AWG_VPN_KEY");
|
|
}
|
|
|
|
importSingleServer();
|
|
|
|
const QString serverId = m_coreController->m_serversController->getServerId(0);
|
|
QSignalSpy serverEditedSpy(m_coreController->m_serversRepository, &SecureServersRepository::serverEdited);
|
|
|
|
QVERIFY(m_coreController->m_serversController->renameServer(serverId, QStringLiteral("Renamed Server")));
|
|
|
|
QVERIFY2(serverEditedSpy.count() == 1, "serverEdited should be emitted");
|
|
const auto renamedDescription = serverDescription(m_coreController->m_serversRepository, serverId);
|
|
QVERIFY2(renamedDescription.has_value(), "Server config should exist");
|
|
QVERIFY2(*renamedDescription == "Renamed Server", "Repository should store renamed description");
|
|
|
|
if (m_coreController->m_serversModel) {
|
|
const QString modelName = m_coreController->m_serversModel
|
|
->data(m_coreController->m_serversModel->index(0, 0), ServersModel::NameRole)
|
|
.toString();
|
|
QVERIFY2(modelName == "Renamed Server", "Model should reflect renamed server");
|
|
}
|
|
|
|
QVERIFY(m_coreController->m_serversController->renameServer(serverId, QStringLiteral("Renamed Again")));
|
|
|
|
QVERIFY2(serverEditedSpy.count() == 2, "serverEdited should be emitted again");
|
|
const auto renamedAgainDescription = serverDescription(m_coreController->m_serversRepository, serverId);
|
|
QVERIFY2(renamedAgainDescription.has_value(), "Server config should exist");
|
|
QVERIFY2(*renamedAgainDescription == "Renamed Again", "Repository should store second rename");
|
|
|
|
if (m_coreController->m_serversModel) {
|
|
const QString modelName = m_coreController->m_serversModel
|
|
->data(m_coreController->m_serversModel->index(0, 0), ServersModel::NameRole)
|
|
.toString();
|
|
QVERIFY2(modelName == "Renamed Again", "Model should reflect second rename");
|
|
}
|
|
}
|
|
};
|
|
|
|
QTEST_MAIN(TestServerRename)
|
|
#include "testServerRename.moc"
|