Skip to content

Commit

Permalink
tst_Http2: Ensure each test uses temporary keychain if needed
Browse files Browse the repository at this point in the history
The duplicateRequestsWithAborts test was missing this, causing failures
on macOS 14. Instead of adding it to each test function, we now set up
the temporary key chain in init(), and restore things in cleanup().

Task-number: QTBUG-119616
Pick-to: 6.8
Change-Id: Ia9d80ae632774b8628417ad30d354a22b6a4916e
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
  • Loading branch information
torarnv committed Sep 27, 2024
1 parent e498a07 commit 882e5d7
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions tests/auto/network/access/http2/tst_http2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class tst_Http2 : public QObject
~tst_Http2();
public slots:
void init();
void cleanup();
private slots:
// Tests:
void defaultQnamHttp2Configuration();
Expand Down Expand Up @@ -126,7 +127,8 @@ protected slots:
void replyFinishedWithError();

private:
[[nodiscard]] auto useTemporaryKeychain()
std::function<void()> m_temporaryKeyChainRollback;
[[nodiscard]] std::function<void()> useTemporaryKeychain()
{
#if QT_CONFIG(securetransport)
// Normally on macOS we use plain text only for SecureTransport
Expand All @@ -136,16 +138,16 @@ protected slots:
// Our CI has this, but somebody testing locally - will have a problem.
auto value = qEnvironmentVariable("QT_SSL_USE_TEMPORARY_KEYCHAIN");
qputenv("QT_SSL_USE_TEMPORARY_KEYCHAIN", "1");
auto envRollback = qScopeGuard([value](){
auto envRollback = [value](){
if (value.isEmpty())
qunsetenv("QT_SSL_USE_TEMPORARY_KEYCHAIN");
else
qputenv("QT_SSL_USE_TEMPORARY_KEYCHAIN", value.toUtf8());
});
};
return envRollback;
#else
// avoid maybe-unused warnings from callers
return qScopeGuard([]{});
return {};
#endif // QT_CONFIG(securetransport)
}

Expand Down Expand Up @@ -241,6 +243,15 @@ tst_Http2::~tst_Http2()
void tst_Http2::init()
{
manager.reset(new QNetworkAccessManager);

m_temporaryKeyChainRollback = useTemporaryKeychain();
}

void tst_Http2::cleanup()
{
if (m_temporaryKeyChainRollback)
m_temporaryKeyChainRollback();
m_temporaryKeyChainRollback = {};
}

void tst_Http2::defaultQnamHttp2Configuration()
Expand Down Expand Up @@ -273,8 +284,6 @@ void tst_Http2::singleRequest()
{
clearHTTP2State();

auto rollback = useTemporaryKeychain();

serverPort = 0;
nRequests = 1;

Expand Down Expand Up @@ -718,8 +727,6 @@ void tst_Http2::connectToHost()

#if QT_CONFIG(ssl)
Q_ASSERT(!clearTextHTTP2 || connectionType != H2Type::h2Alpn);

auto rollback = useTemporaryKeychain();
#else
Q_ASSERT(connectionType == H2Type::h2c || connectionType == H2Type::h2cDirect);
Q_ASSERT(targetServer->isClearText());
Expand Down Expand Up @@ -806,8 +813,6 @@ void tst_Http2::maxFrameSize()
// 'SETTINGS'. If done properly, our server will not chunk
// the payload into several DATA frames.

auto rollback = useTemporaryKeychain();

auto connectionType = H2Type::h2Alpn;
auto attribute = QNetworkRequest::Http2AllowedAttribute;
if (clearTextHTTP2) {
Expand Down Expand Up @@ -961,8 +966,6 @@ void tst_Http2::moreActivitySignals()
{
clearHTTP2State();

auto rollback = useTemporaryKeychain();

serverPort = 0;
QFETCH(H2Type, connectionType);
ServerPtr srv(newServer(defaultServerSettings, connectionType));
Expand Down Expand Up @@ -1064,8 +1067,6 @@ void tst_Http2::contentEncoding()
{
clearHTTP2State();

auto rollback = useTemporaryKeychain();

QFETCH(H2Type, connectionType);

ServerPtr targetServer(newServer(defaultServerSettings, connectionType));
Expand Down Expand Up @@ -1529,8 +1530,6 @@ void tst_Http2::abortOnEncrypted()
QSKIP("TLS support is needed for this test");
#else

auto rollback = useTemporaryKeychain();

clearHTTP2State();
serverPort = 0;

Expand Down

0 comments on commit 882e5d7

Please sign in to comment.