Add tests for QQmlSslConfiguration::sslOptions
The tests show that the sslOptions property is out of sync with the
underlying QSslConfiguration.
Amends b44f466621
.
Task-number: QTBUG-137900
Pick-to: 6.10 6.9 6.8
Change-Id: I2a34b373ea868c7e76c7470f872d3ba0233394ea
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
2ae756eeed
commit
b8fd380724
|
@ -4,5 +4,6 @@
|
||||||
add_subdirectory(qqmlnetworkinformation)
|
add_subdirectory(qqmlnetworkinformation)
|
||||||
if(QT_FEATURE_qml_ssl)
|
if(QT_FEATURE_qml_ssl)
|
||||||
add_subdirectory(qqmlsslconfiguration)
|
add_subdirectory(qqmlsslconfiguration)
|
||||||
|
add_subdirectory(qqmlsslconfiguration_cpp)
|
||||||
add_subdirectory(qqmlsslkey)
|
add_subdirectory(qqmlsslkey)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -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
|
||||||
|
)
|
|
@ -0,0 +1,88 @@
|
||||||
|
// Copyright (C) 2025 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
#include <QSsl>
|
||||||
|
#include <private/qqmlsslconfiguration_p.h>
|
||||||
|
|
||||||
|
class tst_QQmlSslConfiguration : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
enum class ConfType : quint8
|
||||||
|
{
|
||||||
|
DefaultSsl,
|
||||||
|
DefaultDtls,
|
||||||
|
};
|
||||||
|
private Q_SLOTS:
|
||||||
|
void sslOptionsInSync_data();
|
||||||
|
void sslOptionsInSync();
|
||||||
|
};
|
||||||
|
|
||||||
|
static QList<QSsl::SslOption> getSslOptionsFromConfig(const QSslConfiguration &c)
|
||||||
|
{
|
||||||
|
// Keep in sync with QSsl::SslOptions!
|
||||||
|
static constexpr
|
||||||
|
std::array<QSsl::SslOption, 8> allOptions { QSsl::SslOptionDisableEmptyFragments,
|
||||||
|
QSsl::SslOptionDisableSessionTickets,
|
||||||
|
QSsl::SslOptionDisableCompression,
|
||||||
|
QSsl::SslOptionDisableServerNameIndication,
|
||||||
|
QSsl::SslOptionDisableLegacyRenegotiation,
|
||||||
|
QSsl::SslOptionDisableSessionSharing,
|
||||||
|
QSsl::SslOptionDisableSessionPersistence,
|
||||||
|
QSsl::SslOptionDisableServerCipherPreference };
|
||||||
|
|
||||||
|
QList<QSsl::SslOption> 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<ConfType>("type");
|
||||||
|
|
||||||
|
QTest::newRow("DefaultSslConfiguration") << ConfType::DefaultSsl;
|
||||||
|
QTest::newRow("DefaultDtlsConfiguration") << ConfType::DefaultDtls;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QQmlSslConfiguration::sslOptionsInSync()
|
||||||
|
{
|
||||||
|
QFETCH(ConfType, type);
|
||||||
|
std::unique_ptr<QQmlSslConfiguration> 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<QSsl::SslOption> 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"
|
Loading…
Reference in New Issue