[Libreoffice-commits] online.git: test/httpwstest.cpp test/Makefile.am test/UnitPasswordProtected.cpp
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Mon Oct 28 08:12:51 UTC 2019
test/Makefile.am | 4
test/UnitPasswordProtected.cpp | 232 +++++++++++++++++++++++++++++++++++++++++
test/httpwstest.cpp | 145 -------------------------
3 files changed, 236 insertions(+), 145 deletions(-)
New commits:
commit cf19ee6ce51b54d66c4c0c6b9df2fa63ea158498
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Oct 28 09:12:25 2019 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Oct 28 09:12:32 2019 +0100
Convert password protected test to a new-style one
So that they are in-process, which means it's easier to debug when they
fail.
Change-Id: Ie57d028314fec1994f603097cf408cbda2fee8f4
diff --git a/test/Makefile.am b/test/Makefile.am
index cb5d1dac6..fa0fd6524 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -26,6 +26,7 @@ noinst_LTLIBRARIES = \
unit-paste.la \
unit-load-torture.la \
unit-rendering-options.la \
+ unit-password-protected.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
@@ -134,6 +135,8 @@ unit_load_torture_la_SOURCES = UnitLoadTorture.cpp
unit_load_torture_la_LIBADD = $(CPPUNIT_LIBS)
unit_rendering_options_la_SOURCES = UnitRenderingOptions.cpp
unit_rendering_options_la_LIBADD = $(CPPUNIT_LIBS)
+unit_password_protected_la_SOURCES = UnitPasswordProtected.cpp
+unit_password_protected_la_LIBADD = $(CPPUNIT_LIBS)
if HAVE_LO_PATH
SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -158,6 +161,7 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t
unit-paste.la \
unit-load-torture.la \
unit-rendering-options.la \
+ unit-password-protected.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
# TESTS = unit-client.la
# TESTS += unit-admin.la
diff --git a/test/UnitPasswordProtected.cpp b/test/UnitPasswordProtected.cpp
new file mode 100644
index 000000000..f20c6580d
--- /dev/null
+++ b/test/UnitPasswordProtected.cpp
@@ -0,0 +1,232 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <memory>
+#include <string>
+
+#include <Poco/URI.h>
+#include <cppunit/TestAssert.h>
+
+#include <Unit.hpp>
+#include <Util.hpp>
+#include <helpers.hpp>
+
+class LOOLWebSocket;
+
+/// Password protected testcase.
+class UnitPasswordProtected : public UnitWSD
+{
+ TestResult testPasswordProtectedDocumentWithoutPassword();
+ TestResult testPasswordProtectedDocumentWithWrongPassword();
+ TestResult testPasswordProtectedDocumentWithCorrectPassword();
+ TestResult testPasswordProtectedDocumentWithCorrectPasswordAgain();
+ TestResult testPasswordProtectedOOXMLDocument();
+ TestResult testPasswordProtectedBinaryMSOfficeDocument();
+
+public:
+ void invokeTest() override;
+};
+
+UnitBase::TestResult UnitPasswordProtected::testPasswordProtectedDocumentWithoutPassword()
+{
+ const char* testname = "testPasswordProtectedDocumentWithoutPassword";
+ try
+ {
+ std::string documentPath, documentURL;
+ helpers::getDocumentPathAndURL("password-protected.ods", documentPath, documentURL,
+ testname);
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPResponse httpResponse;
+ std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(
+ Poco::URI(helpers::getTestServerURI()), request, httpResponse, testname);
+
+ // Send a load request without password first
+ helpers::sendTextFrame(socket, "load url=" + documentURL);
+
+ const auto response = helpers::getResponseString(socket, "error:", testname);
+ Poco::StringTokenizer tokens(response, " ",
+ Poco::StringTokenizer::TOK_IGNORE_EMPTY
+ | Poco::StringTokenizer::TOK_TRIM);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), tokens.count());
+
+ std::string errorCommand;
+ std::string errorKind;
+ LOOLProtocol::getTokenString(tokens[1], "cmd", errorCommand);
+ LOOLProtocol::getTokenString(tokens[2], "kind", errorKind);
+ CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
+ CPPUNIT_ASSERT_EQUAL(std::string("passwordrequired:to-view"), errorKind);
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+
+ return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitPasswordProtected::testPasswordProtectedDocumentWithWrongPassword()
+{
+ const char* testname = "testPasswordProtectedDocumentWithWrongPassword";
+ try
+ {
+ std::string documentPath, documentURL;
+ helpers::getDocumentPathAndURL("password-protected.ods", documentPath, documentURL,
+ testname);
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPResponse httpResponse;
+ std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(
+ Poco::URI(helpers::getTestServerURI()), request, httpResponse, testname);
+
+ // Send a load request with incorrect password
+ helpers::sendTextFrame(socket, "load url=" + documentURL + " password=2");
+
+ const auto response = helpers::getResponseString(socket, "error:", testname);
+ Poco::StringTokenizer tokens(response, " ",
+ Poco::StringTokenizer::TOK_IGNORE_EMPTY
+ | Poco::StringTokenizer::TOK_TRIM);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), tokens.count());
+
+ std::string errorCommand;
+ std::string errorKind;
+ LOOLProtocol::getTokenString(tokens[1], "cmd", errorCommand);
+ LOOLProtocol::getTokenString(tokens[2], "kind", errorKind);
+ CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
+ CPPUNIT_ASSERT_EQUAL(std::string("wrongpassword"), errorKind);
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+
+ return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitPasswordProtected::testPasswordProtectedDocumentWithCorrectPassword()
+{
+ const char* testname = "testPasswordProtectedDocumentWithCorrectPassword";
+ try
+ {
+ std::string documentPath, documentURL;
+ helpers::getDocumentPathAndURL("password-protected.ods", documentPath, documentURL,
+ testname);
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPResponse response;
+ std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(
+ Poco::URI(helpers::getTestServerURI()), request, response, testname);
+
+ // Send a load request with correct password
+ helpers::sendTextFrame(socket, "load url=" + documentURL + " password=1");
+
+ CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL,
+ helpers::isDocumentLoaded(socket, testname));
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+
+ return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitPasswordProtected::testPasswordProtectedDocumentWithCorrectPasswordAgain()
+{
+ return testPasswordProtectedDocumentWithCorrectPassword();
+}
+
+UnitBase::TestResult UnitPasswordProtected::testPasswordProtectedOOXMLDocument()
+{
+ const char* testname = "testPasswordProtectedOOXMLDocument";
+ try
+ {
+ std::string documentPath, documentURL;
+ helpers::getDocumentPathAndURL("password-protected.docx", documentPath, documentURL,
+ testname);
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPResponse response;
+ std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(
+ Poco::URI(helpers::getTestServerURI()), request, response, testname);
+
+ // Send a load request with correct password
+ helpers::sendTextFrame(socket, "load url=" + documentURL + " password=abc");
+
+ CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL,
+ helpers::isDocumentLoaded(socket, testname));
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+
+ return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitPasswordProtected::testPasswordProtectedBinaryMSOfficeDocument()
+{
+ const char* testname = "testPasswordProtectedBinaryMSOfficeDocument";
+ try
+ {
+ std::string documentPath, documentURL;
+ helpers::getDocumentPathAndURL("password-protected.doc", documentPath, documentURL,
+ testname);
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPResponse response;
+ std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(
+ Poco::URI(helpers::getTestServerURI()), request, response, testname);
+
+ // Send a load request with correct password
+ helpers::sendTextFrame(socket, "load url=" + documentURL + " password=abc");
+
+ CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL,
+ helpers::isDocumentLoaded(socket, testname));
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+
+ return TestResult::Ok;
+}
+
+void UnitPasswordProtected::invokeTest()
+{
+ UnitBase::TestResult result = testPasswordProtectedDocumentWithoutPassword();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testPasswordProtectedDocumentWithWrongPassword();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testPasswordProtectedDocumentWithCorrectPassword();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testPasswordProtectedDocumentWithCorrectPasswordAgain();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testPasswordProtectedOOXMLDocument();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testPasswordProtectedBinaryMSOfficeDocument();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ exitTest(TestResult::Ok);
+}
+
+UnitBase* unit_create_wsd(void) { return new UnitPasswordProtected(); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp
index cb2ea5d27..345c94c08 100644
--- a/test/httpwstest.cpp
+++ b/test/httpwstest.cpp
@@ -98,12 +98,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testReloadWhileDisconnecting);
CPPUNIT_TEST(testExcelLoad);
CPPUNIT_TEST(testPasteBlank);
- CPPUNIT_TEST(testPasswordProtectedDocumentWithoutPassword);
- CPPUNIT_TEST(testPasswordProtectedDocumentWithWrongPassword);
- CPPUNIT_TEST(testPasswordProtectedDocumentWithCorrectPassword);
- CPPUNIT_TEST(testPasswordProtectedDocumentWithCorrectPasswordAgain);
- CPPUNIT_TEST(testPasswordProtectedOOXMLDocument);
- CPPUNIT_TEST(testPasswordProtectedBinaryMSOfficeDocument);
CPPUNIT_TEST(testInsertDelete);
CPPUNIT_TEST(testSlideShow);
CPPUNIT_TEST(testInactiveClient);
@@ -151,12 +145,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
void testReloadWhileDisconnecting();
void testExcelLoad();
void testPasteBlank();
- void testPasswordProtectedDocumentWithoutPassword();
- void testPasswordProtectedDocumentWithWrongPassword();
- void testPasswordProtectedDocumentWithCorrectPassword();
- void testPasswordProtectedDocumentWithCorrectPasswordAgain();
- void testPasswordProtectedOOXMLDocument();
- void testPasswordProtectedBinaryMSOfficeDocument();
void testInsertDelete();
void testSlideShow();
void testInactiveClient();
@@ -744,139 +732,6 @@ void HTTPWSTest::testPasteBlank()
}
}
-void HTTPWSTest::testPasswordProtectedDocumentWithoutPassword()
-{
- const char* testname = "passwordProtectedDocumentWithoutPassword ";
- try
- {
- std::string documentPath, documentURL;
- getDocumentPathAndURL("password-protected.ods", documentPath, documentURL, testname);
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-
- // Send a load request without password first
- sendTextFrame(socket, "load url=" + documentURL);
-
- const auto response = getResponseString(socket, "error:", testname);
- Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), tokens.count());
-
- std::string errorCommand;
- std::string errorKind;
- LOOLProtocol::getTokenString(tokens[1], "cmd", errorCommand);
- LOOLProtocol::getTokenString(tokens[2], "kind", errorKind);
- CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
- CPPUNIT_ASSERT_EQUAL(std::string("passwordrequired:to-view"), errorKind);
- }
- catch (const Poco::Exception& exc)
- {
- CPPUNIT_FAIL(exc.displayText());
- }
-}
-
-void HTTPWSTest::testPasswordProtectedDocumentWithWrongPassword()
-{
- const char* testname = "passwordProtectedDocumentWithWrongPassword ";
- try
- {
- std::string documentPath, documentURL;
- getDocumentPathAndURL("password-protected.ods", documentPath, documentURL, testname);
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-
- // Send a load request with incorrect password
- sendTextFrame(socket, "load url=" + documentURL + " password=2");
-
- const auto response = getResponseString(socket, "error:", testname);
- Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), tokens.count());
-
- std::string errorCommand;
- std::string errorKind;
- LOOLProtocol::getTokenString(tokens[1], "cmd", errorCommand);
- LOOLProtocol::getTokenString(tokens[2], "kind", errorKind);
- CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
- CPPUNIT_ASSERT_EQUAL(std::string("wrongpassword"), errorKind);
- }
- catch (const Poco::Exception& exc)
- {
- CPPUNIT_FAIL(exc.displayText());
- }
-}
-
-void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPassword()
-{
- const char* testname = "passwordProtectedDocumentWithCorrectPassword ";
- try
- {
- std::string documentPath, documentURL;
- getDocumentPathAndURL("password-protected.ods", documentPath, documentURL, testname);
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-
- // Send a load request with correct password
- sendTextFrame(socket, "load url=" + documentURL + " password=1");
-
- CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL, isDocumentLoaded(socket, testname));
- }
- catch (const Poco::Exception& exc)
- {
- CPPUNIT_FAIL(exc.displayText());
- }
-}
-
-void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPasswordAgain()
-{
- testPasswordProtectedDocumentWithCorrectPassword();
-}
-
-void HTTPWSTest::testPasswordProtectedOOXMLDocument()
-{
- const char* testname = "passwordProtectedOOXMLDocument ";
- try
- {
- std::string documentPath, documentURL;
- getDocumentPathAndURL("password-protected.docx", documentPath, documentURL, testname);
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-
- // Send a load request with correct password
- sendTextFrame(socket, "load url=" + documentURL + " password=abc");
-
- CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL, isDocumentLoaded(socket, testname));
- }
- catch (const Poco::Exception& exc)
- {
- CPPUNIT_FAIL(exc.displayText());
- }
-}
-
-void HTTPWSTest::testPasswordProtectedBinaryMSOfficeDocument()
-{
- const char* testname = "passwordProtectedBinaryMSOfficeDocument ";
- try
- {
- std::string documentPath, documentURL;
- getDocumentPathAndURL("password-protected.doc", documentPath, documentURL, testname);
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-
- // Send a load request with correct password
- sendTextFrame(socket, "load url=" + documentURL + " password=abc");
-
- CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL, isDocumentLoaded(socket, testname));
- }
- catch (const Poco::Exception& exc)
- {
- CPPUNIT_FAIL(exc.displayText());
- }
-}
-
void HTTPWSTest::testInsertDelete()
{
const char* testname = "insertDelete ";
More information about the Libreoffice-commits
mailing list