diff --git a/tests/auto/qmlnetwork/CMakeLists.txt b/tests/auto/qmlnetwork/CMakeLists.txt index 74cdf06a51..eba532b941 100644 --- a/tests/auto/qmlnetwork/CMakeLists.txt +++ b/tests/auto/qmlnetwork/CMakeLists.txt @@ -4,5 +4,6 @@ add_subdirectory(qqmlnetworkinformation) if(QT_FEATURE_qml_ssl) add_subdirectory(qqmlsslconfiguration) + add_subdirectory(qqmlsslconfiguration_cpp) add_subdirectory(qqmlsslkey) endif() diff --git a/tests/auto/qmlnetwork/qqmlsslconfiguration_cpp/CMakeLists.txt b/tests/auto/qmlnetwork/qqmlsslconfiguration_cpp/CMakeLists.txt new file mode 100644 index 0000000000..3df15647b6 --- /dev/null +++ b/tests/auto/qmlnetwork/qqmlsslconfiguration_cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2025 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qqmlsslconfiguration_cpp LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qqmlsslconfiguration_cpp + SOURCES + tst_qqmlsslconfiguration_cpp.cpp + LIBRARIES + Qt::QmlNetworkPrivate +) diff --git a/tests/auto/qmlnetwork/qqmlsslconfiguration_cpp/tst_qqmlsslconfiguration_cpp.cpp b/tests/auto/qmlnetwork/qqmlsslconfiguration_cpp/tst_qqmlsslconfiguration_cpp.cpp new file mode 100644 index 0000000000..d125bb12a9 --- /dev/null +++ b/tests/auto/qmlnetwork/qqmlsslconfiguration_cpp/tst_qqmlsslconfiguration_cpp.cpp @@ -0,0 +1,88 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include +#include +#include + +class tst_QQmlSslConfiguration : public QObject +{ + Q_OBJECT + + enum class ConfType : quint8 + { + DefaultSsl, + DefaultDtls, + }; +private Q_SLOTS: + void sslOptionsInSync_data(); + void sslOptionsInSync(); +}; + +static QList getSslOptionsFromConfig(const QSslConfiguration &c) +{ + // Keep in sync with QSsl::SslOptions! + static constexpr + std::array allOptions { QSsl::SslOptionDisableEmptyFragments, + QSsl::SslOptionDisableSessionTickets, + QSsl::SslOptionDisableCompression, + QSsl::SslOptionDisableServerNameIndication, + QSsl::SslOptionDisableLegacyRenegotiation, + QSsl::SslOptionDisableSessionSharing, + QSsl::SslOptionDisableSessionPersistence, + QSsl::SslOptionDisableServerCipherPreference }; + + QList result; + for (auto opt : allOptions) { + if (c.testSslOption(opt)) + result.append(opt); + } + + // return a sorted list + std::sort(result.begin(), result.end()); + return result; +} + +void tst_QQmlSslConfiguration::sslOptionsInSync_data() +{ + QTest::addColumn("type"); + + QTest::newRow("DefaultSslConfiguration") << ConfType::DefaultSsl; + QTest::newRow("DefaultDtlsConfiguration") << ConfType::DefaultDtls; +} + +void tst_QQmlSslConfiguration::sslOptionsInSync() +{ + QFETCH(ConfType, type); + std::unique_ptr conf; + + if (type == ConfType::DefaultSsl) + conf.reset(new QQmlSslDefaultConfiguration); + else + conf.reset(new QQmlSslDefaultDtlsConfiguration); + + // Default config has some options, and originally they're in sync + auto opts = conf->sslOptions(); + std::sort(opts.begin(), opts.end()); + QCOMPARE_EQ(opts, getSslOptionsFromConfig(conf->configuration())); + + // set new options + QList newOptions { QSsl::SslOptionDisableCompression, + QSsl::SslOptionDisableServerCipherPreference }; + conf->setSslOptions(newOptions); + + std::sort(newOptions.begin(), newOptions.end()); + + opts = conf->sslOptions(); + std::sort(opts.begin(), opts.end()); + // reading back the correct value + QCOMPARE_EQ(opts, newOptions); + + // reading the values from the underlying configuration + QEXPECT_FAIL("", "QTBUG-137900", Continue); + QCOMPARE_EQ(getSslOptionsFromConfig(conf->configuration()), newOptions); +} + +QTEST_MAIN(tst_QQmlSslConfiguration) + +#include "tst_qqmlsslconfiguration_cpp.moc"