From 58574ea3590fbb28da5be73b983d83f0a8824d00 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 20 Oct 2009 15:03:56 +0200 Subject: tst_qsslsocket: new bigChunk testcase This new test is to find out if the BIO size of OpenSSL is limited or not. The test passes on my Linux, however the OpenSSL docu suggests that the BIO size is limited. From http://www.openssl.org/docs/crypto/BIO_s_bio.html "This is currently 17K". Reviewed-by: Peter Hartmann --- tests/auto/qsslsocket/tst_qsslsocket.cpp | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index 6b330e1..2f1c2e2 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -173,6 +173,7 @@ private slots: void disconnectFromHostWhenConnected(); void resetProxy(); void readFromClosedSocket(); + void writeBigChunk(); static void exitLoop() { @@ -1537,6 +1538,50 @@ void tst_QSslSocket::readFromClosedSocket() QVERIFY(!socket->bytesToWrite()); } +void tst_QSslSocket::writeBigChunk() +{ + if (!QSslSocket::supportsSsl()) + return; + + QSslSocketPtr socket = newSocket(); + this->socket = socket; + + connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); + socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); + + QByteArray data; + data.resize(1024*1024*10); // 10 MB + // init with garbage. needed so ssl cannot compress it in an efficient way. + for (int i = 0; i < data.size() / sizeof(int); i++) { + int r = qrand(); + data.data()[i*sizeof(int)] = r; + } + + QVERIFY(socket->waitForEncrypted(10000)); + QString errorBefore = socket->errorString(); + + int ret = socket->write(data.constData(), data.size()); + QVERIFY(data.size() == ret); + + // spin the event loop once so QSslSocket::transmit() gets called + QCoreApplication::processEvents(); + QString errorAfter = socket->errorString(); + + // no better way to do this right now since the error is the same as the default error. + if (socket->errorString().startsWith(QLatin1String("Unable to write data"))) + { + qWarning() << socket->error() << socket->errorString(); + QFAIL("Error while writing! Check if the OpenSSL BIO size is limited?!"); + } + // also check the error string. If another error (than UnknownError) occured, it should be different than before + QVERIFY(errorBefore == errorAfter); + + // check that everything has been written to OpenSSL + QVERIFY(socket->bytesToWrite() == 0); + + socket->close(); +} + #endif // QT_NO_OPENSSL QTEST_MAIN(tst_QSslSocket) -- cgit v0.12