[Libreoffice-commits] online.git: test/httpwserror.cpp test/Makefile.am test/UnitBadDocLoad.cpp
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jan 9 07:59:32 UTC 2020
test/Makefile.am | 7 +
test/UnitBadDocLoad.cpp | 222 +++++++++++++++++++++++-------------------------
2 files changed, 113 insertions(+), 116 deletions(-)
New commits:
commit d10bbef7499c0d19791fab85e83b7e44d8da01b1
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jan 9 08:33:48 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jan 9 08:59:09 2020 +0100
Convert the WS error tests to a new-style one
So that they are in-process, which means it's easier to debug when they fail.
Change-Id: Icb3d7a7d0ffa7371eb3056b5de7144137c0acb8a
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/86463
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 6789e3d63..a1b6528e1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -36,6 +36,7 @@ noinst_LTLIBRARIES = \
unit-calc.la \
unit-insert-delete.la \
unit-close.la \
+ unit-bad-doc-load.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
@@ -85,8 +86,7 @@ test_all_source = \
TileCacheTests.cpp \
integration-http-server.cpp \
httpwstest.cpp \
- httpcrashtest.cpp \
- httpwserror.cpp
+ httpcrashtest.cpp
unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
unittest_SOURCES = $(test_base_source) test.cpp
@@ -167,6 +167,8 @@ unit_insert_delete_la_SOURCES = UnitInsertDelete.cpp
unit_insert_delete_la_LIBADD = $(CPPUNIT_LIBS)
unit_close_la_SOURCES = UnitClose.cpp
unit_close_la_LIBADD = $(CPPUNIT_LIBS)
+unit_bad_doc_load_la_SOURCES = UnitBadDocLoad.cpp
+unit_bad_doc_load_la_LIBADD = $(CPPUNIT_LIBS)
if HAVE_LO_PATH
SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -201,6 +203,7 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t
unit-calc.la \
unit-insert-delete.la \
unit-close.la \
+ unit-bad-doc-load.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
# TESTS = unit-client.la
# TESTS += unit-admin.la
diff --git a/test/httpwserror.cpp b/test/UnitBadDocLoad.cpp
similarity index 55%
rename from test/httpwserror.cpp
rename to test/UnitBadDocLoad.cpp
index 9ba782803..7fe0f74e3 100644
--- a/test/httpwserror.cpp
+++ b/test/UnitBadDocLoad.cpp
@@ -7,106 +7,56 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <config.h>
-
-#include <vector>
+#include <memory>
+#include <ostream>
+#include <set>
#include <string>
-#include <Poco/Net/AcceptCertificateHandler.h>
-#include <Poco/Net/HTTPClientSession.h>
-#include <Poco/Net/HTTPRequest.h>
-#include <Poco/Net/HTTPResponse.h>
-#include <Poco/Net/HTTPSClientSession.h>
-#include <Poco/Net/InvalidCertificateHandler.h>
-#include <Poco/Net/NetException.h>
-#include <Poco/Net/SSLManager.h>
+#include <Poco/Exception.h>
+#include <Poco/RegularExpression.h>
#include <Poco/URI.h>
+#include <cppunit/TestAssert.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-#include <Common.hpp>
-#include <Protocol.hpp>
-#include <LOOLWebSocket.hpp>
+#include <Png.hpp>
+#include <Unit.hpp>
#include <helpers.hpp>
-#include <countloolkits.hpp>
-
-using namespace helpers;
-
-class HTTPWSError : public CPPUNIT_NS::TestFixture
-{
- const Poco::URI _uri;
- Poco::Net::HTTPResponse _response;
-
- CPPUNIT_TEST_SUITE(HTTPWSError);
- CPPUNIT_TEST(testBadDocLoadFail);
-// FIXME: Disabled recently - breaking the tests - should
-// check for the warning popup instead.
-#if 0
- CPPUNIT_TEST(testMaxDocuments);
- CPPUNIT_TEST(testMaxConnections);
- CPPUNIT_TEST(testMaxViews);
-#endif
+// Include config.h last, so the test server URI is still HTTP, even in SSL builds.
+#include <config.h>
- CPPUNIT_TEST_SUITE_END();
+class LOOLWebSocket;
- void testBadDocLoadFail();
- void testMaxDocuments();
- void testMaxConnections();
- void testMaxViews();
+/// Test suite for bad document loading, etc.
+class UnitBadDocLoad : public UnitWSD
+{
+ TestResult testBadDocLoadFail();
+ TestResult testMaxDocuments();
+ TestResult testMaxConnections();
+ TestResult testMaxViews();
public:
- HTTPWSError()
- : _uri(helpers::getTestServerURI())
- {
-#if ENABLE_SSL
- Poco::Net::initializeSSL();
- // Just accept the certificate anyway for testing purposes
- Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::AcceptCertificateHandler(false);
- Poco::Net::Context::Params sslParams;
- Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams);
- Poco::Net::SSLManager::instance().initializeClient(nullptr, invalidCertHandler, sslContext);
-#endif
- }
-
-#if ENABLE_SSL
- ~HTTPWSError()
- {
- Poco::Net::uninitializeSSL();
- }
-#endif
-
- void setUp()
- {
- resetTestStartTime();
- testCountHowManyLoolkits();
- resetTestStartTime();
- }
-
- void tearDown()
- {
- resetTestStartTime();
- testNoExtraLoolKitsLeft();
- resetTestStartTime();
- }
+ void invokeTest() override;
};
-void HTTPWSError::testBadDocLoadFail()
+UnitBase::TestResult UnitBadDocLoad::testBadDocLoadFail()
{
// Load corrupted document and validate error.
const char* testname = "docLoadFail ";
try
{
std::string documentPath, documentURL;
- getDocumentPathAndURL("corrupted.odt", documentPath, documentURL, testname);
+ helpers::getDocumentPathAndURL("corrupted.odt", documentPath, documentURL, testname);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
+ Poco::URI uri(helpers::getTestServerURI());
+ Poco::Net::HTTPResponse httpResponse;
+ std::shared_ptr<LOOLWebSocket> socket
+ = helpers::connectLOKit(uri, request, httpResponse, testname);
// Send a load request with incorrect password
- sendTextFrame(socket, "load url=" + documentURL, testname);
+ helpers::sendTextFrame(socket, "load url=" + documentURL, testname);
- const auto response = getResponseString(socket, "error:", testname);
+ const auto response = helpers::getResponseString(socket, "error:", testname);
std::vector<std::string> tokens(LOOLProtocol::tokenize(response, ' '));
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), tokens.size());
@@ -121,9 +71,10 @@ void HTTPWSError::testBadDocLoadFail()
{
CPPUNIT_FAIL(exc.displayText());
}
+ return TestResult::Ok;
}
-void HTTPWSError::testMaxDocuments()
+UnitBase::TestResult UnitBadDocLoad::testMaxDocuments()
{
static_assert(MAX_DOCUMENTS >= 2, "MAX_DOCUMENTS must be at least 2");
const char* testname = "maxDocuments ";
@@ -131,8 +82,9 @@ void HTTPWSError::testMaxDocuments()
if (MAX_DOCUMENTS > 20)
{
std::cerr << "Skipping " << testname << "test since MAX_DOCUMENTS (" << MAX_DOCUMENTS
- << ") is too high to test. Set to a more sensible number, ideally a dozen or so." << std::endl;
- return;
+ << ") is too high to test. Set to a more sensible number, ideally a dozen or so."
+ << std::endl;
+ return TestResult::Ok;
}
try
@@ -143,7 +95,8 @@ void HTTPWSError::testMaxDocuments()
std::cerr << "Loading max number of documents: " << MAX_DOCUMENTS << std::endl;
for (int it = 1; it <= MAX_DOCUMENTS; ++it)
{
- docs.emplace_back(loadDocAndGetSocket("empty.odt", _uri, testname));
+ Poco::URI uri(helpers::getTestServerURI());
+ docs.emplace_back(helpers::loadDocAndGetSocket("empty.odt", uri, testname));
std::cerr << "Loaded document #" << it << " of " << MAX_DOCUMENTS << std::endl;
}
@@ -152,19 +105,22 @@ void HTTPWSError::testMaxDocuments()
// try to open MAX_DOCUMENTS + 1
std::string docPath;
std::string docURL;
- getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
+ helpers::getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
- std::unique_ptr<Poco::Net::HTTPClientSession> session(createSession(_uri));
- auto socket = std::make_shared<LOOLWebSocket>(*session, request, _response);
+ Poco::URI uri(helpers::getTestServerURI());
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
+ Poco::Net::HTTPResponse httpResponse;
+ auto socket = std::make_shared<LOOLWebSocket>(*session, request, httpResponse);
// Send load request, which will fail.
- sendTextFrame(socket, "load url=" + docURL, testname);
+ helpers::sendTextFrame(socket, "load url=" + docURL, testname);
- assertResponseString(socket, "error:", testname);
+ helpers::assertResponseString(socket, "error:", testname);
std::string message;
- const int statusCode = getErrorCode(socket, message, testname);
- CPPUNIT_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode);
+ const int statusCode = helpers::getErrorCode(socket, message, testname);
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::WS_POLICY_VIOLATION),
+ statusCode);
socket->shutdown();
}
@@ -172,9 +128,10 @@ void HTTPWSError::testMaxDocuments()
{
CPPUNIT_FAIL(exc.displayText());
}
+ return TestResult::Ok;
}
-void HTTPWSError::testMaxConnections()
+UnitBase::TestResult UnitBadDocLoad::testMaxConnections()
{
static_assert(MAX_CONNECTIONS >= 3, "MAX_CONNECTIONS must be at least 3");
const char* testname = "maxConnections ";
@@ -182,8 +139,9 @@ void HTTPWSError::testMaxConnections()
if (MAX_CONNECTIONS > 40)
{
std::cerr << "Skipping " << testname << "test since MAX_CONNECTION (" << MAX_CONNECTIONS
- << ") is too high to test. Set to a more sensible number, ideally a dozen or so." << std::endl;
- return;
+ << ") is too high to test. Set to a more sensible number, ideally a dozen or so."
+ << std::endl;
+ return TestResult::Ok;
}
try
@@ -194,32 +152,37 @@ void HTTPWSError::testMaxConnections()
std::string docPath;
std::string docURL;
- getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
+ helpers::getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
- std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, docURL, testname);
+ Poco::URI uri(helpers::getTestServerURI());
+ std::shared_ptr<LOOLWebSocket> socket = helpers::loadDocAndGetSocket(uri, docURL, testname);
std::cerr << "Opened connection #1 of " << MAX_CONNECTIONS << std::endl;
std::vector<std::shared_ptr<LOOLWebSocket>> views;
for (int it = 1; it < MAX_CONNECTIONS; ++it)
{
- std::unique_ptr<Poco::Net::HTTPClientSession> session(createSession(_uri));
- auto ws = std::make_shared<LOOLWebSocket>(*session, request, _response);
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
+ Poco::Net::HTTPResponse httpResponse;
+ auto ws = std::make_shared<LOOLWebSocket>(*session, request, httpResponse);
views.emplace_back(ws);
- std::cerr << "Opened connection #" << (it+1) << " of " << MAX_CONNECTIONS << std::endl;
+ std::cerr << "Opened connection #" << (it + 1) << " of " << MAX_CONNECTIONS
+ << std::endl;
}
std::cerr << "Opening one more connection beyond the limit." << std::endl;
// try to connect MAX_CONNECTIONS + 1
- std::unique_ptr<Poco::Net::HTTPClientSession> session(createSession(_uri));
- auto socketN = std::make_shared<LOOLWebSocket>(*session, request, _response);
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
+ Poco::Net::HTTPResponse httpResponse;
+ auto socketN = std::make_shared<LOOLWebSocket>(*session, request, httpResponse);
// Send load request, which will fail.
- sendTextFrame(socketN, "load url=" + docURL, testname);
+ helpers::sendTextFrame(socketN, "load url=" + docURL, testname);
std::string message;
- const int statusCode = getErrorCode(socketN, message, testname);
- CPPUNIT_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode);
+ const int statusCode = helpers::getErrorCode(socketN, message, testname);
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::WS_POLICY_VIOLATION),
+ statusCode);
socketN->shutdown();
}
@@ -227,9 +190,10 @@ void HTTPWSError::testMaxConnections()
{
CPPUNIT_FAIL(exc.displayText());
}
+ return TestResult::Ok;
}
-void HTTPWSError::testMaxViews()
+UnitBase::TestResult UnitBadDocLoad::testMaxViews()
{
static_assert(MAX_CONNECTIONS >= 3, "MAX_CONNECTIONS must be at least 3");
const char* testname = "maxViews ";
@@ -237,8 +201,9 @@ void HTTPWSError::testMaxViews()
if (MAX_CONNECTIONS > 40)
{
std::cerr << "Skipping " << testname << "test since MAX_CONNECTION (" << MAX_CONNECTIONS
- << ") is too high to test. Set to a more sensible number, ideally a dozen or so." << std::endl;
- return;
+ << ") is too high to test. Set to a more sensible number, ideally a dozen or so."
+ << std::endl;
+ return TestResult::Ok;
}
try
@@ -249,37 +214,66 @@ void HTTPWSError::testMaxViews()
std::string docPath;
std::string docURL;
- getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
+ helpers::getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
- std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, docURL, testname);
+ Poco::URI uri(helpers::getTestServerURI());
+ std::shared_ptr<LOOLWebSocket> socket = helpers::loadDocAndGetSocket(uri, docURL, testname);
std::cerr << "Opened view #1 of " << MAX_CONNECTIONS << std::endl;
std::vector<std::shared_ptr<LOOLWebSocket>> views;
for (int it = 1; it < MAX_CONNECTIONS; ++it)
{
- views.emplace_back(loadDocAndGetSocket(_uri, docURL, testname));
- std::cerr << "Opened view #" << (it+1) << " of " << MAX_CONNECTIONS << std::endl;
+ views.emplace_back(helpers::loadDocAndGetSocket(uri, docURL, testname));
+ std::cerr << "Opened view #" << (it + 1) << " of " << MAX_CONNECTIONS << std::endl;
}
std::cerr << "Opening one more connection beyond the limit." << std::endl;
// try to connect MAX_CONNECTIONS + 1
- std::unique_ptr<Poco::Net::HTTPClientSession> session(createSession(_uri));
- auto socketN = std::make_shared<LOOLWebSocket>(*session, request, _response);
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
+ Poco::Net::HTTPResponse httpResponse;
+ auto socketN = std::make_shared<LOOLWebSocket>(*session, request, httpResponse);
// Send load request, which will fail.
- sendTextFrame(socketN, "load url=" + docURL, testname);
+ helpers::sendTextFrame(socketN, "load url=" + docURL, testname);
std::string message;
- const int statusCode = getErrorCode(socketN, message, testname);
- CPPUNIT_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode);
+ const int statusCode = helpers::getErrorCode(socketN, message, testname);
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::WS_POLICY_VIOLATION),
+ statusCode);
}
catch (const Poco::Exception& exc)
{
CPPUNIT_FAIL(exc.displayText());
}
+ return TestResult::Ok;
+}
+
+void UnitBadDocLoad::invokeTest()
+{
+ UnitBase::TestResult result = testBadDocLoadFail();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+// FIXME: Disabled recently - breaking the tests - should
+// check for the warning popup instead.
+#if 0
+ result = testMaxDocuments();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testMaxConnections();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testMaxViews();
+ if (result != TestResult::Ok)
+ exitTest(result);
+#endif
+
+ exitTest(TestResult::Ok);
}
-CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSError);
+UnitBase* unit_create_wsd(void) { return new UnitBadDocLoad(); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list