Compare commits

...
Author SHA1 Message Date
yp 7f973b22dd remove test log 2026-11-03 17:04:41 +03:00
yp 71d3a39ddc feat: test xray pages ui 2026-11-03 10:31:50 +03:00
11 changed files with 3468 additions and 0 deletions

No files matched your search

+1
View File
@@ -463,6 +463,7 @@ endif()
if(NOT ANDROID)
add_subdirectory(selfHostedAdmin)
add_subdirectory(api)
add_subdirectory(ui/xray)
endif()
enable_testing()
+24
View File
@@ -0,0 +1,24 @@
qt6_add_resources(XRAY_PAGES_UI_QRC
${CLIENT_QML_QRC_FILE}
../../../images/images.qrc
)
add_executable(test_xray_pages_ui
testXrayPagesUi.h
main.cpp
pageMain.cpp
pageTransport.cpp
pageSecurity.cpp
pageFlowPadding.cpp
pageXmux.cpp
saveFlowSnapshots.cpp
knownIssues.cpp
${XRAY_PAGES_UI_QRC}
)
target_link_libraries(test_xray_pages_ui PRIVATE
Qt6::Test
test_common
)
add_test(NAME XrayPagesUiTest COMMAND test_xray_pages_ui)
+108
View File
@@ -0,0 +1,108 @@
#include "testXrayPagesUi.h"
using namespace amnezia;
void TestXrayPagesUi::issueTransportRoundTripLeavesSaveEnabled()
{
storeAndOpen(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
click(typed("RadioItemType", "text", QStringLiteral("XHTTP")));
click(typed("RadioItemType", "text", QStringLiteral("RAW (TCP)")));
QCOMPARE(m_model->transport(), QStringLiteral("raw"));
QVERIFY2(!m_model->hasUnsavedChanges(), "raw -> XHTTP -> raw left the model dirty");
QVERIFY2(!saveButton()->isEnabled(), "Save is enabled although nothing was changed");
}
void TestXrayPagesUi::issueSubpageSavesEmptyPort()
{
XrayServerConfig srv = xraytest::baseConfig("xhttp", "reality", "");
srv.port = QStringLiteral("8443");
storeAndOpen(srv);
m_model->setPort(QString());
m_model->setXhttpUplinkMethod(QStringLiteral("PUT"));
XRAY_LOAD("PageProtocolXrayTransportSettings");
XRAY_QUESTIONS(questions);
QQuickItem *save = saveButton();
if (save->isEnabled())
click(save);
const bool proceeded = questions.count() > 0;
if (proceeded)
answer(questions, false);
QVERIFY2(!proceeded, "a sub-page offered to save with an empty port");
}
void TestXrayPagesUi::issueHiddenRealitySniBlocksMkcpSave()
{
XrayServerConfig srv = xraytest::baseConfig("raw", "reality", "");
srv.sni = QStringLiteral("*.asd.com");
srv.site = srv.sni;
openStored(srv);
XRAY_LOAD("PageProtocolXrayTransportSettings");
click(typed("RadioItemType", "text", QStringLiteral("mKCP")));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
if (questions.count() > 0)
answer(questions, false);
QVERIFY2(errors.isEmpty(), qPrintable(QStringLiteral("refused with: ") + (errors.isEmpty() ? QString()
: errors.first().first().toString())));
}
void TestXrayPagesUi::issueClearingXmuxZeroEnablesSave()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(minMaxInput(minMaxRow(0), QStringLiteral("Min")), QString());
QCOMPARE(m_model->xmuxMaxConcurrencyMin(), QString());
QVERIFY2(!m_model->hasUnsavedChanges(), "clearing a 0 field counts as an unsaved change");
QVERIFY2(!saveButton()->isEnabled(), "Save is enabled for a no-op");
}
void TestXrayPagesUi::issueSnapshotWithoutPortApplyIsSilent()
{
const QString snapshot = QStringLiteral(
R"({"displayName":"no port","serverConfig":{"xray_transport":"raw","xray_security":"tls"}})");
QVERIFY(m_snapshots->importFromJson(snapshot));
XRAY_LOAD("PageProtocolXraySnapshots");
QCOMPARE(m_model->transport(), QStringLiteral("xhttp"));
QObject *drawer = popupOf(m_page);
click(typed("ListItemType", "text", QStringLiteral("no port")));
QVERIFY(QTest::qWaitFor([drawer] { return drawer->property("opened").toBool(); }, 3000));
QTest::qWait(250);
const QString portBefore = m_model->port();
click(typed("ListItemType", "text", QStringLiteral("Apply configuration"), popupContent(drawer)));
QCOMPARE(m_model->transport(), QStringLiteral("raw"));
QCOMPARE(m_model->security(), QStringLiteral("tls"));
QCOMPARE(m_model->port(), portBefore);
}
void TestXrayPagesUi::issueSaveWithoutReturnSkipsClamp()
{
openStored(xraytest::baseConfig("mkcp", "none", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
clearAndType(field(QStringLiteral("TTI")), QStringLiteral("5"), false);
QCOMPARE(m_model->mkcpTti(), QStringLiteral("5"));
XRAY_QUESTIONS(questions);
click(saveButton());
if (questions.count() > 0)
answer(questions, false);
QCOMPARE(m_model->mkcpTti(), QStringLiteral("10"));
}
void TestXrayPagesUi::issueSaveWithoutReturnKeepsRawKeepAlive()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(field(QStringLiteral("hKeepAlivePeriod")), QStringLiteral("-"), false);
QCOMPARE(m_model->xmuxHKeepAlivePeriod(), QStringLiteral("-"));
XRAY_QUESTIONS(questions);
click(saveButton());
if (questions.count() > 0)
answer(questions, false);
QCOMPARE(m_model->xmuxHKeepAlivePeriod(), QString());
}
+278
View File
@@ -0,0 +1,278 @@
#include <QApplication>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickStyle>
#include <QUuid>
#include "testXrayPagesUi.h"
#include "ui/utils/pageEnum.h"
#include "vpnConnection.h"
using namespace amnezia;
void TestXrayPagesUi::initTestCase()
{
QQuickStyle::setStyle(QStringLiteral("Basic"));
PageLoader::declareQmlPageEnum();
for (const char *name : { "ProtocolEnum", "TransportProto", "ServiceType" })
qmlRegisterUncreatableMetaObject(ProtocolEnumNS::staticMetaObject, "ProtocolEnum", 1, 0, name,
QStringLiteral("Error: only enums"));
m_settings = new SecureQSettings("AmneziaVPN-Test-" + QUuid::createUuid().toString(), "amnezia-client", nullptr, false);
m_engine = new QQmlApplicationEngine(this);
m_engine->addImportPath(QStringLiteral("qrc:/ui/qml/Modules/"));
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
m_core = new TestCoreController(vpnConnection, m_settings, m_engine, this);
m_model = qobject_cast<XrayConfigModel *>(
m_engine->rootContext()->contextProperty(QStringLiteral("XrayConfigModel")).value<QObject *>());
QVERIFY2(m_model, "XrayConfigModel is not exposed to QML");
m_snapshots = qobject_cast<XrayConfigSnapshotsModel *>(
m_engine->rootContext()->contextProperty(QStringLiteral("XrayConfigSnapshotsModel")).value<QObject *>());
QVERIFY2(m_snapshots, "XrayConfigSnapshotsModel is not exposed to QML");
m_pages = m_core->pageController();
QVERIFY(m_pages);
m_serverId = addServer(QStringLiteral("203.0.113.10"), QStringLiteral("not-used"),
serverConfigUtils::ConfigType::SelfHostedAdmin);
m_readOnlyServerId = addServer(QStringLiteral("203.0.113.11"), QString(), serverConfigUtils::ConfigType::SelfHostedUser);
m_hostlessServerId = addServer(QString(), QStringLiteral("not-used"), serverConfigUtils::ConfigType::SelfHostedAdmin);
QVERIFY2(!m_serverId.isEmpty() && !m_readOnlyServerId.isEmpty() && !m_hostlessServerId.isEmpty(),
"test servers were not added");
selectServer(m_readOnlyServerId);
QVERIFY2(!m_core->m_serversUiController->isProcessedServerHasWriteAccess(), "read-only server must not be editable");
selectServer(m_hostlessServerId);
QVERIFY2(m_core->m_serversUiController->isProcessedServerHasWriteAccess(), "hostless server must be editable");
selectServer(m_serverId);
QVERIFY2(m_core->m_serversUiController->isProcessedServerHasWriteAccess(), "test server must be editable");
}
void TestXrayPagesUi::init()
{
selectServer(m_serverId);
storeAndOpen(xraytest::baseConfig("xhttp", "reality", ""));
m_core->m_appSettingsRepository->setXraySavedConfigs(QByteArray());
m_snapshots->reload();
}
void TestXrayPagesUi::cleanup()
{
closePage();
}
void TestXrayPagesUi::cleanupTestCase()
{
closePage();
m_settings->clearSettings();
delete m_core;
delete m_engine;
delete m_settings;
}
void TestXrayPagesUi::transportRadioClickChangesModel()
{
openStored(xraytest::baseConfig("xhttp", "reality", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
for (const auto &pair : { qMakePair(QStringLiteral("RAW (TCP)"), QStringLiteral("raw")),
qMakePair(QStringLiteral("mKCP"), QStringLiteral("mkcp")),
qMakePair(QStringLiteral("XHTTP"), QStringLiteral("xhttp")) }) {
QQuickItem *radio = item("text", pair.first);
QVERIFY(radio);
click(radio);
QCOMPARE(m_model->transport(), pair.second);
}
}
void TestXrayPagesUi::packetUpFieldsFollowMode_data()
{
QTest::addColumn<QString>("mode");
QTest::addColumn<QString>("security");
QTest::addColumn<bool>("seqVisible");
QTest::addColumn<bool>("dataVisible");
QTest::newRow("stream-one + reality") << "Stream-one" << "reality" << false << false;
QTest::newRow("stream-up + tls") << "Stream-up" << "tls" << false << false;
QTest::newRow("packet-up + tls") << "Packet-up" << "tls" << true << true;
QTest::newRow("auto + none") << "Auto" << "none" << true << false;
QTest::newRow("auto + reality") << "Auto" << "reality" << false << false;
}
void TestXrayPagesUi::packetUpFieldsFollowMode()
{
QFETCH(QString, mode);
QFETCH(QString, security);
QFETCH(bool, seqVisible);
QFETCH(bool, dataVisible);
XrayServerConfig srv = xraytest::baseConfig("xhttp", security, "");
srv.xhttp.mode = mode;
srv.xhttp.seqPlacement = QStringLiteral("Header");
srv.xhttp.uplinkDataPlacement = QStringLiteral("Header");
openStored(srv);
XRAY_LOAD("PageProtocolXrayTransportSettings");
const QList<QPair<QString, bool>> expected = {
{ QStringLiteral("SeqKey"), seqVisible },
{ QStringLiteral("SeqPlacement"), seqVisible },
{ QStringLiteral("UplinkDataKey"), dataVisible },
{ QStringLiteral("UplinkDataPlacement"), dataVisible },
};
for (const auto &e : expected) {
QQuickItem *f = item("headerText", e.first);
QVERIFY2(f, qPrintable(e.first));
QCOMPARE(f->isVisible(), e.second);
}
}
void TestXrayPagesUi::pathGetsLeadingSlash()
{
openStored(xraytest::baseConfig("xhttp", "reality", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *textField = field(QStringLiteral("Path"));
QVERIFY(textField);
clearAndType(textField, QStringLiteral("amnezia"));
QCOMPARE(m_model->xhttpPath(), QStringLiteral("/amnezia"));
QCOMPARE(textField->property("text").toString(), QStringLiteral("/amnezia"));
}
void TestXrayPagesUi::visionNeedsTlsOrReality_data()
{
QTest::addColumn<QString>("security");
QTest::addColumn<bool>("enabled");
QTest::newRow("none") << "none" << false;
QTest::newRow("tls") << "tls" << true;
QTest::newRow("reality") << "reality" << true;
}
void TestXrayPagesUi::visionNeedsTlsOrReality()
{
QFETCH(QString, security);
QFETCH(bool, enabled);
openStored(xraytest::baseConfig("raw", security, ""));
XRAY_LOAD("PageProtocolXrayFlowSettings");
for (const QString &flow : { QStringLiteral("xtls-rprx-vision"), QStringLiteral("xtls-rprx-vision-udp443") }) {
QQuickItem *radio = item("text", flow);
QVERIFY(radio);
QCOMPARE(radio->isEnabled(), enabled);
}
}
void TestXrayPagesUi::fingerprintHiddenOnMkcp_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<bool>("visible");
QTest::newRow("raw + tls") << "raw" << true;
QTest::newRow("mkcp + tls") << "mkcp" << false;
}
void TestXrayPagesUi::fingerprintHiddenOnMkcp()
{
QFETCH(QString, transport);
QFETCH(bool, visible);
openStored(xraytest::baseConfig(transport, "tls", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *dd = item("descriptionText", QStringLiteral("Fingerprint"));
QVERIFY(dd);
QCOMPARE(dd->isVisible(), visible);
}
void TestXrayPagesUi::sniRejectsWildcardInput()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *textField = visibleField(QStringLiteral("Server Name (SNI)"));
QVERIFY(textField);
clearAndType(textField, QStringLiteral("*.example.com"));
QVERIFY2(!textField->property("text").toString().contains(QLatin1Char('*')),
qPrintable(textField->property("text").toString()));
QVERIFY(!m_model->sni().contains(QLatin1Char('*')));
}
void TestXrayPagesUi::xPaddingFieldsFollowObfsMode_data()
{
QTest::addColumn<bool>("obfs");
QTest::newRow("obfs on") << true;
QTest::newRow("obfs off") << false;
}
void TestXrayPagesUi::xPaddingFieldsFollowObfsMode()
{
QFETCH(bool, obfs);
XrayServerConfig srv = xraytest::baseConfig("xhttp", "reality", "");
srv.xhttp.xPadding.obfsMode = obfs;
srv.xhttp.xPadding.bytesMin.clear();
srv.xhttp.xPadding.bytesMax.clear();
openStored(srv);
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *bytes = item("text", QStringLiteral("xPaddingBytes"));
QVERIFY(bytes);
QVERIFY(bytes->isEnabled());
QCOMPARE(bytes->property("subtitle").toString(), QStringLiteral("Default (100—1000)"));
for (const QString &header : { QStringLiteral("xPaddingKey"), QStringLiteral("xPaddingPlacement"),
QStringLiteral("xPaddingMethod") }) {
QQuickItem *f = item("headerText", header);
QVERIFY(f);
QCOMPARE(f->isEnabled(), obfs);
}
QQuickItem *paddingHeader = item("headerText", QStringLiteral("xPaddingHeader"));
QVERIFY(paddingHeader);
QVERIFY(!paddingHeader->isEnabled());
}
void TestXrayPagesUi::subpageSaveRefusesInvalidSni_data()
{
QTest::addColumn<QString>("page");
QTest::newRow("flow") << "PageProtocolXrayFlowSettings";
QTest::newRow("xmux") << "PageProtocolXrayXmuxSettings";
QTest::newRow("xPadding") << "PageProtocolXrayXPaddingSettings";
QTest::newRow("xPaddingBytes") << "PageProtocolXrayXPaddingBytesSettings";
QTest::newRow("security") << "PageProtocolXraySecuritySettings";
QTest::newRow("transport") << "PageProtocolXrayTransportSettings";
}
void TestXrayPagesUi::subpageSaveRefusesInvalidSni()
{
QFETCH(QString, page);
openStored(xraytest::baseConfig("xhttp", "reality", ""));
m_model->setSni(QStringLiteral("*"));
QVERIFY(m_model->hasUnsavedChanges());
loadPage(page);
if (QTest::currentTestFailed())
return;
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
QQuickItem *save = saveButton();
QVERIFY(save);
QVERIFY2(save->isVisible() && save->isEnabled(), "Save must be shown for an edited, writable server");
click(save);
QCOMPARE(errors.count(), 1);
QVERIFY2(errors.first().first().toString().contains(QLatin1String("SNI")),
qPrintable(errors.first().first().toString()));
}
int main(int argc, char *argv[])
{
#ifndef Q_OS_MACOS
if (!qEnvironmentVariableIsSet("QT_QPA_PLATFORM"))
qputenv("QT_QPA_PLATFORM", "offscreen");
#endif
QApplication app(argc, argv);
TestXrayPagesUi test;
QStringList args = app.arguments();
if (!args.contains(QStringLiteral("-maxwarnings")))
args << QStringLiteral("-maxwarnings") << QStringLiteral("0");
return QTest::qExec(&test, args);
}
+399
View File
@@ -0,0 +1,399 @@
#include "testXrayPagesUi.h"
#include "ui/utils/pageEnum.h"
using namespace amnezia;
namespace
{
const QString kVision = QStringLiteral("xtls-rprx-vision");
const QString kUdp443 = QStringLiteral("xtls-rprx-vision-udp443");
const QString kVisionHint =
QStringLiteral("xtls-rprx-vision is available only with the RAW (TCP) transport and TLS or Reality security.");
const QString kDeviceOnlyText =
QStringLiteral("The server will not be changed now. The new settings apply the next time you connect.");
const QString kServerBreaksSharedText = QStringLiteral(
"The server configuration will be updated. All users with whom you shared a connection with will no "
"longer be able to connect to it. You will need to share the connection again.");
}
void TestXrayPagesUi::flowRadioRoundTrip()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXrayFlowSettings");
auto checkedOnly = [this](const QString &text) {
for (const QString &t : { QStringLiteral("Empty"), kVision, kUdp443 }) {
if (typed("RadioItemType", "text", t)->property("checked").toBool() != (t == text))
return false;
}
return true;
};
QVERIFY(checkedOnly(QStringLiteral("Empty")));
QVERIFY(!saveButton()->isEnabled());
click(typed("RadioItemType", "text", kVision));
QCOMPARE(m_model->flow(), kVision);
QVERIFY(checkedOnly(kVision));
QVERIFY(saveButton()->isEnabled());
click(typed("RadioItemType", "text", kUdp443));
QCOMPARE(m_model->flow(), kUdp443);
QVERIFY(checkedOnly(kUdp443));
click(typed("RadioItemType", "text", QStringLiteral("Empty")));
QCOMPARE(m_model->flow(), QString());
QVERIFY(checkedOnly(QStringLiteral("Empty")));
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::flowUdp443Subtitle()
{
XRAY_LOAD("PageProtocolXrayFlowSettings");
QCOMPARE(typed("RadioItemType", "text", kUdp443)->property("subtitle").toString(),
QStringLiteral("For apps that require QUIC. Browsers may stop loading."));
}
void TestXrayPagesUi::flowVisionNotAllowed_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("flow");
QTest::newRow("xhttp + reality + vision") << "xhttp" << "reality" << kVision;
QTest::newRow("mkcp + tls + vision") << "mkcp" << "tls" << kVision;
QTest::newRow("raw + none + udp443") << "raw" << "none" << kUdp443;
QTest::newRow("mkcp + none + empty") << "mkcp" << "none" << "";
}
void TestXrayPagesUi::flowVisionNotAllowed()
{
QFETCH(QString, transport);
QFETCH(QString, security);
QFETCH(QString, flow);
openStored(xraytest::baseConfig(transport, security, flow));
XRAY_LOAD("PageProtocolXrayFlowSettings");
QVERIFY(typed("RadioItemType", "text", QStringLiteral("Empty"))->property("checked").toBool());
for (const QString &t : { kVision, kUdp443 }) {
QQuickItem *radio = typed("RadioItemType", "text", t);
QVERIFY2(!radio->isEnabled(), qPrintable(t));
QVERIFY2(!radio->property("checked").toBool(), qPrintable(t));
}
QQuickItem *hint = typed("SmallTextType", "text", kVisionHint);
QVERIFY(hint && hint->isVisible());
QCOMPARE(m_model->flow(), flow);
QVERIFY(!m_model->hasUnsavedChanges());
click(typed("RadioItemType", "text", kVision));
QCOMPARE(m_model->flow(), flow);
}
void TestXrayPagesUi::flowEmptyWhenVisionNotAllowed()
{
openStored(xraytest::baseConfig("xhttp", "reality", kVision));
XRAY_LOAD("PageProtocolXrayFlowSettings");
QQuickItem *empty = typed("RadioItemType", "text", QStringLiteral("Empty"));
QVERIFY(empty);
QVERIFY(empty->property("checked").toBool());
QVERIFY(!empty->isEnabled());
click(empty);
QCOMPARE(m_model->flow(), kVision);
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::flowDeviceOrServerChange_data()
{
QTest::addColumn<QString>("from");
QTest::addColumn<QString>("to");
QTest::addColumn<QString>("expected");
QTest::newRow("vision -> udp443 is device-only") << kVision << kUdp443 << kDeviceOnlyText;
QTest::newRow("empty -> vision breaks shared configs") << "" << kVision << kServerBreaksSharedText;
}
void TestXrayPagesUi::flowDeviceOrServerChange()
{
QFETCH(QString, from);
QFETCH(QString, to);
QFETCH(QString, expected);
openStored(xraytest::baseConfig("raw", "tls", from));
XRAY_LOAD("PageProtocolXrayFlowSettings");
click(typed("RadioItemType", "text", to));
QCOMPARE(m_model->flow(), to);
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(1).toString(), expected);
answer(questions, false);
}
void TestXrayPagesUi::flowEmptyTransportCountsAsRaw()
{
XrayServerConfig srv = xraytest::baseConfig("raw", "tls", "");
srv.transport.clear();
srv.isThirdPartyConfig = true;
openStored(srv);
XRAY_LOAD("PageProtocolXrayFlowSettings");
QCOMPARE(m_model->transport(), QString());
QVERIFY(typed("RadioItemType", "text", kVision)->isEnabled());
QVERIFY(typed("RadioItemType", "text", kUdp443)->isEnabled());
}
void TestXrayPagesUi::flowUnknownStoredFlow()
{
openStored(xraytest::baseConfig("raw", "tls", "xtls-rprx-direct"));
XRAY_LOAD("PageProtocolXrayFlowSettings");
for (const QString &t : { QStringLiteral("Empty"), kVision, kUdp443 })
QVERIFY2(!typed("RadioItemType", "text", t)->property("checked").toBool(), qPrintable(t));
}
void TestXrayPagesUi::flowKeyboard()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXrayFlowSettings");
QQuickItem *radio = typed("RadioItemType", "text", kVision);
radio->forceActiveFocus();
key(Qt::Key_Return);
QCOMPARE(m_model->flow(), kVision);
}
void TestXrayPagesUi::paddingInitialState()
{
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *obfs = switcherOf(typed("SwitchRowType", "text", QStringLiteral("xPaddingObfsMode")));
QVERIFY(obfs && obfs->property("checked").toBool());
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("xPaddingPlacement"))->property("text").toString(),
QStringLiteral("Cookie"));
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("xPaddingMethod"))->property("text").toString(),
QStringLiteral("Repeat-x"));
QQuickItem *keyInput = field(QStringLiteral("xPaddingKey"));
QQuickItem *headerInput = field(QStringLiteral("xPaddingHeader"));
QCOMPARE(keyInput->property("text").toString(), QString());
QCOMPARE(keyInput->property("placeholderText").toString(), QStringLiteral("x_padding"));
QCOMPARE(headerInput->property("text").toString(), QString());
QCOMPARE(headerInput->property("placeholderText").toString(), QStringLiteral("X-Padding"));
}
void TestXrayPagesUi::paddingSwitchTogglesFields()
{
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *obfs = switcherOf(typed("SwitchRowType", "text", QStringLiteral("xPaddingObfsMode")));
QVERIFY(obfs);
auto dependents = [this] {
return QList<QQuickItem *> { typed("TextFieldType", "headerText", QStringLiteral("xPaddingKey")),
typed("DropDownType", "headerText", QStringLiteral("xPaddingPlacement")),
typed("DropDownType", "headerText", QStringLiteral("xPaddingMethod")) };
};
QQuickItem *bytes = typed("ListItemType", "text", QStringLiteral("xPaddingBytes"));
QQuickItem *paddingHeader = typed("TextFieldType", "headerText", QStringLiteral("xPaddingHeader"));
QVERIFY(bytes && paddingHeader);
click(obfs);
QCOMPARE(m_model->xPaddingObfsMode(), false);
for (QQuickItem *dep : dependents())
QVERIFY(dep && !dep->isEnabled());
QVERIFY(bytes->isEnabled());
QVERIFY(!paddingHeader->isEnabled());
QVERIFY(saveButton()->isEnabled());
click(obfs);
QCOMPARE(m_model->xPaddingObfsMode(), true);
for (QQuickItem *dep : dependents())
QVERIFY(dep && dep->isEnabled());
QVERIFY(bytes->isEnabled());
QVERIFY(!paddingHeader->isEnabled());
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::paddingSwitchLabelToggles()
{
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *label = typed("BodyTextType", "text", QStringLiteral("xPaddingObfsMode"));
QVERIFY(label);
click(label);
QCOMPARE(m_model->xPaddingObfsMode(), false);
}
void TestXrayPagesUi::paddingBytesSubtitle_data()
{
QTest::addColumn<QString>("min");
QTest::addColumn<QString>("max");
QTest::addColumn<QString>("subtitle");
QTest::newRow("both empty") << "" << "" << "Default (100—1000)";
QTest::newRow("min only") << "200" << "" << "200—1000";
QTest::newRow("max only") << "" << "500" << "100—500";
QTest::newRow("both") << "200" << "400" << "200—400";
}
void TestXrayPagesUi::paddingBytesSubtitle()
{
QFETCH(QString, min);
QFETCH(QString, max);
QFETCH(QString, subtitle);
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
m_model->setXPaddingBytesMin(min);
m_model->setXPaddingBytesMax(max);
QCOMPARE(typed("ListItemType", "text", QStringLiteral("xPaddingBytes"))->property("subtitle").toString(), subtitle);
}
void TestXrayPagesUi::paddingBytesRowNavigates_data()
{
QTest::addColumn<bool>("obfs");
QTest::newRow("obfs on navigates") << true;
QTest::newRow("obfs off navigates") << false;
}
void TestXrayPagesUi::paddingBytesRowNavigates()
{
QFETCH(bool, obfs);
XrayServerConfig srv = xraytest::baseConfig("xhttp", "reality", "");
srv.xhttp.xPadding.obfsMode = obfs;
openStored(srv);
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QSignalSpy pages(m_pages, &PageController::goToPage);
click(typed("ListItemType", "text", QStringLiteral("xPaddingBytes")));
QCOMPARE(pages.count(), 1);
QCOMPARE(qvariant_cast<PageLoader::PageEnum>(pages.first().at(0)),
PageLoader::PageEnum::PageProtocolXrayXPaddingBytesSettings);
}
void TestXrayPagesUi::paddingKeyHeaderFilter_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("expected");
QTest::newRow("key") << "xPaddingKey" << "my.key name$1" << "mykeyname1";
QTest::newRow("header") << "xPaddingHeader" << "X-Pad.ding" << "X-Padding";
}
void TestXrayPagesUi::paddingKeyHeaderFilter()
{
QFETCH(QString, header);
QFETCH(QString, typed);
QFETCH(QString, expected);
XrayServerConfig srv = xraytest::baseConfig("xhttp", "reality", "");
if (header == QLatin1String("xPaddingHeader"))
srv.xhttp.xPadding.placement = QStringLiteral("Header");
openStored(srv);
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *f = field(header);
clearAndType(f, typed);
QCOMPARE(f->property("text").toString(), expected);
QCOMPARE(header == QLatin1String("xPaddingKey") ? m_model->xPaddingKey() : m_model->xPaddingHeader(), expected);
QVERIFY(saveButton()->isEnabled());
}
void TestXrayPagesUi::paddingDropDownRoundTrip_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QString>("option");
for (const QString o : { QStringLiteral("Cookie"), QStringLiteral("Header"), QStringLiteral("Query"),
QStringLiteral("Query in header") })
QTest::newRow(qPrintable("placement = " + o)) << "xPaddingPlacement" << o;
for (const QString o : { QStringLiteral("Repeat-x"), QStringLiteral("Tokenish") })
QTest::newRow(qPrintable("method = " + o)) << "xPaddingMethod" << o;
}
void TestXrayPagesUi::paddingDropDownRoundTrip()
{
QFETCH(QString, header);
QFETCH(QString, option);
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *dd = typed("DropDownType", "headerText", header);
QVERIFY(dd);
const QStringList all = optionNames(dd, false);
const QStringList expected = header == QLatin1String("xPaddingPlacement")
? QStringList { "Cookie", "Header", "Query", "Query in header" }
: QStringList { "Repeat-x", "Tokenish" };
QCOMPARE(all, expected);
QVERIFY(chooseOption(dd, option));
QCOMPARE(header == QLatin1String("xPaddingPlacement") ? m_model->xPaddingPlacement() : m_model->xPaddingMethod(),
option);
QCOMPARE(dd->property("text").toString(), option);
QCOMPARE(optionNames(dd, true), QStringList { option });
}
void TestXrayPagesUi::paddingDisabledDropDownDoesNotOpen()
{
XrayServerConfig srv = xraytest::baseConfig("xhttp", "reality", "");
srv.xhttp.xPadding.obfsMode = false;
openStored(srv);
XRAY_LOAD("PageProtocolXrayXPaddingSettings");
QQuickItem *dd = typed("DropDownType", "headerText", QStringLiteral("xPaddingPlacement"));
QObject *popup = popupOf(dd);
QVERIFY(popup);
click(dd);
QTest::qWait(400);
QVERIFY(!popup->property("opened").toBool());
}
void TestXrayPagesUi::paddingBytesInitialState()
{
XRAY_LOAD("PageProtocolXrayXPaddingBytesSettings");
QQuickItem *row = minMaxRow(0);
QQuickItem *minInput = minMaxInput(row, QStringLiteral("Min"));
QQuickItem *maxInput = minMaxInput(row, QStringLiteral("Max"));
QVERIFY(minInput && maxInput);
QCOMPARE(minInput->property("text").toString(), QString());
QCOMPARE(maxInput->property("text").toString(), QString());
QCOMPARE(minInput->property("placeholderText").toString(), QStringLiteral("100"));
QCOMPARE(maxInput->property("placeholderText").toString(), QStringLiteral("1000"));
QVERIFY(typed("SmallTextType", "text", QStringLiteral("≤ 2147483647"))->isVisible());
QVERIFY(typed("SmallTextType", "text", QStringLiteral("Range"))->isVisible());
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::paddingBytesRange_data()
{
QTest::addColumn<QString>("minBefore");
QTest::addColumn<QString>("maxBefore");
QTest::addColumn<QString>("which");
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("minAfter");
QTest::addColumn<QString>("maxAfter");
QTest::newRow("min only") << "" << "" << "Min" << "200" << "200" << "";
QTest::newRow("max only") << "" << "" << "Max" << "400" << "" << "400";
QTest::newRow("min above max placeholder raises max") << "" << "" << "Min" << "2000" << "2000" << "2000";
QTest::newRow("min above max raises max") << "" << "400" << "Min" << "500" << "500" << "500";
QTest::newRow("max below min is raised") << "300" << "" << "Max" << "200" << "300" << "300";
QTest::newRow("max below min placeholder is raised") << "" << "" << "Max" << "50" << "" << "100";
QTest::newRow("leading zeros") << "" << "" << "Min" << "007" << "7" << "";
QTest::newRow("clear min") << "200" << "" << "Min" << "" << "" << "";
}
void TestXrayPagesUi::paddingBytesRange()
{
QFETCH(QString, minBefore);
QFETCH(QString, maxBefore);
QFETCH(QString, which);
QFETCH(QString, typed);
QFETCH(QString, minAfter);
QFETCH(QString, maxAfter);
XRAY_LOAD("PageProtocolXrayXPaddingBytesSettings");
m_model->setXPaddingBytesMin(minBefore);
m_model->setXPaddingBytesMax(maxBefore);
QQuickItem *row = minMaxRow(0);
clearAndType(minMaxInput(row, which), typed);
QCOMPARE(m_model->xPaddingBytesMin(), minAfter);
QCOMPARE(m_model->xPaddingBytesMax(), maxAfter);
QCOMPARE(minMaxInput(row, QStringLiteral("Max"))->property("text").toString(), maxAfter);
}
void TestXrayPagesUi::paddingBytesOverflowAndFilter()
{
XRAY_LOAD("PageProtocolXrayXPaddingBytesSettings");
QQuickItem *minInput = minMaxInput(minMaxRow(0), QStringLiteral("Min"));
clearAndType(minInput, QStringLiteral("9999999999"), false);
QCOMPARE(minInput->property("text").toString(), QStringLiteral("999999999"));
QCOMPARE(m_model->xPaddingBytesMin(), QStringLiteral("999999999"));
clearAndType(minInput, QStringLiteral("-12a"), false);
QCOMPARE(minInput->property("text").toString(), QStringLiteral("12"));
}
+378
View File
@@ -0,0 +1,378 @@
#include "testXrayPagesUi.h"
#include "ui/utils/pageEnum.h"
using namespace amnezia;
namespace
{
const QString kPortChangeText = QStringLiteral(
"All users with whom you shared a connection with will no longer be able to connect to it. "
"You will need to share the connection again.");
}
void TestXrayPagesUi::mainPortPlaceholderAndDefault()
{
XRAY_LOAD("PageProtocolXraySettings");
m_model->setPort(QString());
QQuickItem *port = field(QStringLiteral("Port"));
QVERIFY(port);
QCOMPARE(port->property("text").toString(), QString());
QCOMPARE(port->property("placeholderText").toString(), QStringLiteral("443"));
}
void TestXrayPagesUi::mainPortInput_data()
{
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("expected");
QTest::newRow("letters and symbols are blocked") << "a-+ .x1" << "1";
QTest::newRow("65536 cannot be typed") << "65536" << "6553";
QTest::newRow("70000 cannot be typed") << "70000" << "7000";
QTest::newRow("0 is clamped to 1") << "0" << "1";
QTest::newRow("0000 is clamped to 1") << "0000" << "1";
QTest::newRow("leading zeros dropped") << "0443" << "443";
QTest::newRow("65535 accepted") << "65535" << "65535";
}
void TestXrayPagesUi::mainPortInput()
{
QFETCH(QString, typed);
QFETCH(QString, expected);
XRAY_LOAD("PageProtocolXraySettings");
QQuickItem *port = field(QStringLiteral("Port"));
QVERIFY(port);
clearAndType(port, typed);
QCOMPARE(port->property("text").toString(), expected);
QCOMPARE(m_model->port(), expected);
}
void TestXrayPagesUi::mainPortEditTogglesSave()
{
XRAY_LOAD("PageProtocolXraySettings");
QQuickItem *port = field(QStringLiteral("Port"));
QQuickItem *save = saveButton();
QVERIFY(port && save);
QVERIFY(!save->isEnabled());
clearAndType(port, QStringLiteral("8443"), false);
QCOMPARE(m_model->port(), QStringLiteral("8443"));
QVERIFY(m_model->hasUnsavedChanges());
QVERIFY(save->isEnabled());
clearAndType(port, QStringLiteral("443"), false);
QVERIFY(!m_model->hasUnsavedChanges());
QVERIFY(!save->isEnabled());
}
void TestXrayPagesUi::mainEmptyPortDisablesSave()
{
XRAY_LOAD("PageProtocolXraySettings");
m_model->setXhttpDisableGrpc(false);
QVERIFY(m_model->hasUnsavedChanges());
QQuickItem *port = field(QStringLiteral("Port"));
QQuickItem *save = saveButton();
QVERIFY(port && save);
QVERIFY(save->isEnabled());
clearAndType(port, QString(), false);
QCOMPARE(m_model->port(), QString());
QVERIFY2(!save->isEnabled(), "Save must stay disabled while the port is empty");
}
void TestXrayPagesUi::mainEmptyPortErrorOnFocusOut()
{
XRAY_LOAD("PageProtocolXraySettings");
QQuickItem *portField = typed("TextFieldType", "headerText", QStringLiteral("Port"));
QQuickItem *port = input(portField);
QVERIFY(port);
clearAndType(port, QString(), false);
port->setProperty("focus", false);
QTest::qWait(50);
QCOMPARE(portField->property("errorText").toString(), QStringLiteral("The field can't be empty"));
click(port);
type(QStringLiteral("1"));
QCOMPARE(portField->property("errorText").toString(), QString());
}
void TestXrayPagesUi::mainPortFollowsModelOnlyWhenUnfocused()
{
XRAY_LOAD("PageProtocolXraySettings");
QQuickItem *port = field(QStringLiteral("Port"));
QVERIFY(port);
m_model->setPort(QStringLiteral("2053"));
QCOMPARE(port->property("text").toString(), QStringLiteral("2053"));
click(port);
m_model->setPort(QStringLiteral("9999"));
QCOMPARE(port->property("text").toString(), QStringLiteral("2053"));
}
void TestXrayPagesUi::mainSaveRefusesInvalidPort()
{
XRAY_LOAD("PageProtocolXraySettings");
m_model->setPort(QStringLiteral("0"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
QQuickItem *save = saveButton();
QVERIFY(save && save->isEnabled());
click(save);
QCOMPARE(errors.count(), 1);
QCOMPARE(errors.first().first().toString(), QStringLiteral("Port must be in the range of 1 to 65535"));
}
void TestXrayPagesUi::mainSaveJoinsErrors()
{
XRAY_LOAD("PageProtocolXraySettings");
m_model->setPort(QStringLiteral("0"));
m_model->setSni(QStringLiteral("*"));
m_model->setXhttpHost(QStringLiteral("bad host"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
click(saveButton());
QCOMPARE(errors.count(), 1);
QCOMPARE(errors.first().first().toString(),
QStringLiteral("Port must be in the range of 1 to 65535\n"
"SNI: enter a valid IP address or domain name\n"
"Host: enter a valid IP address or domain name"));
}
void TestXrayPagesUi::mainPortChangeDialog()
{
XRAY_LOAD("PageProtocolXraySettings");
XRAY_QUESTIONS(questions);
clearAndType(field(QStringLiteral("Port")), QStringLiteral("8443"));
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(0).toString(), QStringLiteral("Save settings?"));
QCOMPARE(questions.first().at(1).toString(), kPortChangeText);
QCOMPARE(questions.first().at(2).toString(), QStringLiteral("Continue"));
QCOMPARE(questions.first().at(3).toString(), QStringLiteral("Cancel"));
answer(questions, false);
}
void TestXrayPagesUi::mainTransportSubtitle_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("subtitle");
QTest::newRow("raw") << "raw" << "RAW (TCP)";
QTest::newRow("xhttp") << "xhttp" << "XHTTP";
QTest::newRow("mkcp") << "mkcp" << "mKCP";
}
void TestXrayPagesUi::mainTransportSubtitle()
{
QFETCH(QString, transport);
QFETCH(QString, subtitle);
XRAY_LOAD("PageProtocolXraySettings");
m_model->setTransport(transport);
QQuickItem *row = typed("ListItemType", "text", QStringLiteral("Transport"));
QVERIFY(row);
QCOMPARE(row->property("subtitle").toString(), subtitle);
}
void TestXrayPagesUi::mainSecuritySubtitle_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("subtitle");
QTest::newRow("raw + none") << "raw" << "none" << "None";
QTest::newRow("raw + tls") << "raw" << "tls" << "TLS";
QTest::newRow("raw + reality") << "raw" << "reality" << "Reality";
QTest::newRow("mkcp + tls") << "mkcp" << "tls" << "TLS";
QTest::newRow("mkcp + reality shows None") << "mkcp" << "reality" << "None";
}
void TestXrayPagesUi::mainSecuritySubtitle()
{
QFETCH(QString, transport);
QFETCH(QString, security);
QFETCH(QString, subtitle);
XRAY_LOAD("PageProtocolXraySettings");
m_model->setTransport(transport);
m_model->setSecurity(security);
QQuickItem *row = typed("ListItemType", "text", QStringLiteral("Security"));
QVERIFY(row);
QCOMPARE(row->property("subtitle").toString(), subtitle);
}
void TestXrayPagesUi::mainFlowSubtitle_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("flow");
QTest::addColumn<QString>("subtitle");
QTest::newRow("raw + tls + vision") << "raw" << "tls" << "xtls-rprx-vision" << "xtls-rprx-vision";
QTest::newRow("raw + reality + udp443") << "raw" << "reality" << "xtls-rprx-vision-udp443" << "xtls-rprx-vision-udp443";
QTest::newRow("raw + reality + empty") << "raw" << "reality" << "" << "Empty";
QTest::newRow("raw + none + vision") << "raw" << "none" << "xtls-rprx-vision" << "Empty";
QTest::newRow("xhttp + reality + vision") << "xhttp" << "reality" << "xtls-rprx-vision" << "Empty";
QTest::newRow("mkcp + tls + vision") << "mkcp" << "tls" << "xtls-rprx-vision" << "Empty";
}
void TestXrayPagesUi::mainFlowSubtitle()
{
QFETCH(QString, transport);
QFETCH(QString, security);
QFETCH(QString, flow);
QFETCH(QString, subtitle);
XRAY_LOAD("PageProtocolXraySettings");
m_model->setTransport(transport);
m_model->setSecurity(security);
m_model->setFlow(flow);
QQuickItem *row = typed("ListItemType", "text", QStringLiteral("Flow"));
QVERIFY(row);
QCOMPARE(row->property("subtitle").toString(), subtitle);
}
void TestXrayPagesUi::mainRowsNavigate_data()
{
QTest::addColumn<QString>("row");
QTest::addColumn<int>("page");
QTest::newRow("Transport") << "Transport" << static_cast<int>(PageLoader::PageEnum::PageProtocolXrayTransportSettings);
QTest::newRow("Security") << "Security" << static_cast<int>(PageLoader::PageEnum::PageProtocolXraySecuritySettings);
QTest::newRow("Flow") << "Flow" << static_cast<int>(PageLoader::PageEnum::PageProtocolXrayFlowSettings);
}
void TestXrayPagesUi::mainRowsNavigate()
{
QFETCH(QString, row);
QFETCH(int, page);
XRAY_LOAD("PageProtocolXraySettings");
QSignalSpy pages(m_pages, &PageController::goToPage);
click(typed("ListItemType", "text", row));
QCOMPARE(pages.count(), 1);
QCOMPARE(static_cast<int>(qvariant_cast<PageLoader::PageEnum>(pages.first().at(0))), page);
}
void TestXrayPagesUi::mainSnapshotsIconNavigates()
{
XRAY_LOAD("PageProtocolXraySettings");
QSignalSpy pages(m_pages, &PageController::goToPage);
QQuickItem *icon = iconButton(QStringLiteral("more-vertical.svg"));
QVERIFY(icon);
click(icon);
QCOMPARE(pages.count(), 1);
QCOMPARE(qvariant_cast<PageLoader::PageEnum>(pages.first().at(0)), PageLoader::PageEnum::PageProtocolXraySnapshots);
}
void TestXrayPagesUi::mainBackButtonClosesPage()
{
XRAY_LOAD("PageProtocolXraySettings");
QSignalSpy closed(m_pages, &PageController::closePage);
QQuickItem *back = iconButton(QStringLiteral("arrow-left.svg"));
QVERIFY(back);
click(back);
QCOMPARE(closed.count(), 1);
}
void TestXrayPagesUi::mainResetDialogTexts()
{
XRAY_LOAD("PageProtocolXraySettings");
XRAY_QUESTIONS(questions);
click(typed("ListItemType", "text", QStringLiteral("Reset settings")));
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(0).toString(), QStringLiteral("Reset settings?"));
QCOMPARE(questions.first().at(1).toString(), QStringLiteral("All XRay settings will be restored to defaults."));
QCOMPARE(questions.first().at(2).toString(), QStringLiteral("Reset"));
QCOMPARE(questions.first().at(3).toString(), QStringLiteral("Cancel"));
}
void TestXrayPagesUi::mainResetAccepted()
{
XrayServerConfig srv = xraytest::baseConfig("xhttp", "tls", "");
srv.port = QStringLiteral("8443");
storeAndOpen(srv);
XRAY_LOAD("PageProtocolXraySettings");
XRAY_QUESTIONS(questions);
QSignalSpy notes(m_pages, &PageController::showNotificationMessage);
click(typed("ListItemType", "text", QStringLiteral("Reset settings")));
QCOMPARE(questions.count(), 1);
answer(questions, true);
QCOMPARE(notes.count(), 1);
QCOMPARE(notes.first().at(0).toString(),
QStringLiteral("Settings were reset to defaults. Tap Save to apply them on the server."));
QCOMPARE(m_model->transport(), QStringLiteral("raw"));
QCOMPARE(m_model->security(), QStringLiteral("reality"));
QCOMPARE(m_model->flow(), QStringLiteral("xtls-rprx-vision"));
QCOMPARE(m_model->port(), QStringLiteral("443"));
QCOMPARE(m_model->sni(), QStringLiteral("www.googletagmanager.com"));
QCOMPARE(typed("ListItemType", "text", QStringLiteral("Transport"))->property("subtitle").toString(),
QStringLiteral("RAW (TCP)"));
QCOMPARE(typed("ListItemType", "text", QStringLiteral("Security"))->property("subtitle").toString(),
QStringLiteral("Reality"));
QCOMPARE(typed("ListItemType", "text", QStringLiteral("Flow"))->property("subtitle").toString(),
QStringLiteral("xtls-rprx-vision"));
QCOMPARE(field(QStringLiteral("Port"))->property("text").toString(), QStringLiteral("443"));
QVERIFY(saveButton()->isEnabled());
}
void TestXrayPagesUi::mainResetCancelled()
{
XRAY_LOAD("PageProtocolXraySettings");
XRAY_QUESTIONS(questions);
QSignalSpy notes(m_pages, &PageController::showNotificationMessage);
click(typed("ListItemType", "text", QStringLiteral("Reset settings")));
QCOMPARE(questions.count(), 1);
answer(questions, false);
QCOMPARE(notes.count(), 0);
QCOMPARE(m_model->transport(), QStringLiteral("xhttp"));
QVERIFY(!m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::mainKeyMigrationDialog()
{
XRAY_LOAD("PageProtocolXraySettings");
XRAY_QUESTIONS(questions);
QSignalSpy busy(m_pages, &PageController::showBusyIndicator);
emit m_core->m_installUiController->xrayKeyMigrationNeedsConfirm(QStringLiteral("MSG"));
QTest::qWait(50);
QCOMPARE(busy.count(), 1);
QCOMPARE(busy.first().at(0).toBool(), false);
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(0).toString(), QStringLiteral("Recreate XRay with new keys?"));
QCOMPARE(questions.first().at(1).toString(), QStringLiteral("MSG"));
QCOMPARE(questions.first().at(2).toString(), QStringLiteral("Continue"));
QCOMPARE(questions.first().at(3).toString(), QStringLiteral("Cancel"));
answer(questions, false);
}
void TestXrayPagesUi::mainReadOnlyServer()
{
selectServer(m_readOnlyServerId);
storeAndOpen(xraytest::baseConfig("xhttp", "reality", ""), m_readOnlyServerId);
XRAY_LOAD("PageProtocolXraySettings");
QSignalSpy pages(m_pages, &PageController::goToPage);
QVERIFY(!typed("ListItemType", "text", QStringLiteral("Reset settings"))->isVisible());
QVERIFY(!saveButton()->isVisible());
QVERIFY(!field(QStringLiteral("Port"))->isEnabled());
for (const QString &row : { QStringLiteral("Transport"), QStringLiteral("Security"), QStringLiteral("Flow") })
QVERIFY2(!typed("ListItemType", "text", row)->isEnabled(), qPrintable(row));
click(typed("ListItemType", "text", QStringLiteral("Transport")));
QCOMPARE(pages.count(), 0);
}
void TestXrayPagesUi::mainWritableServerBaseline()
{
XRAY_LOAD("PageProtocolXraySettings");
QVERIFY(typed("ListItemType", "text", QStringLiteral("Reset settings"))->isVisible());
QQuickItem *save = saveButton();
QVERIFY(save->isVisible());
QVERIFY(!save->isEnabled());
}
+388
View File
@@ -0,0 +1,388 @@
#include "testXrayPagesUi.h"
using namespace amnezia;
namespace
{
const QString kSni = QStringLiteral("Server Name (SNI)");
const QString kSniError = QStringLiteral("Enter a valid IP address or domain name");
const QString kDeviceOnlyText =
QStringLiteral("The server will not be changed now. The new settings apply the next time you connect.");
const QString kServerBreaksSharedText = QStringLiteral(
"The server configuration will be updated. All users with whom you shared a connection with will no "
"longer be able to connect to it. You will need to share the connection again.");
const QStringList kFingerprints = { "hellochrome_120", "chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random" };
const QStringList kRealityFingerprints = { "hellochrome_120", "chrome", "firefox", "safari", "ios", "edge", "qq", "random" };
const QStringList kAlpn = { "h2", "http/1.1", "h2,http/1.1" };
}
void TestXrayPagesUi::securityMatrix_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("checked");
QTest::addColumn<bool>("realityEnabled");
QTest::addColumn<bool>("hint");
QTest::addColumn<bool>("alpn");
QTest::addColumn<bool>("tlsFingerprint");
QTest::addColumn<bool>("realityFingerprint");
QTest::addColumn<int>("sniFields");
for (const QString t : { QStringLiteral("raw"), QStringLiteral("xhttp") }) {
QTest::newRow(qPrintable(t + " + none")) << t << "none" << "None" << true << false << false << false << false << 0;
QTest::newRow(qPrintable(t + " + tls")) << t << "tls" << "TLS" << true << false << true << true << false << 1;
QTest::newRow(qPrintable(t + " + reality")) << t << "reality" << "Reality" << true << false << false << false << true << 1;
}
QTest::newRow("mkcp + none") << "mkcp" << "none" << "None" << false << true << false << false << false << 0;
QTest::newRow("mkcp + tls") << "mkcp" << "tls" << "TLS" << false << true << true << false << false << 1;
QTest::newRow("mkcp + reality shows None") << "mkcp" << "reality" << "None" << false << true << false << false << false << 0;
}
void TestXrayPagesUi::securityMatrix()
{
QFETCH(QString, transport);
QFETCH(QString, security);
QFETCH(QString, checked);
QFETCH(bool, realityEnabled);
QFETCH(bool, hint);
QFETCH(bool, alpn);
QFETCH(bool, tlsFingerprint);
QFETCH(bool, realityFingerprint);
QFETCH(int, sniFields);
openStored(xraytest::baseConfig(transport, security, ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
for (const QString &text : { QStringLiteral("None"), QStringLiteral("TLS"), QStringLiteral("Reality") }) {
QQuickItem *radio = typed("RadioItemType", "text", text);
QVERIFY(radio);
QCOMPARE(radio->property("checked").toBool(), text == checked);
}
QCOMPARE(typed("RadioItemType", "text", QStringLiteral("Reality"))->isEnabled(), realityEnabled);
QCOMPARE(typed("SmallTextType", "text",
QStringLiteral("REALITY is not supported with the mKCP transport. Use None or TLS."))->isVisible(),
hint);
QCOMPARE(typed("DropDownType", "descriptionText", QStringLiteral("ALPN"))->isVisible(), alpn);
QList<QQuickItem *> fingerprints;
for (QQuickItem *dd : allOfType("DropDownType")) {
if (dd->property("descriptionText").toString() == QLatin1String("Fingerprint"))
fingerprints << dd;
}
QCOMPARE(fingerprints.size(), 2);
QCOMPARE(fingerprints.at(0)->isVisible(), tlsFingerprint);
QCOMPARE(fingerprints.at(1)->isVisible(), realityFingerprint);
int visibleSni = 0;
for (QQuickItem *f : allOfType("TextFieldType")) {
if (f->property("headerText").toString() == kSni && f->isVisible())
++visibleSni;
}
QCOMPARE(visibleSni, sniFields);
}
void TestXrayPagesUi::securityRadioRoundTrip()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
click(typed("RadioItemType", "text", QStringLiteral("TLS")));
QCOMPARE(m_model->security(), QStringLiteral("tls"));
QVERIFY(typed("RadioItemType", "text", QStringLiteral("TLS"))->property("checked").toBool());
QVERIFY(!typed("RadioItemType", "text", QStringLiteral("Reality"))->property("checked").toBool());
QVERIFY(saveButton()->isEnabled());
click(typed("RadioItemType", "text", QStringLiteral("None")));
QCOMPARE(m_model->security(), QStringLiteral("none"));
click(typed("RadioItemType", "text", QStringLiteral("Reality")));
QCOMPARE(m_model->security(), QStringLiteral("reality"));
QVERIFY(!m_model->hasUnsavedChanges());
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::securityRealityNotClickableOnMkcp()
{
openStored(xraytest::baseConfig("mkcp", "tls", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *reality = typed("RadioItemType", "text", QStringLiteral("Reality"));
QVERIFY(reality && !reality->isEnabled());
click(reality);
QCOMPARE(m_model->security(), QStringLiteral("tls"));
QVERIFY(!m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::securityMkcpStoredReality()
{
openStored(xraytest::baseConfig("mkcp", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QVERIFY(typed("RadioItemType", "text", QStringLiteral("None"))->property("checked").toBool());
QCOMPARE(m_model->security(), QStringLiteral("reality"));
QVERIFY(!m_model->hasUnsavedChanges());
click(typed("RadioItemType", "text", QStringLiteral("None")));
QCOMPARE(m_model->security(), QStringLiteral("none"));
QVERIFY(saveButton()->isEnabled());
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(1).toString(), kDeviceOnlyText);
answer(questions, false);
}
void TestXrayPagesUi::securityDropDownOptions_data()
{
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("description");
QTest::addColumn<QStringList>("expected");
QTest::addColumn<QString>("current");
QTest::newRow("tls ALPN") << "tls" << "ALPN" << kAlpn << "h2";
QTest::newRow("tls Fingerprint") << "tls" << "Fingerprint" << kFingerprints << "hellochrome_120";
QTest::newRow("reality Fingerprint") << "reality" << "Fingerprint" << kRealityFingerprints << "hellochrome_120";
}
void TestXrayPagesUi::securityDropDownOptions()
{
QFETCH(QString, security);
QFETCH(QString, description);
QFETCH(QStringList, expected);
QFETCH(QString, current);
openStored(xraytest::baseConfig("raw", security, ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *dd = dropDown(description);
QVERIFY(dd && dd->isVisible());
QCOMPARE(optionNames(dd, false), expected);
QCOMPARE(optionNames(dd, true), QStringList { current });
}
void TestXrayPagesUi::securityDropDownRoundTrip_data()
{
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("description");
QTest::addColumn<QString>("option");
for (const QString &o : kAlpn)
QTest::newRow(qPrintable("ALPN = " + o)) << "tls" << "ALPN" << o;
for (const QString &o : kFingerprints)
QTest::newRow(qPrintable("tls Fingerprint = " + o)) << "tls" << "Fingerprint" << o;
for (const QString &o : kRealityFingerprints)
QTest::newRow(qPrintable("reality Fingerprint = " + o)) << "reality" << "Fingerprint" << o;
}
void TestXrayPagesUi::securityDropDownRoundTrip()
{
QFETCH(QString, security);
QFETCH(QString, description);
QFETCH(QString, option);
openStored(xraytest::baseConfig("raw", security, ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *dd = dropDown(description);
QVERIFY(dd);
QVERIFY(chooseOption(dd, option));
QCOMPARE(description == QLatin1String("ALPN") ? m_model->alpn() : m_model->fingerprint(), option);
QCOMPARE(dd->property("text").toString(), option);
const bool isDefault = option == QLatin1String("h2") || option == QLatin1String("hellochrome_120");
QCOMPARE(saveButton()->isEnabled(), !isDefault);
QCOMPARE(optionNames(dd, true), QStringList { option });
}
void TestXrayPagesUi::securityFingerprintSharedBetweenBlocks()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QVERIFY(chooseOption(dropDown(QStringLiteral("Fingerprint")), QStringLiteral("safari")));
click(typed("RadioItemType", "text", QStringLiteral("TLS")));
QQuickItem *tlsFingerprint = dropDown(QStringLiteral("Fingerprint"));
QVERIFY(tlsFingerprint && tlsFingerprint->isVisible());
QCOMPARE(tlsFingerprint->property("text").toString(), QStringLiteral("safari"));
QCOMPARE(optionNames(tlsFingerprint, true), QStringList { QStringLiteral("safari") });
}
void TestXrayPagesUi::securityValidSni()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(kSni);
QVERIFY(sni);
clearAndType(sni, QStringLiteral("vpn.example.org"));
QCOMPARE(m_model->sni(), QStringLiteral("vpn.example.org"));
QCOMPARE(m_model->site(), QStringLiteral("vpn.example.org"));
QCOMPARE(ownerField(sni)->property("errorText").toString(), QString());
QVERIFY(saveButton()->isEnabled());
}
void TestXrayPagesUi::securitySniSiteCoupling()
{
XrayServerConfig srv = xraytest::baseConfig("raw", "reality", "");
srv.sni = QStringLiteral("a.example.com");
srv.site = QStringLiteral("b.example.com");
openStored(srv);
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(kSni);
QVERIFY(sni);
click(sni);
key(Qt::Key_Return);
QCOMPARE(m_model->site(), QStringLiteral("b.example.com"));
QVERIFY(!m_model->hasUnsavedChanges());
key(Qt::Key_End);
key(Qt::Key_Backspace);
type(QStringLiteral("m"));
QCOMPARE(m_model->sni(), QStringLiteral("a.example.com"));
QCOMPARE(m_model->site(), QStringLiteral("a.example.com"));
QVERIFY(m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::securityInvalidSni_data()
{
QTest::addColumn<QString>("value");
QTest::newRow("no tld: localhost") << "localhost";
QTest::newRow("no tld: example") << "example";
QTest::newRow("digits only") << "123";
QTest::newRow("bad ipv4") << "999.1.1.1";
QTest::newRow("short ipv4") << "1.2.3";
}
void TestXrayPagesUi::securityInvalidSni()
{
QFETCH(QString, value);
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(kSni);
QQuickItem *sniField = ownerField(sni);
QVERIFY(sniField);
clearAndType(sni, value);
QCOMPARE(m_model->sni(), value);
QCOMPARE(sniField->property("errorText").toString(), kSniError);
type(QStringLiteral("x"));
QCOMPARE(sniField->property("errorText").toString(), QString());
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
click(saveButton());
QCOMPARE(errors.count(), 1);
QCOMPARE(errors.first().first().toString(), QStringLiteral("SNI: enter a valid IP address or domain name"));
}
void TestXrayPagesUi::securityIpv4Sni()
{
openStored(xraytest::baseConfig("raw", "tls", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
clearAndType(visibleField(kSni), QStringLiteral("1.2.3.4"));
QCOMPARE(m_model->sni(), QStringLiteral("1.2.3.4"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 1);
answer(questions, false);
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
clearAndType(visibleField(kSni), QStringLiteral("1.2.3.4"));
QCOMPARE(m_model->sni(), QStringLiteral("1.2.3.4"));
QSignalSpy realityErrors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
click(saveButton());
QCOMPARE(realityErrors.count(), 1);
QCOMPARE(realityErrors.first().first().toString(),
QStringLiteral("REALITY needs a domain name in SNI, not an IP address"));
}
void TestXrayPagesUi::securitySniFilter()
{
openStored(xraytest::baseConfig("raw", "tls", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(kSni);
clearAndType(sni, QStringLiteral("a b:c/d_e*"), false);
QCOMPARE(sni->property("text").toString(), QStringLiteral("ab:cd_e"));
QCOMPARE(m_model->sni(), QStringLiteral("ab:cd_e"));
}
void TestXrayPagesUi::securityEmptySni()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(kSni);
clearAndType(sni, QString());
QCOMPARE(m_model->sni(), QString());
QCOMPARE(m_model->site(), QString());
QCOMPARE(sni->property("placeholderText").toString(), QStringLiteral("www.googletagmanager.com"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 1);
answer(questions, false);
}
void TestXrayPagesUi::securitySniErrorOnFocusOut()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(kSni);
QQuickItem *sniField = ownerField(sni);
QVERIFY(sniField);
clearAndType(sni, QStringLiteral("localhost"), false);
QCOMPARE(sniField->property("errorText").toString(), QString());
sni->setProperty("focus", false);
QTest::qWait(50);
QCOMPARE(sniField->property("errorText").toString(), kSniError);
}
void TestXrayPagesUi::securityNoneIgnoresSni()
{
openStored(xraytest::baseConfig("raw", "none", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
m_model->setSni(QStringLiteral("*"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 1);
answer(questions, false);
}
void TestXrayPagesUi::securitySaveDialogDescription_data()
{
QTest::addColumn<QString>("security");
QTest::addColumn<QString>("edit");
QTest::addColumn<QString>("expected");
QTest::newRow("fingerprint is device-only") << "reality" << "fingerprint" << kDeviceOnlyText;
QTest::newRow("alpn breaks shared configs") << "tls" << "alpn" << kServerBreaksSharedText;
QTest::newRow("reality to tls breaks shared configs") << "reality" << "security" << kServerBreaksSharedText;
QTest::newRow("sni breaks shared configs") << "reality" << "sni" << kServerBreaksSharedText;
}
void TestXrayPagesUi::securitySaveDialogDescription()
{
QFETCH(QString, security);
QFETCH(QString, edit);
QFETCH(QString, expected);
openStored(xraytest::baseConfig("raw", security, ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
if (edit == QLatin1String("fingerprint"))
QVERIFY(chooseOption(dropDown(QStringLiteral("Fingerprint")), QStringLiteral("firefox")));
else if (edit == QLatin1String("alpn"))
QVERIFY(chooseOption(dropDown(QStringLiteral("ALPN")), QStringLiteral("http/1.1")));
else if (edit == QLatin1String("security"))
click(typed("RadioItemType", "text", QStringLiteral("TLS")));
else if (edit == QLatin1String("sni"))
clearAndType(visibleField(kSni), QStringLiteral("www.example.org"));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(0).toString(), QStringLiteral("Save settings?"));
QCOMPARE(questions.first().at(1).toString(), expected);
answer(questions, false);
}
+759
View File
@@ -0,0 +1,759 @@
#include "testXrayPagesUi.h"
#include "ui/utils/pageEnum.h"
using namespace amnezia;
namespace
{
const QString kDeviceOnlyText =
QStringLiteral("The server will not be changed now. The new settings apply the next time you connect.");
const QString kServerKeepsSharedText = QStringLiteral(
"The server configuration will be updated. If XRay on the server is outdated, the container will be "
"recreated with the current version; connections that were already shared keep working.");
const QString kServerBreaksSharedText = QStringLiteral(
"The server configuration will be updated. All users with whom you shared a connection with will no "
"longer be able to connect to it. You will need to share the connection again.");
QString xhttpValue(const XrayConfigModel *m, const QString &header)
{
if (header == QLatin1String("Mode"))
return m->xhttpMode();
if (header == QLatin1String("UplinkHTTPMethod"))
return m->xhttpUplinkMethod();
if (header == QLatin1String("SessionPlacement"))
return m->xhttpSessionPlacement();
if (header == QLatin1String("SeqPlacement"))
return m->xhttpSeqPlacement();
if (header == QLatin1String("UplinkDataPlacement"))
return m->xhttpUplinkDataPlacement();
if (header == QLatin1String("SessionKey"))
return m->xhttpSessionKey();
if (header == QLatin1String("SeqKey"))
return m->xhttpSeqKey();
if (header == QLatin1String("UplinkDataKey"))
return m->xhttpUplinkDataKey();
if (header == QLatin1String("UplinkChunkSize"))
return m->xhttpUplinkChunkSize();
if (header == QLatin1String("scMaxBufferedPosts"))
return m->xhttpScMaxBufferedPosts();
if (header == QLatin1String("TTI"))
return m->mkcpTti();
if (header == QLatin1String("uplinkCapacity"))
return m->mkcpUplinkCapacity();
if (header == QLatin1String("downlinkCapacity"))
return m->mkcpDownlinkCapacity();
if (header == QLatin1String("mtu"))
return m->mkcpMtu();
if (header == QLatin1String("cwndMultiplier"))
return m->mkcpCwndMultiplier();
if (header == QLatin1String("maxSendingWindow"))
return m->mkcpMaxSendingWindow();
return QStringLiteral("<unknown field %1>").arg(header);
}
XrayServerConfig packetUpTls()
{
XrayServerConfig srv = xraytest::baseConfig("xhttp", "tls", "");
srv.xhttp.mode = QStringLiteral("Packet-up");
srv.xhttp.sessionPlacement = QStringLiteral("Header");
srv.xhttp.seqPlacement = QStringLiteral("Header");
srv.xhttp.uplinkDataPlacement = QStringLiteral("Header");
return srv;
}
}
void TestXrayPagesUi::transportXhttpRadioSubtitle()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *radio = typed("RadioItemType", "text", QStringLiteral("XHTTP"));
QVERIFY(radio);
QCOMPARE(radio->property("subtitle").toString(), QStringLiteral("Advanced users"));
}
void TestXrayPagesUi::transportRadioCheckedFollowsModel_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("checkedText");
QTest::newRow("raw") << "raw" << "RAW (TCP)";
QTest::newRow("xhttp") << "xhttp" << "XHTTP";
QTest::newRow("mkcp") << "mkcp" << "mKCP";
}
void TestXrayPagesUi::transportRadioCheckedFollowsModel()
{
QFETCH(QString, transport);
QFETCH(QString, checkedText);
openStored(xraytest::baseConfig(transport, "tls", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
for (const QString &text : { QStringLiteral("RAW (TCP)"), QStringLiteral("XHTTP"), QStringLiteral("mKCP") }) {
QQuickItem *radio = typed("RadioItemType", "text", text);
QVERIFY(radio);
QCOMPARE(radio->property("checked").toBool(), text == checkedText);
}
}
void TestXrayPagesUi::transportRadioReturnKey()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *radio = typed("RadioItemType", "text", QStringLiteral("RAW (TCP)"));
QVERIFY(radio);
radio->forceActiveFocus();
key(Qt::Key_Return);
QCOMPARE(m_model->transport(), QStringLiteral("raw"));
}
void TestXrayPagesUi::transportSectionVisibility_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<bool>("mkcpVisible");
QTest::addColumn<bool>("xhttpVisible");
QTest::newRow("raw") << "raw" << false << false;
QTest::newRow("xhttp") << "xhttp" << false << true;
QTest::newRow("mkcp") << "mkcp" << true << false;
}
void TestXrayPagesUi::transportSectionVisibility()
{
QFETCH(QString, transport);
QFETCH(bool, mkcpVisible);
QFETCH(bool, xhttpVisible);
openStored(xraytest::baseConfig(transport, "tls", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
QCOMPARE(typed("TextFieldType", "headerText", QStringLiteral("TTI"))->isVisible(), mkcpVisible);
QCOMPARE(typed("SmallTextType", "text", QStringLiteral("mKCP Settings"))->isVisible(), mkcpVisible);
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("Mode"))->isVisible(), xhttpVisible);
}
void TestXrayPagesUi::transportRawToXhttpFillsDefaults()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
QCOMPARE(m_model->xhttpMode(), QString());
XRAY_LOAD("PageProtocolXrayTransportSettings");
click(typed("RadioItemType", "text", QStringLiteral("XHTTP")));
QCOMPARE(m_model->transport(), QStringLiteral("xhttp"));
QCOMPARE(m_model->xhttpMode(), QStringLiteral("Stream-one"));
QCOMPARE(m_model->xhttpUplinkMethod(), QStringLiteral("POST"));
QCOMPARE(m_model->xhttpSessionPlacement(), QStringLiteral("Path"));
QCOMPARE(m_model->xhttpSeqPlacement(), QStringLiteral("Path"));
QCOMPARE(m_model->xhttpUplinkDataPlacement(), QStringLiteral("Body"));
QCOMPARE(m_model->xhttpHost(), QStringLiteral("www.googletagmanager.com"));
QCOMPARE(m_model->xhttpScMaxEachPostBytesMin(), QStringLiteral("1000000"));
QCOMPARE(m_model->xhttpScMaxEachPostBytesMax(), QStringLiteral("1000000"));
QCOMPARE(m_model->xhttpScMinPostsIntervalMsMin(), QStringLiteral("100"));
QCOMPARE(m_model->xhttpScMinPostsIntervalMsMax(), QStringLiteral("800"));
QCOMPARE(m_model->xhttpScStreamUpServerSecsMin(), QStringLiteral("1"));
QCOMPARE(m_model->xhttpScStreamUpServerSecsMax(), QStringLiteral("100"));
QCOMPARE(m_model->xhttpPath(), QString());
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("Mode"))->property("text").toString(),
QStringLiteral("Stream-one"));
}
void TestXrayPagesUi::transportSwitchKeepsXhttpValues()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
m_model->setXhttpHost(QStringLiteral("a.com"));
click(typed("RadioItemType", "text", QStringLiteral("mKCP")));
QCOMPARE(m_model->transport(), QStringLiteral("mkcp"));
QCOMPARE(m_model->xhttpHost(), QStringLiteral("a.com"));
}
void TestXrayPagesUi::transportPacketUpFieldsMoreRows_data()
{
QTest::addColumn<QString>("mode");
QTest::addColumn<QString>("security");
QTest::addColumn<bool>("seqVisible");
QTest::addColumn<bool>("dataVisible");
QTest::newRow("packet-up + reality") << "Packet-up" << "reality" << true << true;
QTest::newRow("auto + tls") << "Auto" << "tls" << true << false;
QTest::newRow("empty + none") << "" << "none" << true << false;
QTest::newRow("empty + reality") << "" << "reality" << false << false;
QTest::newRow("stream-up + none") << "Stream-up" << "none" << false << false;
QTest::newRow("stream-one + tls") << "Stream-one" << "tls" << false << false;
}
void TestXrayPagesUi::transportPacketUpFieldsMoreRows()
{
QFETCH(QString, mode);
QFETCH(QString, security);
QFETCH(bool, seqVisible);
QFETCH(bool, dataVisible);
XrayServerConfig srv = xraytest::baseConfig("xhttp", security, "");
srv.xhttp.seqPlacement = QStringLiteral("Header");
srv.xhttp.uplinkDataPlacement = QStringLiteral("Header");
openStored(srv);
XRAY_LOAD("PageProtocolXrayTransportSettings");
m_model->setXhttpMode(mode);
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("SeqPlacement"))->isVisible(), seqVisible);
QCOMPARE(typed("TextFieldType", "headerText", QStringLiteral("SeqKey"))->isVisible(), seqVisible);
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("UplinkDataPlacement"))->isVisible(), dataVisible);
QCOMPARE(typed("TextFieldType", "headerText", QStringLiteral("UplinkDataKey"))->isVisible(), dataVisible);
}
void TestXrayPagesUi::transportPacketUpFieldsFollowModeLive()
{
XrayServerConfig srv = xraytest::baseConfig("xhttp", "tls", "");
srv.xhttp.seqPlacement = QStringLiteral("Header");
openStored(srv);
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *seqKey = typed("TextFieldType", "headerText", QStringLiteral("SeqKey"));
QQuickItem *mode = typed("DropDownType", "headerText", QStringLiteral("Mode"));
QVERIFY(seqKey && mode);
QVERIFY(!seqKey->isVisible());
QVERIFY(chooseOption(mode, QStringLiteral("Packet-up")));
QVERIFY(seqKey->isVisible());
QVERIFY(chooseOption(mode, QStringLiteral("Stream-up")));
QVERIFY(!seqKey->isVisible());
}
void TestXrayPagesUi::transportAlwaysVisibleXhttpControls_data()
{
QTest::addColumn<QString>("mode");
QTest::newRow("Auto") << "Auto";
QTest::newRow("Packet-up") << "Packet-up";
QTest::newRow("Stream-up") << "Stream-up";
QTest::newRow("Stream-one") << "Stream-one";
}
void TestXrayPagesUi::transportAlwaysVisibleXhttpControls()
{
QFETCH(QString, mode);
XrayServerConfig srv = xraytest::baseConfig("xhttp", "tls", "");
srv.xhttp.mode = mode;
openStored(srv);
XRAY_LOAD("PageProtocolXrayTransportSettings");
QVERIFY(typed("DropDownType", "headerText", QStringLiteral("UplinkHTTPMethod"))->isVisible());
for (const QString &h : { QStringLiteral("Host"), QStringLiteral("Path") })
QVERIFY2(typed("TextFieldType", "headerText", h)->isVisible(), qPrintable(h));
QVERIFY(typed("SwitchRowType", "descriptionText", QStringLiteral("noSSEHeader"))->isVisible());
QCOMPARE(typed("DropDownType", "headerText", QStringLiteral("SessionPlacement"))->isVisible(),
mode != QLatin1String("Stream-one"));
}
void TestXrayPagesUi::transportDropDownOptions_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QStringList>("expected");
QTest::newRow("Mode") << "Mode" << QStringList { "Auto", "Packet-up", "Stream-up", "Stream-one" };
QTest::newRow("UplinkHTTPMethod") << "UplinkHTTPMethod" << QStringList { "POST", "PUT", "PATCH" };
QTest::newRow("SessionPlacement") << "SessionPlacement" << QStringList { "Path", "Header", "Cookie", "Query" };
QTest::newRow("SeqPlacement") << "SeqPlacement" << QStringList { "Path", "Header", "Cookie", "Query" };
QTest::newRow("UplinkDataPlacement") << "UplinkDataPlacement" << QStringList { "Body", "Auto", "Header", "Cookie" };
}
void TestXrayPagesUi::transportDropDownOptions()
{
QFETCH(QString, header);
QFETCH(QStringList, expected);
openStored(packetUpTls());
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *dd = typed("DropDownType", "headerText", header);
QVERIFY(dd);
QCOMPARE(optionNames(dd, false), expected);
QCOMPARE(optionNames(dd, true), QStringList { xhttpValue(m_model, header) });
}
void TestXrayPagesUi::transportDropDownRoundTrip_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QString>("option");
const QList<QPair<QString, QStringList>> lists = {
{ "Mode", { "Auto", "Packet-up", "Stream-up", "Stream-one" } },
{ "UplinkHTTPMethod", { "POST", "PUT", "PATCH" } },
{ "SessionPlacement", { "Path", "Header", "Cookie", "Query" } },
{ "SeqPlacement", { "Path", "Header", "Cookie", "Query" } },
{ "UplinkDataPlacement", { "Body", "Auto", "Header", "Cookie" } },
};
for (const auto &list : lists) {
for (const QString &option : list.second)
QTest::newRow(qPrintable(list.first + QStringLiteral(" = ") + option)) << list.first << option;
}
}
void TestXrayPagesUi::transportDropDownRoundTrip()
{
QFETCH(QString, header);
QFETCH(QString, option);
openStored(packetUpTls());
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *dd = typed("DropDownType", "headerText", header);
QVERIFY(dd);
QVERIFY(chooseOption(dd, option));
QCOMPARE(xhttpValue(m_model, header), option);
QCOMPARE(dd->property("text").toString(), option);
QCOMPARE(optionNames(dd, true), QStringList { option });
}
void TestXrayPagesUi::transportDropDownEscape()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *dd = typed("DropDownType", "headerText", QStringLiteral("Mode"));
QObject *popup = openDropDown(dd);
QVERIFY(popup);
QVERIFY(closeWithEscape(popup));
QCOMPARE(m_model->xhttpMode(), QStringLiteral("Stream-one"));
QVERIFY(!m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::transportChoosingCurrentModeIsNoChange()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QVERIFY(chooseOption(typed("DropDownType", "headerText", QStringLiteral("Mode")), QStringLiteral("Stream-one")));
QVERIFY(!m_model->hasUnsavedChanges());
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::transportPacketUpRealityAllowed()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QVERIFY(chooseOption(typed("DropDownType", "headerText", QStringLiteral("Mode")), QStringLiteral("Packet-up")));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 1);
answer(questions, false);
}
void TestXrayPagesUi::transportSwitches_data()
{
QTest::addColumn<QString>("description");
QTest::newRow("noGRPCHeader") << "noGRPCHeader";
QTest::newRow("noSSEHeader") << "noSSEHeader";
}
void TestXrayPagesUi::transportSwitches()
{
QFETCH(QString, description);
XRAY_LOAD("PageProtocolXrayTransportSettings");
auto value = [this, &description] {
return description == QLatin1String("noGRPCHeader") ? m_model->xhttpDisableGrpc() : m_model->xhttpDisableSse();
};
QQuickItem *sw = switcherOf(typed("SwitchRowType", "descriptionText", description));
QVERIFY(sw);
QCOMPARE(value(), true);
QCOMPARE(sw->property("checked").toBool(), true);
click(sw);
QCOMPARE(value(), false);
QVERIFY(m_model->hasUnsavedChanges());
QVERIFY(saveButton()->isEnabled());
click(sw);
QCOMPARE(value(), true);
QVERIFY(!m_model->hasUnsavedChanges());
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::transportSwitchLabelToggles()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *label = typed("BodyTextType", "text", QStringLiteral("Disable gRPC Header"));
QVERIFY(label);
click(label);
QCOMPARE(m_model->xhttpDisableGrpc(), false);
}
void TestXrayPagesUi::transportHostFilter()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *host = field(QStringLiteral("Host"));
QVERIFY(host);
clearAndType(host, QStringLiteral("a b/c*@!"), false);
QCOMPARE(host->property("text").toString(), QStringLiteral("abc"));
QCOMPARE(m_model->xhttpHost(), QStringLiteral("abc"));
}
void TestXrayPagesUi::transportHostValidity_data()
{
QTest::addColumn<QString>("value");
QTest::addColumn<bool>("valid");
QTest::newRow("domain") << "example.com" << true;
QTest::newRow("ipv4") << "1.2.3.4" << true;
QTest::newRow("ipv6") << "::1" << true;
QTest::newRow("digits only") << "12345" << false;
QTest::newRow("no tld") << "localhost" << false;
QTest::newRow("short ipv4") << "1.2.3" << false;
QTest::newRow("two hosts") << "a.com,b.com" << false;
QTest::newRow("host with port") << "example.com:443" << false;
}
void TestXrayPagesUi::transportHostValidity()
{
QFETCH(QString, value);
QFETCH(bool, valid);
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *hostField = typed("TextFieldType", "headerText", QStringLiteral("Host"));
clearAndType(input(hostField), value);
QCOMPARE(m_model->xhttpHost(), value);
QCOMPARE(hostField->property("errorText").toString(),
valid ? QString() : QStringLiteral("Enter a valid IP address or domain name"));
QCOMPARE(XrayConfigModel::isValidHost(value), valid);
if (!valid) {
type(QStringLiteral("x"));
QCOMPARE(hostField->property("errorText").toString(), QString());
}
}
void TestXrayPagesUi::transportEmptyHost()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *hostField = typed("TextFieldType", "headerText", QStringLiteral("Host"));
clearAndType(input(hostField), QString());
QCOMPARE(m_model->xhttpHost(), QString());
QCOMPARE(hostField->property("errorText").toString(), QString());
QCOMPARE(hostField->property("placeholderText").toString(), QStringLiteral("www.googletagmanager.com"));
}
void TestXrayPagesUi::transportSaveRefusesInvalidHost()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
m_model->setXhttpHost(QStringLiteral("12345"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
click(saveButton());
QCOMPARE(errors.count(), 1);
QCOMPARE(errors.first().first().toString(), QStringLiteral("Host: enter a valid IP address or domain name"));
}
void TestXrayPagesUi::transportPathFilter()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *path = field(QStringLiteral("Path"));
clearAndType(path, QStringLiteral("a b|c"), false);
QCOMPARE(path->property("text").toString(), QStringLiteral("abc"));
key(Qt::Key_Return);
QCOMPARE(m_model->xhttpPath(), QStringLiteral("/abc"));
}
void TestXrayPagesUi::transportPathEdgeCases_data()
{
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("expected");
QTest::newRow("empty stays empty") << "" << "";
QTest::newRow("slash kept") << "/x" << "/x";
QTest::newRow("nested gets slash") << "x/y" << "/x/y";
QTest::newRow("query kept") << "p?a=1" << "/p?a=1";
}
void TestXrayPagesUi::transportPathEdgeCases()
{
QFETCH(QString, typed);
QFETCH(QString, expected);
XRAY_LOAD("PageProtocolXrayTransportSettings");
clearAndType(field(QStringLiteral("Path")), typed);
QCOMPARE(m_model->xhttpPath(), expected);
}
void TestXrayPagesUi::transportKeyFieldsFilter_data()
{
QTest::addColumn<QString>("header");
QTest::newRow("SessionKey") << "SessionKey";
QTest::newRow("SeqKey") << "SeqKey";
QTest::newRow("UplinkDataKey") << "UplinkDataKey";
}
void TestXrayPagesUi::transportKeyFieldsFilter()
{
QFETCH(QString, header);
openStored(packetUpTls());
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *f = field(header);
QVERIFY(f);
clearAndType(f, QStringLiteral("a.b c/d=e_-"));
QCOMPARE(f->property("text").toString(), QStringLiteral("abcde_-"));
QCOMPARE(xhttpValue(m_model, header), QStringLiteral("abcde_-"));
}
void TestXrayPagesUi::transportNumberFields_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("expected");
for (const QString h : { QStringLiteral("UplinkChunkSize"), QStringLiteral("scMaxBufferedPosts") }) {
QTest::newRow(qPrintable(h + QStringLiteral(": above max is clamped")))
<< h << "9999999999"
<< (h == QLatin1String("scMaxBufferedPosts") ? "100000" : "2147483647");
QTest::newRow(qPrintable(h + QStringLiteral(": leading zeros"))) << h << "007" << "7";
QTest::newRow(qPrintable(h + QStringLiteral(": letters blocked"))) << h << "12a-3" << "123";
QTest::newRow(qPrintable(h + QStringLiteral(": zero"))) << h << "0" << "0";
QTest::newRow(qPrintable(h + QStringLiteral(": empty"))) << h << "" << "";
}
}
void TestXrayPagesUi::transportNumberFields()
{
QFETCH(QString, header);
QFETCH(QString, typed);
QFETCH(QString, expected);
openStored(packetUpTls());
XRAY_LOAD("PageProtocolXrayTransportSettings");
clearAndType(field(header), typed);
QCOMPARE(xhttpValue(m_model, header), expected);
}
void TestXrayPagesUi::transportMinMaxRows_data()
{
QTest::addColumn<int>("row");
QTest::addColumn<QString>("minBefore");
QTest::addColumn<QString>("maxBefore");
QTest::addColumn<QString>("which");
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("minAfter");
QTest::addColumn<QString>("maxAfter");
QTest::newRow("minPosts: min above max raises max") << 2 << "100" << "800" << "Min" << "900" << "900" << "900";
QTest::newRow("minPosts: max below min is raised") << 2 << "100" << "800" << "Max" << "50" << "100" << "100";
QTest::newRow("minPosts: empty min uses placeholder") << 2 << "" << "800" << "Max" << "20" << "" << "30";
QTest::newRow("minPosts: clear min") << 2 << "100" << "800" << "Min" << "" << "" << "800";
QTest::newRow("minPosts: leading zeros") << 2 << "100" << "800" << "Min" << "007" << "7" << "800";
QTest::newRow("streamUp: min above empty max placeholder") << 1 << "1" << "" << "Min" << "200" << "200" << "200";
QTest::newRow("eachPost: max below min") << 0 << "1000000" << "1000000" << "Max" << "5" << "1000000" << "1000000";
}
void TestXrayPagesUi::transportMinMaxRows()
{
QFETCH(int, row);
QFETCH(QString, minBefore);
QFETCH(QString, maxBefore);
QFETCH(QString, which);
QFETCH(QString, typed);
QFETCH(QString, minAfter);
QFETCH(QString, maxAfter);
XrayServerConfig srv = packetUpTls();
if (row == 1)
srv.xhttp.mode = QStringLiteral("Stream-up");
openStored(srv);
XRAY_LOAD("PageProtocolXrayTransportSettings");
auto setRow = [this, row](const QString &mn, const QString &mx) {
if (row == 0) {
m_model->setXhttpScMaxEachPostBytesMin(mn);
m_model->setXhttpScMaxEachPostBytesMax(mx);
} else if (row == 1) {
m_model->setXhttpScStreamUpServerSecsMin(mn);
m_model->setXhttpScStreamUpServerSecsMax(mx);
} else {
m_model->setXhttpScMinPostsIntervalMsMin(mn);
m_model->setXhttpScMinPostsIntervalMsMax(mx);
}
};
auto rowValues = [this, row] {
if (row == 0)
return qMakePair(m_model->xhttpScMaxEachPostBytesMin(), m_model->xhttpScMaxEachPostBytesMax());
if (row == 1)
return qMakePair(m_model->xhttpScStreamUpServerSecsMin(), m_model->xhttpScStreamUpServerSecsMax());
return qMakePair(m_model->xhttpScMinPostsIntervalMsMin(), m_model->xhttpScMinPostsIntervalMsMax());
};
setRow(minBefore, maxBefore);
QQuickItem *rowItem = minMaxRow(row);
QVERIFY(rowItem);
clearAndType(minMaxInput(rowItem, which), typed);
QCOMPARE(rowValues().first, minAfter);
QCOMPARE(rowValues().second, maxAfter);
}
void TestXrayPagesUi::transportMinMaxOverflow()
{
openStored(packetUpTls());
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *minInput = minMaxInput(minMaxRow(2), QStringLiteral("Min"));
QVERIFY(minInput);
clearAndType(minInput, QStringLiteral("9999999999"), false);
QCOMPARE(minInput->property("text").toString(), QStringLiteral("999999999"));
QCOMPARE(m_model->xhttpScMinPostsIntervalMsMin(), QStringLiteral("999999999"));
clearAndType(minInput, QStringLiteral("-12a"), false);
QCOMPARE(minInput->property("text").toString(), QStringLiteral("12"));
QVERIFY(typed("SmallTextType", "text", QStringLiteral("≤ 2147483647. Empty = core default (1000000).")));
}
void TestXrayPagesUi::transportMkcpPlaceholders_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QString>("placeholder");
QTest::addColumn<QString>("helper");
QTest::newRow("TTI") << "TTI" << "50" << "Transmission time interval (ms). Valid range: 10–100.";
QTest::newRow("uplinkCapacity") << "uplinkCapacity" << "5" << "Uplink capacity (MB/s). Maximum: 4095.";
QTest::newRow("downlinkCapacity") << "downlinkCapacity" << "20" << "Downlink capacity (MB/s). Maximum: 4095.";
QTest::newRow("mtu") << "mtu" << "1350" << "Maximum packet size in bytes. Range: 576–1460.";
QTest::newRow("cwndMultiplier") << "cwndMultiplier" << "1" << "Congestion window multiplier. Range: 1–5000.";
QTest::newRow("maxSendingWindow") << "maxSendingWindow" << ""
<< "Send window in bytes. Must not be smaller than mtu. Leave empty to let Xray decide.";
}
void TestXrayPagesUi::transportMkcpPlaceholders()
{
QFETCH(QString, header);
QFETCH(QString, placeholder);
QFETCH(QString, helper);
openStored(xraytest::baseConfig("mkcp", "none", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
QQuickItem *f = typed("TextFieldType", "headerText", header);
QVERIFY(f && f->isVisible());
QCOMPARE(f->property("placeholderText").toString(), placeholder);
QCOMPARE(f->property("helperText").toString(), helper);
}
void TestXrayPagesUi::transportMkcpClamps_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<QString>("mtuBefore");
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("expected");
QTest::newRow("TTI 101 cannot be typed") << "TTI" << "" << "101" << "10";
QTest::newRow("TTI 100") << "TTI" << "" << "100" << "100";
QTest::newRow("TTI 5 -> 10") << "TTI" << "" << "5" << "10";
QTest::newRow("TTI 0 -> 10") << "TTI" << "" << "0" << "10";
QTest::newRow("TTI 05 -> 10") << "TTI" << "" << "05" << "10";
QTest::newRow("TTI empty") << "TTI" << "" << "" << "";
QTest::newRow("uplink above max") << "uplinkCapacity" << "" << "9999999999" << "4095";
QTest::newRow("uplink 0") << "uplinkCapacity" << "" << "0" << "0";
QTest::newRow("downlink above max") << "downlinkCapacity" << "" << "9999999999" << "4095";
QTest::newRow("mtu 100 -> 576") << "mtu" << "" << "100" << "576";
QTest::newRow("mtu 9999 -> 1460") << "mtu" << "" << "9999" << "1460";
QTest::newRow("cwnd 0 -> 1") << "cwndMultiplier" << "" << "0" << "1";
QTest::newRow("window below mtu 1000") << "maxSendingWindow" << "1000" << "800" << "1000";
QTest::newRow("window below default mtu") << "maxSendingWindow" << "" << "800" << "1350";
QTest::newRow("window empty") << "maxSendingWindow" << "" << "" << "";
}
void TestXrayPagesUi::transportMkcpClamps()
{
QFETCH(QString, header);
QFETCH(QString, mtuBefore);
QFETCH(QString, typed);
QFETCH(QString, expected);
openStored(xraytest::baseConfig("mkcp", "none", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
m_model->setMkcpMtu(mtuBefore);
clearAndType(field(header), typed);
QCOMPARE(xhttpValue(m_model, header), expected);
}
void TestXrayPagesUi::transportMtuRaisesSendingWindow_data()
{
QTest::addColumn<QString>("windowBefore");
QTest::addColumn<QString>("mtuTyped");
QTest::addColumn<QString>("windowAfter");
QTest::newRow("600 raised to mtu 1000") << "600" << "1000" << "1000";
QTest::newRow("2000 above mtu kept") << "2000" << "1460" << "2000";
QTest::newRow("cleared mtu uses 1350") << "1000" << "" << "1350";
QTest::newRow("empty window stays empty") << "" << "1000" << "";
}
void TestXrayPagesUi::transportMtuRaisesSendingWindow()
{
QFETCH(QString, windowBefore);
QFETCH(QString, mtuTyped);
QFETCH(QString, windowAfter);
openStored(xraytest::baseConfig("mkcp", "none", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
m_model->setMkcpMaxSendingWindow(windowBefore);
clearAndType(field(QStringLiteral("mtu")), mtuTyped);
QCOMPARE(m_model->mkcpMaxSendingWindow(), windowAfter);
}
void TestXrayPagesUi::transportSaveDialogDescription_data()
{
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("edit");
QTest::addColumn<QString>("expected");
QTest::newRow("uplink method is device-only") << "xhttp" << "uplinkMethod" << kDeviceOnlyText;
QTest::newRow("chunk size is device-only") << "xhttp" << "chunk" << kDeviceOnlyText;
QTest::newRow("min posts interval is device-only") << "xhttp" << "minPosts" << kDeviceOnlyText;
QTest::newRow("buffered posts keep shared configs") << "xhttp" << "bufferedPosts" << kServerKeepsSharedText;
QTest::newRow("stream-up secs keep shared configs") << "xhttp" << "streamUp" << kServerKeepsSharedText;
QTest::newRow("mkcp tti keeps shared configs") << "mkcp" << "tti" << kServerKeepsSharedText;
QTest::newRow("path breaks shared configs") << "xhttp" << "path" << kServerBreaksSharedText;
QTest::newRow("host breaks shared configs") << "xhttp" << "host" << kServerBreaksSharedText;
QTest::newRow("noGRPC breaks shared configs") << "xhttp" << "grpc" << kServerBreaksSharedText;
QTest::newRow("transport breaks shared configs") << "xhttp" << "transport" << kServerBreaksSharedText;
}
void TestXrayPagesUi::transportSaveDialogDescription()
{
QFETCH(QString, transport);
QFETCH(QString, edit);
QFETCH(QString, expected);
openStored(xraytest::baseConfig(transport, "tls", ""));
XRAY_LOAD("PageProtocolXrayTransportSettings");
if (edit == QLatin1String("uplinkMethod"))
m_model->setXhttpUplinkMethod(QStringLiteral("PUT"));
else if (edit == QLatin1String("chunk"))
m_model->setXhttpUplinkChunkSize(QStringLiteral("4096"));
else if (edit == QLatin1String("minPosts"))
m_model->setXhttpScMinPostsIntervalMsMin(QStringLiteral("5"));
else if (edit == QLatin1String("bufferedPosts"))
m_model->setXhttpScMaxBufferedPosts(QStringLiteral("5"));
else if (edit == QLatin1String("streamUp"))
m_model->setXhttpScStreamUpServerSecsMax(QStringLiteral("50"));
else if (edit == QLatin1String("tti"))
m_model->setMkcpTti(QStringLiteral("20"));
else if (edit == QLatin1String("path"))
m_model->setXhttpPath(QStringLiteral("/other"));
else if (edit == QLatin1String("host"))
m_model->setXhttpHost(QStringLiteral("cdn.example.com"));
else if (edit == QLatin1String("grpc"))
m_model->setXhttpDisableGrpc(false);
else if (edit == QLatin1String("transport"))
click(typed("RadioItemType", "text", QStringLiteral("RAW (TCP)")));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(0).toString(), QStringLiteral("Save settings?"));
QCOMPARE(questions.first().at(1).toString(), expected);
answer(questions, false);
}
void TestXrayPagesUi::transportSubpageRows()
{
XRAY_LOAD("PageProtocolXrayTransportSettings");
QSignalSpy pages(m_pages, &PageController::goToPage);
click(typed("ListItemType", "text", QStringLiteral("xPadding")));
QCOMPARE(pages.count(), 1);
QCOMPARE(qvariant_cast<PageLoader::PageEnum>(pages.at(0).at(0)), PageLoader::PageEnum::PageProtocolXrayXPaddingSettings);
QQuickItem *xmuxRow = typed("ListItemType", "text", QStringLiteral("XMux"));
QCOMPARE(xmuxRow->property("subtitle").toString(), QStringLiteral("Custom"));
m_model->setXmuxEnabled(false);
QCOMPARE(xmuxRow->property("subtitle").toString(), QStringLiteral("Core defaults"));
click(xmuxRow);
QCOMPARE(pages.count(), 2);
QCOMPARE(qvariant_cast<PageLoader::PageEnum>(pages.at(1).at(0)), PageLoader::PageEnum::PageProtocolXrayXmuxSettings);
}
void TestXrayPagesUi::transportReadOnly()
{
selectServer(m_readOnlyServerId);
storeAndOpen(xraytest::baseConfig("xhttp", "reality", ""), m_readOnlyServerId);
XRAY_LOAD("PageProtocolXrayTransportSettings");
QVERIFY(!saveButton()->isVisible());
for (const QString &text : { QStringLiteral("RAW (TCP)"), QStringLiteral("XHTTP"), QStringLiteral("mKCP") })
QVERIFY2(!typed("RadioItemType", "text", text)->isEnabled(), qPrintable(text));
click(typed("RadioItemType", "text", QStringLiteral("RAW (TCP)")));
QCOMPARE(m_model->transport(), QStringLiteral("xhttp"));
}
+164
View File
@@ -0,0 +1,164 @@
#include "testXrayPagesUi.h"
using namespace amnezia;
namespace
{
const QString kXmuxRule = QStringLiteral(
"Set either maxConcurrency or maxConnections, not both. Off = core defaults (maxConnections 3, "
"hMaxRequestTimes 600–900, hMaxReusableSecs 1800–3000). If any field is set, the other defaults are "
"not applied.");
const QString kXmuxError = QStringLiteral("XMux: set either maxConcurrency or maxConnections, not both");
const QString kDeviceOnlyText =
QStringLiteral("The server will not be changed now. The new settings apply the next time you connect.");
}
void TestXrayPagesUi::xmuxInitialState()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
QQuickItem *row = typed("SwitchRowType", "descriptionText", kXmuxRule);
QVERIFY(row);
QVERIFY(switcherOf(row)->property("checked").toBool());
QVERIFY(typed("SmallTextType", "text", kXmuxRule)->isVisible());
const QList<QQuickItem *> rows = allOfType("MinMaxRowType");
QCOMPARE(rows.size(), 5);
for (QQuickItem *r : rows) {
for (const QString which : { QStringLiteral("Min"), QStringLiteral("Max") }) {
QQuickItem *in = minMaxInput(r, which);
QVERIFY(in);
QCOMPARE(in->property("text").toString(), QStringLiteral("0"));
QCOMPARE(in->property("placeholderText").toString(), QStringLiteral("0"));
}
}
QQuickItem *keepAlive = typed("TextFieldType", "headerText", QStringLiteral("hKeepAlivePeriod"));
QCOMPARE(input(keepAlive)->property("text").toString(), QString());
QCOMPARE(keepAlive->property("helperText").toString(), QStringLiteral("HTTP keep-alive period. Integer, may be negative."));
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::xmuxSwitchDisablesFields()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
QQuickItem *sw = switcherOf(typed("SwitchRowType", "descriptionText", kXmuxRule));
QVERIFY(sw);
click(sw);
QCOMPARE(m_model->xmuxEnabled(), false);
for (QQuickItem *r : allOfType("MinMaxRowType")) {
QVERIFY(!minMaxInput(r, QStringLiteral("Min"))->isEnabled());
QVERIFY(!minMaxInput(r, QStringLiteral("Max"))->isEnabled());
}
QVERIFY(!field(QStringLiteral("hKeepAlivePeriod"))->isEnabled());
QVERIFY(saveButton()->isEnabled());
click(sw);
QCOMPARE(m_model->xmuxEnabled(), true);
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::xmuxMinRaisesMax()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(minMaxInput(minMaxRow(0), QStringLiteral("Min")), QStringLiteral("16"));
QCOMPARE(m_model->xmuxMaxConcurrencyMin(), QStringLiteral("16"));
QCOMPARE(m_model->xmuxMaxConcurrencyMax(), QStringLiteral("16"));
}
void TestXrayPagesUi::xmuxMaxBelowMin()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
m_model->setXmuxMaxConnectionsMin(QStringLiteral("4"));
m_model->setXmuxMaxConnectionsMax(QStringLiteral("4"));
clearAndType(minMaxInput(minMaxRow(1), QStringLiteral("Max")), QStringLiteral("2"));
QCOMPARE(m_model->xmuxMaxConnectionsMax(), QStringLiteral("4"));
}
void TestXrayPagesUi::xmuxBothLimitsRefusedOnSave()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(minMaxInput(minMaxRow(0), QStringLiteral("Min")), QStringLiteral("16"));
clearAndType(minMaxInput(minMaxRow(1), QStringLiteral("Min")), QStringLiteral("4"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
click(saveButton());
QCOMPARE(errors.count(), 1);
QCOMPARE(errors.first().first().toString(), kXmuxError);
}
void TestXrayPagesUi::xmuxZeroCountsAsUnset()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(minMaxInput(minMaxRow(0), QStringLiteral("Min")), QStringLiteral("16"));
QCOMPARE(m_model->xmuxMaxConnectionsMin(), QStringLiteral("0"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 1);
answer(questions, false);
}
void TestXrayPagesUi::xmuxDisabledIsNotValidated()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
m_model->setXmuxMaxConcurrencyMin(QStringLiteral("1"));
m_model->setXmuxMaxConnectionsMin(QStringLiteral("1"));
QQuickItem *sw = switcherOf(typed("SwitchRowType", "descriptionText", kXmuxRule));
QVERIFY(sw);
click(sw);
QCOMPARE(m_model->xmuxEnabled(), false);
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 1);
answer(questions, false);
}
void TestXrayPagesUi::xmuxTwoErrorsAtOnce()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
m_model->setXmuxMaxConcurrencyMin(QStringLiteral("1"));
m_model->setXmuxMaxConnectionsMin(QStringLiteral("1"));
m_model->setSni(QStringLiteral("*"));
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
click(saveButton());
QCOMPARE(errors.count(), 1);
QCOMPARE(errors.first().first().toString(),
QStringLiteral("SNI: enter a valid IP address or domain name\n") + kXmuxError);
}
void TestXrayPagesUi::xmuxKeepAlive_data()
{
QTest::addColumn<QString>("typed");
QTest::addColumn<QString>("expected");
QTest::newRow("lone minus") << "-" << "";
QTest::newRow("negative") << "-30" << "-30";
QTest::newRow("leading zeros") << "007" << "7";
QTest::newRow("minus zero") << "-0" << "0";
QTest::newRow("above int32") << "99999999999" << "2147483647";
QTest::newRow("below int32") << "-99999999999" << "-2147483648";
QTest::newRow("inner minus blocked") << "12-3" << "123";
QTest::newRow("empty") << "" << "";
}
void TestXrayPagesUi::xmuxKeepAlive()
{
QFETCH(QString, typed);
QFETCH(QString, expected);
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(field(QStringLiteral("hKeepAlivePeriod")), typed);
QCOMPARE(m_model->xmuxHKeepAlivePeriod(), expected);
}
void TestXrayPagesUi::xmuxEditIsDeviceOnly()
{
XRAY_LOAD("PageProtocolXrayXmuxSettings");
clearAndType(minMaxInput(minMaxRow(2), QStringLiteral("Min")), QStringLiteral("5"));
QCOMPARE(m_model->xmuxCMaxReuseTimesMin(), QStringLiteral("5"));
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(1).toString(), kDeviceOnlyText);
answer(questions, false);
}
+341
View File
@@ -0,0 +1,341 @@
#include <QJsonDocument>
#include <QRegularExpression>
#include "core/utils/errorCodes.h"
#include "testXrayPagesUi.h"
#include "ui/utils/pageEnum.h"
using namespace amnezia;
namespace
{
const QString kDeviceOnlyText =
QStringLiteral("The server will not be changed now. The new settings apply the next time you connect.");
const QStringList kAllPages = { "PageProtocolXraySettings", "PageProtocolXrayTransportSettings",
"PageProtocolXraySecuritySettings", "PageProtocolXrayFlowSettings",
"PageProtocolXrayXPaddingSettings", "PageProtocolXrayXPaddingBytesSettings",
"PageProtocolXrayXmuxSettings" };
}
void TestXrayPagesUi::saveInitiallyDisabled_data()
{
QTest::addColumn<QString>("page");
for (const QString &p : kAllPages)
QTest::newRow(qPrintable(p)) << p;
}
void TestXrayPagesUi::saveInitiallyDisabled()
{
QFETCH(QString, page);
loadPage(page);
if (QTest::currentTestFailed())
return;
QQuickItem *save = saveButton();
QVERIFY(save);
QVERIFY(save->isVisible());
QVERIFY(!save->isEnabled());
QSignalSpy errors(m_pages, qOverload<const QString &>(&PageController::showErrorMessage));
XRAY_QUESTIONS(questions);
click(save);
QCOMPARE(errors.count(), 0);
QCOMPARE(questions.count(), 0);
}
void TestXrayPagesUi::saveEditThenRevert()
{
openStored(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QSignalSpy unsaved(m_model, &XrayConfigModel::hasUnsavedChangesChanged);
QQuickItem *fingerprint = dropDown(QStringLiteral("Fingerprint"));
QVERIFY(chooseOption(fingerprint, QStringLiteral("firefox")));
QVERIFY(saveButton()->isEnabled());
QVERIFY(chooseOption(fingerprint, QStringLiteral("hellochrome_120")));
QVERIFY(!saveButton()->isEnabled());
QCOMPARE(unsaved.count(), 2);
}
void TestXrayPagesUi::saveReloadDiscardsEdits()
{
storeAndOpen(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
QQuickItem *sni = visibleField(QStringLiteral("Server Name (SNI)"));
clearAndType(sni, QStringLiteral("vpn.example.org"));
QVERIFY(m_model->hasUnsavedChanges());
m_core->m_installUiController->openServerSettings(m_serverId, static_cast<int>(DockerContainer::Xray),
static_cast<int>(Proto::Xray));
QVERIFY(!m_model->hasUnsavedChanges());
QVERIFY(!saveButton()->isEnabled());
QCOMPARE(m_model->sni(), QStringLiteral("www.example.com"));
QCOMPARE(sni->property("text").toString(), QStringLiteral("www.example.com"));
}
void TestXrayPagesUi::saveCancelDoesNothing()
{
storeAndOpen(xraytest::baseConfig("raw", "reality", ""));
XRAY_LOAD("PageProtocolXraySecuritySettings");
m_model->setFingerprint(QStringLiteral("firefox"));
QSignalSpy pages(m_pages, &PageController::goToPage);
QSignalSpy finished(m_core->m_installUiController, &InstallUiController::updateContainerFinished);
QSignalSpy failed(m_core->m_installUiController, &InstallUiController::installationErrorOccurred);
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
answer(questions, false);
QTest::qWait(300);
QCOMPARE(pages.count(), 0);
QCOMPARE(finished.count(), 0);
QCOMPARE(failed.count(), 0);
QVERIFY(m_model->hasUnsavedChanges());
QVERIFY(saveButton()->isEnabled());
QCOMPARE(stored().fingerprint, QStringLiteral("hellochrome_120"));
}
void TestXrayPagesUi::saveDeviceOnlyContinue_data()
{
QTest::addColumn<QString>("page");
QTest::addColumn<QString>("transport");
QTest::addColumn<QString>("flow");
QTest::addColumn<QString>("edit");
QTest::newRow("security: fingerprint") << "PageProtocolXraySecuritySettings" << "raw" << "" << "fingerprint";
QTest::newRow("flow: vision -> udp443") << "PageProtocolXrayFlowSettings" << "raw" << "xtls-rprx-vision" << "udp443";
QTest::newRow("xmux: cMaxReuseTimes") << "PageProtocolXrayXmuxSettings" << "xhttp" << "" << "xmux";
QTest::newRow("transport: uplink method") << "PageProtocolXrayTransportSettings" << "xhttp" << "" << "method";
}
void TestXrayPagesUi::saveDeviceOnlyContinue()
{
QFETCH(QString, page);
QFETCH(QString, transport);
QFETCH(QString, flow);
QFETCH(QString, edit);
storeAndOpen(xraytest::baseConfig(transport, "reality", flow));
loadPage(page);
if (QTest::currentTestFailed())
return;
if (edit == QLatin1String("fingerprint"))
m_model->setFingerprint(QStringLiteral("firefox"));
else if (edit == QLatin1String("udp443"))
m_model->setFlow(QStringLiteral("xtls-rprx-vision-udp443"));
else if (edit == QLatin1String("xmux"))
m_model->setXmuxCMaxReuseTimesMin(QStringLiteral("5"));
else
m_model->setXhttpUplinkMethod(QStringLiteral("PUT"));
QVERIFY(!m_model->pendingChangeTouchesServer(QString()));
QSignalSpy pages(m_pages, &PageController::goToPage);
QSignalSpy finished(m_core->m_installUiController, &InstallUiController::updateContainerFinished);
QSignalSpy failed(m_core->m_installUiController, &InstallUiController::installationErrorOccurred);
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(1).toString(), kDeviceOnlyText);
answer(questions, true);
QTRY_COMPARE(finished.count() + failed.count(), 1);
QCOMPARE(failed.count(), 0);
QCOMPARE(finished.first().at(0).toString(), QStringLiteral("Settings updated successfully"));
QCOMPARE(finished.first().at(1).toBool(), false);
QCOMPARE(pages.count(), 0);
const XrayServerConfig after = stored();
if (edit == QLatin1String("fingerprint"))
QCOMPARE(after.fingerprint, QStringLiteral("firefox"));
else if (edit == QLatin1String("udp443"))
QCOMPARE(after.flow, QStringLiteral("xtls-rprx-vision-udp443"));
else if (edit == QLatin1String("xmux"))
QCOMPARE(after.xhttp.xmux.cMaxReuseTimesMin, QStringLiteral("5"));
else
QCOMPARE(after.xhttp.uplinkMethod, QStringLiteral("PUT"));
QTRY_VERIFY(!m_model->hasUnsavedChanges());
QVERIFY(!saveButton()->isEnabled());
}
void TestXrayPagesUi::saveServerChangeOnHostlessServer()
{
selectServer(m_hostlessServerId);
storeAndOpen(xraytest::baseConfig("raw", "reality", ""), m_hostlessServerId);
XRAY_LOAD("PageProtocolXraySecuritySettings");
m_model->setSni(QStringLiteral("www.example.org"));
QVERIFY(m_model->pendingChangeTouchesServer(QString()));
QSignalSpy pages(m_pages, &PageController::goToPage);
QSignalSpy finished(m_core->m_installUiController, &InstallUiController::updateContainerFinished);
QSignalSpy failed(m_core->m_installUiController, &InstallUiController::installationErrorOccurred);
XRAY_QUESTIONS(questions);
click(saveButton());
QCOMPARE(questions.count(), 1);
answer(questions, true);
QCOMPARE(pages.count(), 1);
QCOMPARE(qvariant_cast<PageLoader::PageEnum>(pages.first().at(0)), PageLoader::PageEnum::PageSetupWizardInstalling);
QTRY_COMPARE(finished.count() + failed.count(), 1);
QCOMPARE(failed.count(), 1);
QCOMPARE(qvariant_cast<ErrorCode>(failed.first().at(0)), ErrorCode::InternalError);
QCOMPARE(stored(m_hostlessServerId).sni, QStringLiteral("www.example.com"));
QVERIFY(m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::saveCppGuardRefusesInvalid()
{
m_model->setSni(QStringLiteral("*"));
QSignalSpy failed(m_core->m_installUiController, &InstallUiController::installationErrorOccurred);
m_core->m_installUiController->updateServerConfig(m_serverId, static_cast<int>(DockerContainer::Xray),
static_cast<int>(Proto::Xray), false);
QCOMPARE(failed.count(), 1);
QCOMPARE(qvariant_cast<ErrorCode>(failed.first().at(0)), ErrorCode::XrayServerConfigInvalid);
QCOMPARE(stored().sni, QStringLiteral("www.example.com"));
}
void TestXrayPagesUi::saveReadOnlySubpages_data()
{
QTest::addColumn<QString>("page");
for (const QString &p : kAllPages.mid(1))
QTest::newRow(qPrintable(p)) << p;
}
void TestXrayPagesUi::saveReadOnlySubpages()
{
QFETCH(QString, page);
selectServer(m_readOnlyServerId);
storeAndOpen(xraytest::baseConfig("xhttp", "reality", ""), m_readOnlyServerId);
loadPage(page);
if (QTest::currentTestFailed())
return;
QVERIFY(!saveButton()->isVisible());
int controls = 0;
for (const char *type : { "RadioItemType", "TextFieldType", "DropDownType", "SwitchRowType", "MinMaxRowType" }) {
for (QQuickItem *control : allOfType(type)) {
++controls;
QVERIFY2(!control->isEnabled(), qPrintable(QString::fromLatin1(type)));
}
}
QVERIFY(controls > 0);
}
void TestXrayPagesUi::snapshotsEmptyState()
{
XRAY_LOAD("PageProtocolXraySnapshots");
QCOMPARE(m_snapshots->rowCount(), 0);
QQuickItem *empty = typed("BodyTextType", "text",
QStringLiteral("No saved configurations yet.\nCreate one from the current settings."));
QVERIFY(empty && empty->isVisible());
QVERIFY(!typed("SmallTextType", "text", QStringLiteral("Configurations"))->isVisible());
}
void TestXrayPagesUi::snapshotsCreate()
{
XRAY_LOAD("PageProtocolXraySnapshots");
click(typed("ListItemType", "text", QStringLiteral("Create configuration based on current settings")));
QCOMPARE(m_snapshots->rowCount(), 1);
QQuickItem *row = nullptr;
QTRY_VERIFY((row = typed("ListItemType", "text", QStringLiteral("XHTTP Reality"))) != nullptr);
QVERIFY(QRegularExpression(QStringLiteral(R"(^\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}$)"))
.match(row->property("subtitle").toString())
.hasMatch());
QVERIFY(typed("SmallTextType", "text", QStringLiteral("Configurations"))->isVisible());
QVERIFY(!m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::snapshotsApply()
{
storeAndOpen(xraytest::baseConfig("raw", "tls", ""));
m_snapshots->createFromCurrentModel();
openStored(xraytest::baseConfig("xhttp", "reality", ""));
XRAY_LOAD("PageProtocolXraySnapshots");
QQuickItem *row = typed("ListItemType", "text", QStringLiteral("RAW (TCP) TLS"));
QVERIFY(row);
QObject *drawer = popupOf(m_page);
QVERIFY(drawer);
click(row);
QVERIFY(QTest::qWaitFor([drawer] { return drawer->property("opened").toBool(); }, 3000));
QTest::qWait(250);
QSignalSpy closed(m_pages, &PageController::closePage);
click(typed("ListItemType", "text", QStringLiteral("Apply configuration"), popupContent(drawer)));
QCOMPARE(closed.count(), 1);
QCOMPARE(m_model->transport(), QStringLiteral("raw"));
QCOMPARE(m_model->security(), QStringLiteral("tls"));
QVERIFY(m_model->hasUnsavedChanges());
}
void TestXrayPagesUi::snapshotsDelete()
{
m_snapshots->createFromCurrentModel();
XRAY_LOAD("PageProtocolXraySnapshots");
QSignalSpy removed(m_snapshots, &XrayConfigSnapshotsModel::configRemoved);
QObject *drawer = popupOf(m_page);
click(typed("ListItemType", "text", QStringLiteral("XHTTP Reality")));
QVERIFY(QTest::qWaitFor([drawer] { return drawer->property("opened").toBool(); }, 3000));
QTest::qWait(250);
XRAY_QUESTIONS(questions);
click(typed("ListItemType", "text", QStringLiteral("Delete configuration"), popupContent(drawer)));
QCOMPARE(questions.count(), 1);
QCOMPARE(questions.first().at(0).toString(), QStringLiteral("Delete configuration?"));
QCOMPARE(questions.first().at(1).toString(), QStringLiteral("This action cannot be undone."));
QCOMPARE(questions.first().at(2).toString(), QStringLiteral("Delete"));
QCOMPARE(questions.first().at(3).toString(), QStringLiteral("Cancel"));
answer(questions, true);
QCOMPARE(removed.count(), 1);
QCOMPARE(m_snapshots->rowCount(), 0);
}
void TestXrayPagesUi::snapshotsDeleteCancelled()
{
m_snapshots->createFromCurrentModel();
XRAY_LOAD("PageProtocolXraySnapshots");
QObject *drawer = popupOf(m_page);
click(typed("ListItemType", "text", QStringLiteral("XHTTP Reality")));
QVERIFY(QTest::qWaitFor([drawer] { return drawer->property("opened").toBool(); }, 3000));
QTest::qWait(250);
XRAY_QUESTIONS(questions);
click(typed("ListItemType", "text", QStringLiteral("Delete configuration"), popupContent(drawer)));
QCOMPARE(questions.count(), 1);
answer(questions, false);
QCOMPARE(m_snapshots->rowCount(), 1);
}
void TestXrayPagesUi::snapshotsImportExport()
{
m_snapshots->createFromCurrentModel();
QCOMPARE(m_snapshots->rowCount(), 1);
const QString json = m_snapshots->exportToJson(0);
const QJsonObject exported = QJsonDocument::fromJson(json.toUtf8()).object();
for (const char *key : { "id", "displayName", "createdAt", "serverConfig" })
QVERIFY2(exported.contains(QLatin1String(key)), key);
QCOMPARE(exported.value("displayName").toString(), QStringLiteral("XHTTP Reality"));
QVERIFY(m_snapshots->importFromJson(json));
QCOMPARE(m_snapshots->rowCount(), 2);
XRAY_LOAD("PageProtocolXraySnapshots");
QSignalSpy notes(m_pages, &PageController::showNotificationMessage);
QSignalSpy importFailed(m_snapshots, &XrayConfigSnapshotsModel::importFailed);
QVERIFY(!m_snapshots->importFromJson(QStringLiteral("[]")));
QCOMPARE(importFailed.count(), 1);
QCOMPARE(importFailed.first().at(0).toString(), QStringLiteral("Invalid JSON format"));
QCOMPARE(notes.count(), 1);
QCOMPARE(notes.first().at(0).toString(), QStringLiteral("Invalid JSON format"));
QCOMPARE(m_snapshots->rowCount(), 2);
}
void TestXrayPagesUi::snapshotsExportWithoutSnapshots()
{
XRAY_LOAD("PageProtocolXraySnapshots");
QSignalSpy busy(m_pages, &PageController::showBusyIndicator);
QSignalSpy notes(m_pages, &PageController::showNotificationMessage);
click(typed("ListItemType", "text", QStringLiteral("Export settings")));
QTest::qWait(200);
QCOMPARE(busy.count(), 0);
QCOMPARE(notes.count(), 0);
}
+628
View File
@@ -0,0 +1,628 @@
#ifndef TEST_XRAY_PAGES_UI_H
#define TEST_XRAY_PAGES_UI_H
#include <QJSValue>
#include <QJsonObject>
#include <QKeySequence>
#include <QQmlApplicationEngine>
#include <QQmlProperty>
#include <QQuickItem>
#include <QQuickWindow>
#include <QSignalSpy>
#include <QTest>
#include "core/models/containerConfig.h"
#include "core/models/protocols/xrayProtocolConfig.h"
#include "core/models/selfhosted/selfHostedAdminServerConfig.h"
#include "core/utils/serverConfigUtils.h"
#include "ui/controllers/selfhosted/installUiController.h"
#include "ui/controllers/serversUiController.h"
#include "secureQSettings.h"
#include "ui/controllers/qml/pageController.h"
#include "ui/models/protocols/xrayConfigModel.h"
#include "ui/models/protocols/xrayConfigSnapshotsModel.h"
#include "utils/testCoreController.h"
#include "utils/xrayMatrix.h"
#define XRAY_LOAD(page) \
do { \
loadPage(QStringLiteral(page)); \
if (QTest::currentTestFailed()) \
return; \
} while (0)
#define XRAY_QUESTIONS(name) \
QSignalSpy name(dialogs(), SIGNAL(questionRequested(QString, QString, QString, QString, QVariant, QVariant)))
class TestXrayPagesUi : public QObject
{
Q_OBJECT
private:
SecureQSettings *m_settings = nullptr;
QQmlApplicationEngine *m_engine = nullptr;
TestCoreController *m_core = nullptr;
XrayConfigModel *m_model = nullptr;
XrayConfigSnapshotsModel *m_snapshots = nullptr;
PageController *m_pages = nullptr;
QString m_serverId;
QString m_readOnlyServerId;
QString m_hostlessServerId;
QQuickWindow *m_window = nullptr;
QQuickItem *m_page = nullptr;
static amnezia::ContainerConfig xrayContainer(const amnezia::XrayServerConfig &srv)
{
amnezia::ContainerConfig container;
container.container = amnezia::DockerContainer::Xray;
amnezia::XrayProtocolConfig xray;
xray.serverConfig = srv;
amnezia::XrayClientConfig client;
client.nativeConfig = xraytest::compact(xraytest::clientJson(srv));
client.localPort = QStringLiteral("10808");
client.id = xraytest::clientId();
xray.setClientConfig(client);
container.protocolConfig = xray;
return container;
}
static QJsonObject serverJson(const QString &host, const QString &password, const amnezia::XrayServerConfig &srv)
{
amnezia::SelfHostedAdminServerConfig server;
server.hostName = host;
server.userName = QStringLiteral("root");
server.password = password;
server.port = 22;
server.description = QStringLiteral("xray ui test ") + (host.isEmpty() ? QStringLiteral("hostless") : host);
server.displayName = server.description;
server.defaultContainer = amnezia::DockerContainer::Xray;
server.containers.insert(amnezia::DockerContainer::Xray, xrayContainer(srv));
return server.toJson();
}
QString addServer(const QString &host, const QString &password, serverConfigUtils::ConfigType kind)
{
const int before = m_core->m_serversRepository->serversCount();
const QString id = m_core->m_serversRepository->addServer(
QString(), serverJson(host, password, xraytest::baseConfig("xhttp", "reality", "")), kind);
return m_core->m_serversRepository->serversCount() == before + 1 ? id : QString();
}
void storeAndOpen(const amnezia::XrayServerConfig &srv, const QString &serverId = QString())
{
const QString id = serverId.isEmpty() ? m_serverId : serverId;
const auto kind = m_core->m_serversRepository->serverKind(id);
const QString host = id == m_serverId ? QStringLiteral("203.0.113.10")
: id == m_readOnlyServerId ? QStringLiteral("203.0.113.11")
: QString();
const QString password = id == m_readOnlyServerId ? QString() : QStringLiteral("not-used");
m_core->m_serversRepository->editServer(id, serverJson(host, password, srv), kind);
m_core->m_installUiController->openServerSettings(id, static_cast<int>(amnezia::DockerContainer::Xray),
static_cast<int>(amnezia::Proto::Xray));
}
void openStored(const amnezia::XrayServerConfig &srv)
{
amnezia::XrayProtocolConfig cfg = *xrayContainer(srv).getXrayProtocolConfig();
m_model->updateModel(amnezia::DockerContainer::Xray, cfg);
}
amnezia::XrayServerConfig stored(const QString &serverId = QString()) const
{
const amnezia::ContainerConfig container = m_core->m_serversController->getContainerConfig(
serverId.isEmpty() ? m_serverId : serverId, amnezia::DockerContainer::Xray);
const auto *xray = container.getXrayProtocolConfig();
return xray ? xray->serverConfig : amnezia::XrayServerConfig {};
}
void selectServer(const QString &serverId)
{
m_core->m_serversUiController->updateModel();
m_core->m_serversUiController->setProcessedServerId(serverId);
m_core->m_serversUiController->setProcessedContainerIndex(static_cast<int>(amnezia::DockerContainer::Xray));
}
void loadPage(const QString &page)
{
closePage();
const QByteArray qml = QStringLiteral(
"import QtQuick\n"
"import QtQuick.Controls\n"
"import \"../Config\"\n"
"ApplicationWindow {\n"
" width: 420; height: 800; visible: true\n"
" property var dialogs: Dialogs\n"
" Loader { objectName: \"pageLoader\"; anchors.fill: parent; source: \"qrc:/ui/qml/Pages2/%1.qml\" }\n"
"}\n").arg(page).toUtf8();
m_engine->loadData(qml, QUrl(QStringLiteral("qrc:/ui/qml/Pages2/xrayUiTestHost.qml")));
QVERIFY2(!m_engine->rootObjects().isEmpty(), "test host window did not load");
m_window = qobject_cast<QQuickWindow *>(m_engine->rootObjects().last());
QVERIFY(m_window);
QVERIFY(QTest::qWaitForWindowExposed(m_window));
m_window->requestActivate();
QVERIFY(QTest::qWaitForWindowActive(m_window));
auto *loader = m_window->findChild<QObject *>(QStringLiteral("pageLoader"));
QVERIFY(loader);
QTRY_VERIFY2(loader->property("status").toInt() == 1, qPrintable(page + QStringLiteral(" failed to load")));
m_page = qvariant_cast<QQuickItem *>(loader->property("item"));
QVERIFY(m_page);
}
void closePage()
{
m_page = nullptr;
if (m_window) {
m_window->close();
m_window->deleteLater();
m_window = nullptr;
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
}
QObject *dialogs() const
{
return m_window ? qvariant_cast<QObject *>(m_window->property("dialogs")) : nullptr;
}
static void answer(const QSignalSpy &questions, bool yes)
{
QJSValue fn = questions.last().at(yes ? 4 : 5).value<QJSValue>();
fn.call();
QTest::qWait(50);
}
static void collect(QQuickItem *item, QList<QQuickItem *> &out)
{
out.append(item);
for (QQuickItem *child : item->childItems())
collect(child, out);
}
QList<QQuickItem *> items(QQuickItem *root = nullptr) const
{
QList<QQuickItem *> out;
if (QQuickItem *start = root ? root : m_page)
collect(start, out);
return out;
}
static bool isType(const QObject *object, const char *qmlType)
{
return QString::fromLatin1(object->metaObject()->className()).startsWith(QLatin1String(qmlType));
}
QQuickItem *item(const char *property, const QString &value, QQuickItem *root = nullptr)
{
for (QQuickItem *candidate : items(root)) {
const QVariant v = candidate->property(property);
if (v.isValid() && v.toString() == value)
return candidate;
}
qWarning().noquote() << "no item with" << property << "=" << value;
return nullptr;
}
QQuickItem *visibleItem(const char *property, const QString &value, QQuickItem *root = nullptr)
{
for (QQuickItem *candidate : items(root)) {
const QVariant v = candidate->property(property);
if (v.isValid() && v.toString() == value && candidate->isVisible())
return candidate;
}
qWarning().noquote() << "no visible item with" << property << "=" << value;
return nullptr;
}
QQuickItem *typed(const char *qmlType, const char *property, const QString &value, QQuickItem *root = nullptr)
{
for (QQuickItem *candidate : items(root)) {
if (!isType(candidate, qmlType))
continue;
const QVariant v = candidate->property(property);
if (v.isValid() && v.toString() == value)
return candidate;
}
qWarning().noquote() << "no" << qmlType << "with" << property << "=" << value;
return nullptr;
}
QList<QQuickItem *> allOfType(const char *qmlType, QQuickItem *root = nullptr)
{
QList<QQuickItem *> out;
for (QQuickItem *candidate : items(root)) {
if (isType(candidate, qmlType))
out.append(candidate);
}
return out;
}
static QQuickItem *input(QQuickItem *field)
{
return field ? qvariant_cast<QQuickItem *>(field->property("textField")) : nullptr;
}
static QQuickItem *ownerField(QQuickItem *textInput)
{
QQuickItem *p = textInput ? textInput->parentItem() : nullptr;
while (p && !isType(p, "TextFieldType"))
p = p->parentItem();
return p;
}
QQuickItem *field(const QString &headerText)
{
return input(typed("TextFieldType", "headerText", headerText));
}
QQuickItem *visibleField(const QString &headerText)
{
for (QQuickItem *candidate : allOfType("TextFieldType")) {
if (candidate->property("headerText").toString() == headerText && candidate->isVisible())
return input(candidate);
}
qWarning().noquote() << "no visible TextFieldType" << headerText;
return nullptr;
}
QQuickItem *dropDown(const QString &descriptionText)
{
for (QQuickItem *candidate : allOfType("DropDownType")) {
if (candidate->property("descriptionText").toString() == descriptionText && candidate->isVisible())
return candidate;
}
return typed("DropDownType", "descriptionText", descriptionText);
}
QQuickItem *minMaxRow(int index) { return allOfType("MinMaxRowType").value(index); }
QQuickItem *minMaxInput(QQuickItem *row, const QString &which)
{
return row ? input(typed("TextFieldType", "headerText", which, row)) : nullptr;
}
QQuickItem *iconButton(const QString &iconSuffix)
{
for (QQuickItem *candidate : items()) {
QQmlProperty source(candidate, QStringLiteral("icon.source"));
if (source.isValid() && source.read().toUrl().toString().endsWith(iconSuffix))
return candidate;
}
qWarning().noquote() << "no icon button" << iconSuffix;
return nullptr;
}
QQuickItem *saveButton() { return typed("ButtonType", "text", QStringLiteral("Save")); }
QQuickItem *switcherOf(QQuickItem *switchRow)
{
return switchRow ? qvariant_cast<QQuickItem *>(switchRow->property("switcher")) : nullptr;
}
void scrollIntoView(QQuickItem *target)
{
for (QQuickItem *p = target->parentItem(); p; p = p->parentItem()) {
if (!p->property("contentY").isValid() || !p->property("contentHeight").isValid())
continue;
auto *content = qvariant_cast<QQuickItem *>(p->property("contentItem"));
if (!content)
continue;
const qreal inView = target->mapToItem(p, QPointF(0, 0)).y();
if (inView >= 0 && inView + target->height() <= p->height())
return;
const qreal originY = p->property("originY").toReal();
const qreal y = target->mapToItem(content, QPointF(0, 0)).y();
const qreal maxY = qMax<qreal>(originY, originY + p->property("contentHeight").toReal() - p->height());
p->setProperty("contentY", qBound<qreal>(originY, y - p->height() / 3, maxY));
QTest::qWait(50);
return;
}
}
static void polishAncestors(QQuickItem *item)
{
QList<QQuickItem *> chain;
for (QQuickItem *p = item; p; p = p->parentItem())
chain.prepend(p);
for (QQuickItem *p : chain)
p->ensurePolished();
}
void click(QQuickItem *target)
{
polishAncestors(target);
scrollIntoView(target);
const QPointF center = target->mapToScene(QPointF(target->width() / 2, target->height() / 2));
QTest::mouseClick(m_window, Qt::LeftButton, {}, center.toPoint());
QTest::qWait(50);
}
void type(const QString &text)
{
for (const QChar ch : text)
QTest::keyClick(m_window, ch.toLatin1());
}
void key(Qt::Key k)
{
QTest::keyClick(m_window, k);
QTest::qWait(30);
}
void clearAndType(QQuickItem *textInput, const QString &text, bool commit = true)
{
click(textInput);
QTest::keySequence(m_window, QKeySequence::SelectAll);
QTest::keyClick(m_window, Qt::Key_Backspace);
type(text);
if (commit)
key(Qt::Key_Return);
QTest::qWait(30);
}
void blur(QQuickItem *otherInput) { click(otherInput); }
static QObject *popupOf(QObject *owner)
{
if (!owner)
return nullptr;
for (QObject *child : owner->findChildren<QObject *>()) {
if (child->inherits("QQuickPopup"))
return child;
}
return nullptr;
}
static QQuickItem *popupContent(QObject *popup)
{
return popup ? qvariant_cast<QQuickItem *>(popup->property("contentItem")) : nullptr;
}
QObject *openDropDown(QQuickItem *dd)
{
QObject *popup = popupOf(dd);
if (!popup)
return nullptr;
for (int attempt = 0; attempt < 2; ++attempt) {
QTest::qWait(100);
click(dd);
if (QTest::qWaitFor([popup] { return popup->property("opened").toBool(); }, 1500)) {
QTest::qWait(250);
return popup;
}
}
return nullptr;
}
bool closeWithEscape(QObject *popup)
{
key(Qt::Key_Escape);
return QTest::qWaitFor([popup] { return !popup->property("visible").toBool(); }, 3000);
}
QList<QQuickItem *> options(QObject *popup)
{
QList<QQuickItem *> out;
for (QQuickItem *candidate : allOfType("RadioItemType", popupContent(popup))) {
if (candidate->isVisible())
out.append(candidate);
}
return out;
}
bool chooseOption(QQuickItem *dd, const QString &option)
{
QObject *popup = openDropDown(dd);
if (!popup) {
qWarning().noquote() << "drop-down did not open";
return false;
}
for (QQuickItem *candidate : options(popup)) {
if (candidate->property("text").toString() == option) {
click(candidate);
return QTest::qWaitFor([popup] { return !popup->property("visible").toBool(); }, 3000);
}
}
qWarning().noquote() << "no option" << option;
closeWithEscape(popup);
return false;
}
QStringList optionNames(QQuickItem *dd, bool checkedOnly)
{
QStringList names;
QObject *popup = openDropDown(dd);
if (!popup)
return { QStringLiteral("<did not open>") };
for (QQuickItem *candidate : options(popup)) {
if (!checkedOnly || candidate->property("checked").toBool())
names << candidate->property("text").toString();
}
closeWithEscape(popup);
return names;
}
private slots:
void initTestCase();
void init();
void cleanup();
void cleanupTestCase();
void transportRadioClickChangesModel();
void packetUpFieldsFollowMode_data();
void packetUpFieldsFollowMode();
void pathGetsLeadingSlash();
void visionNeedsTlsOrReality_data();
void visionNeedsTlsOrReality();
void fingerprintHiddenOnMkcp_data();
void fingerprintHiddenOnMkcp();
void sniRejectsWildcardInput();
void xPaddingFieldsFollowObfsMode_data();
void xPaddingFieldsFollowObfsMode();
void subpageSaveRefusesInvalidSni_data();
void subpageSaveRefusesInvalidSni();
void mainPortPlaceholderAndDefault();
void mainPortInput_data();
void mainPortInput();
void mainPortEditTogglesSave();
void mainEmptyPortDisablesSave();
void mainEmptyPortErrorOnFocusOut();
void mainPortFollowsModelOnlyWhenUnfocused();
void mainSaveRefusesInvalidPort();
void mainSaveJoinsErrors();
void mainPortChangeDialog();
void mainTransportSubtitle_data();
void mainTransportSubtitle();
void mainSecuritySubtitle_data();
void mainSecuritySubtitle();
void mainFlowSubtitle_data();
void mainFlowSubtitle();
void mainRowsNavigate_data();
void mainRowsNavigate();
void mainSnapshotsIconNavigates();
void mainBackButtonClosesPage();
void mainResetDialogTexts();
void mainResetAccepted();
void mainResetCancelled();
void mainKeyMigrationDialog();
void mainReadOnlyServer();
void mainWritableServerBaseline();
void transportXhttpRadioSubtitle();
void transportRadioCheckedFollowsModel_data();
void transportRadioCheckedFollowsModel();
void transportRadioReturnKey();
void transportSectionVisibility_data();
void transportSectionVisibility();
void transportRawToXhttpFillsDefaults();
void transportSwitchKeepsXhttpValues();
void transportPacketUpFieldsMoreRows_data();
void transportPacketUpFieldsMoreRows();
void transportPacketUpFieldsFollowModeLive();
void transportAlwaysVisibleXhttpControls_data();
void transportAlwaysVisibleXhttpControls();
void transportDropDownOptions_data();
void transportDropDownOptions();
void transportDropDownRoundTrip_data();
void transportDropDownRoundTrip();
void transportDropDownEscape();
void transportChoosingCurrentModeIsNoChange();
void transportPacketUpRealityAllowed();
void transportSwitches_data();
void transportSwitches();
void transportSwitchLabelToggles();
void transportHostFilter();
void transportHostValidity_data();
void transportHostValidity();
void transportEmptyHost();
void transportSaveRefusesInvalidHost();
void transportPathFilter();
void transportPathEdgeCases_data();
void transportPathEdgeCases();
void transportKeyFieldsFilter_data();
void transportKeyFieldsFilter();
void transportNumberFields_data();
void transportNumberFields();
void transportMinMaxRows_data();
void transportMinMaxRows();
void transportMinMaxOverflow();
void transportMkcpPlaceholders_data();
void transportMkcpPlaceholders();
void transportMkcpClamps_data();
void transportMkcpClamps();
void transportMtuRaisesSendingWindow_data();
void transportMtuRaisesSendingWindow();
void transportSaveDialogDescription_data();
void transportSaveDialogDescription();
void transportSubpageRows();
void transportReadOnly();
void securityMatrix_data();
void securityMatrix();
void securityRadioRoundTrip();
void securityRealityNotClickableOnMkcp();
void securityMkcpStoredReality();
void securityDropDownOptions_data();
void securityDropDownOptions();
void securityDropDownRoundTrip_data();
void securityDropDownRoundTrip();
void securityFingerprintSharedBetweenBlocks();
void securityValidSni();
void securitySniSiteCoupling();
void securityInvalidSni_data();
void securityInvalidSni();
void securityIpv4Sni();
void securitySniFilter();
void securityEmptySni();
void securitySniErrorOnFocusOut();
void securityNoneIgnoresSni();
void securitySaveDialogDescription_data();
void securitySaveDialogDescription();
void flowRadioRoundTrip();
void flowUdp443Subtitle();
void flowVisionNotAllowed_data();
void flowVisionNotAllowed();
void flowEmptyWhenVisionNotAllowed();
void flowDeviceOrServerChange_data();
void flowDeviceOrServerChange();
void flowEmptyTransportCountsAsRaw();
void flowUnknownStoredFlow();
void flowKeyboard();
void paddingInitialState();
void paddingSwitchTogglesFields();
void paddingSwitchLabelToggles();
void paddingBytesSubtitle_data();
void paddingBytesSubtitle();
void paddingBytesRowNavigates_data();
void paddingBytesRowNavigates();
void paddingKeyHeaderFilter_data();
void paddingKeyHeaderFilter();
void paddingDropDownRoundTrip_data();
void paddingDropDownRoundTrip();
void paddingDisabledDropDownDoesNotOpen();
void paddingBytesInitialState();
void paddingBytesRange_data();
void paddingBytesRange();
void paddingBytesOverflowAndFilter();
void xmuxInitialState();
void xmuxSwitchDisablesFields();
void xmuxMinRaisesMax();
void xmuxMaxBelowMin();
void xmuxBothLimitsRefusedOnSave();
void xmuxZeroCountsAsUnset();
void xmuxDisabledIsNotValidated();
void xmuxTwoErrorsAtOnce();
void xmuxKeepAlive_data();
void xmuxKeepAlive();
void xmuxEditIsDeviceOnly();
void saveInitiallyDisabled_data();
void saveInitiallyDisabled();
void saveEditThenRevert();
void saveReloadDiscardsEdits();
void saveCancelDoesNothing();
void saveDeviceOnlyContinue_data();
void saveDeviceOnlyContinue();
void saveServerChangeOnHostlessServer();
void saveCppGuardRefusesInvalid();
void saveReadOnlySubpages_data();
void saveReadOnlySubpages();
void snapshotsEmptyState();
void snapshotsCreate();
void snapshotsApply();
void snapshotsDelete();
void snapshotsDeleteCancelled();
void snapshotsImportExport();
void snapshotsExportWithoutSnapshots();
void issueTransportRoundTripLeavesSaveEnabled();
void issueSubpageSavesEmptyPort();
void issueHiddenRealitySniBlocksMkcpSave();
void issueClearingXmuxZeroEnablesSave();
void issueSnapshotWithoutPortApplyIsSilent();
void issueSaveWithoutReturnSkipsClamp();
void issueSaveWithoutReturnKeepsRawKeepAlive();
};
#endif