From 57fcc378bf83b217b0b7c828fd2b5840b616efe4 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Mon, 3 Jun 2024 20:55:38 +0200 Subject: [PATCH] Expand the test --- tests/networking/src/QtNetworkTests.cpp | 78 ++++++++++++++++++++++--- tests/networking/src/QtNetworkTests.h | 9 ++- 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/tests/networking/src/QtNetworkTests.cpp b/tests/networking/src/QtNetworkTests.cpp index a4e36e7c66..bb70652e72 100644 --- a/tests/networking/src/QtNetworkTests.cpp +++ b/tests/networking/src/QtNetworkTests.cpp @@ -2,9 +2,8 @@ // PacketTests.cpp // tests/networking/src // -// Created by Stephen Birarda on 07/14/15. -// Copyright 2015 High Fidelity, Inc. -// Copyright 2021 Vircadia contributors. +// Created by Dale Glass on 02/06/2024 +// Copyright 2024 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -17,6 +16,25 @@ #include #include #include +#include +#include +#include +#include + +/** + * @brief Test basic Qt networking functionality + * + * This test was created to test a problem found with the Conan PR. + * Possibly some sort of library trouble. + * + * Normally there's no reason why this should go wrong, so it's mostly + * a test of that Qt is deployed and working properly. + * + */ +const QUrl HTTP_URL("http://ping.archlinux.org/"); +const QUrl HTTPS_URL("https://ping.archlinux.org/"); +const QString TCP_HOST("ping.archlinux.org"); +const QString SSL_HOST("ping.archlinux.org"); @@ -27,11 +45,50 @@ void QtNetworkTests::initTestCase() { qRegisterMetaType(); } + +void QtNetworkTests::tcpSocket() { + QTcpSocket sock; + QSignalSpy spy(&sock, &QTcpSocket::connected); + + qDebug() << "Connecting to" << TCP_HOST << "on port 80"; + sock.connectToHost(TCP_HOST, 80); + spy.wait(); + QVERIFY(sock.waitForConnected()); + QVERIFY(sock.localPort() > 0); + + qDebug() << "Local address is" << sock.localAddress() << ":" << sock.localPort(); +} + +void QtNetworkTests::sslSocket() { + QSslSocket sock; + QSignalSpy spy(&sock, &QSslSocket::connected); + + QVERIFY(QSslSocket::supportsSsl()); + qDebug() << "SSL library version: " << QSslSocket::sslLibraryVersionString(); + + qDebug() << "Connecting to" << SSL_HOST << "on port 443"; + sock.connectToHostEncrypted(SSL_HOST, 443); + spy.wait(); + QVERIFY(sock.waitForEncrypted()); + QVERIFY(sock.localPort() > 0); + + QVERIFY(!sock.sslConfiguration().isNull()); + QVERIFY(sock.sslHandshakeErrors().length() == 0); + QVERIFY(sock.sessionProtocol() != QSsl::UnknownProtocol); + + qDebug() << "Local address is" << sock.localAddress() << ":" << sock.localPort(); + qDebug() << "SSL protocol : " << sock.sessionProtocol(); + qDebug() << "SSL cipher : " << sock.sessionCipher().protocolString(); + qDebug() << "SSL cert : " << sock.peerCertificate(); +} + + void QtNetworkTests::httpRequest() { auto manager = new QNetworkAccessManager(); + qDebug() << "Making request to" << HTTP_URL; QSignalSpy spy(manager, &QNetworkAccessManager::finished); - QNetworkRequest req(QUrl("http://google.com")); + QNetworkRequest req(HTTP_URL); manager->get(req); spy.wait(); @@ -40,14 +97,18 @@ void QtNetworkTests::httpRequest() { QList arguments = spy.takeFirst(); QNetworkReply *reply = arguments.at(0).value(); QVERIFY(!reply->error()); - qDebug() << reply->readAll().length() << "Bytes received"; + QVERIFY(!reply->sslConfiguration().isNull()); + + QString data = reply->readAll(); + qDebug() << "DATA: " << data; } void QtNetworkTests::httpsRequest() { auto manager = new QNetworkAccessManager(); + qDebug() << "Making request to" << HTTPS_URL; QSignalSpy spy(manager, &QNetworkAccessManager::finished); - QNetworkRequest req(QUrl("https://google.com")); + QNetworkRequest req(HTTPS_URL); manager->get(req); spy.wait(); @@ -56,5 +117,8 @@ void QtNetworkTests::httpsRequest() { QList arguments = spy.takeFirst(); QNetworkReply *reply = arguments.at(0).value(); QVERIFY(!reply->error()); - qDebug() << reply->readAll().length() << "Bytes received"; + QVERIFY(!reply->sslConfiguration().isNull()); + + QString data = reply->readAll(); + qDebug() << "DATA: " << data; } diff --git a/tests/networking/src/QtNetworkTests.h b/tests/networking/src/QtNetworkTests.h index 095f553f63..a0c3a1b038 100644 --- a/tests/networking/src/QtNetworkTests.h +++ b/tests/networking/src/QtNetworkTests.h @@ -1,14 +1,15 @@ // -// PacketTests.h +// PacketTests.cpp // tests/networking/src // -// Created by Stephen Birarda on 07/14/15. -// Copyright 2015 High Fidelity, Inc. +// Created by Dale Glass on 02/06/2024 +// Copyright 2024 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #ifndef overte_QtNetworkTests_h #define overte_QtNetworkTests_h @@ -20,6 +21,8 @@ class QtNetworkTests : public QObject { Q_OBJECT private slots: void initTestCase(); + void tcpSocket(); + void sslSocket(); void httpRequest(); void httpsRequest(); };