2015-10-28 04:34:20 -05:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
2016-04-08 06:49:33 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-03-21 03:37:39 -05:00
|
|
|
#include <Poco/Net/AcceptCertificateHandler.h>
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
2016-04-08 04:24:52 -05:00
|
|
|
#include <Poco/Net/HTTPClientSession.h>
|
2016-03-21 03:37:39 -05:00
|
|
|
#include <Poco/Net/HTTPSClientSession.h>
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <Poco/Net/HTTPResponse.h>
|
2016-03-21 03:37:39 -05:00
|
|
|
#include <Poco/Net/InvalidCertificateHandler.h>
|
2016-02-18 15:11:01 -06:00
|
|
|
#include <Poco/Net/NetException.h>
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <Poco/Net/WebSocket.h>
|
2016-03-22 13:32:21 -05:00
|
|
|
#include <Poco/Net/PrivateKeyPassphraseHandler.h>
|
2016-02-18 15:11:01 -06:00
|
|
|
#include <Poco/Net/Socket.h>
|
2016-03-21 03:37:39 -05:00
|
|
|
#include <Poco/Net/SSLManager.h>
|
2016-01-05 14:32:53 -06:00
|
|
|
#include <Poco/Path.h>
|
2015-11-19 04:01:34 -06:00
|
|
|
#include <Poco/StringTokenizer.h>
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <Poco/URI.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
2016-02-20 15:13:35 -06:00
|
|
|
#include <Poco/JSON/JSON.h>
|
|
|
|
#include <Poco/JSON/Parser.h>
|
|
|
|
#include <Poco/Dynamic/Var.h>
|
2016-03-19 16:35:24 -05:00
|
|
|
|
2016-01-05 14:32:53 -06:00
|
|
|
#include <Common.hpp>
|
2016-03-19 16:35:24 -05:00
|
|
|
#include <Util.hpp>
|
|
|
|
#include <LOOLProtocol.hpp>
|
2015-10-28 04:34:20 -05:00
|
|
|
|
|
|
|
/// Tests the HTTP WebSocket API of loolwsd. The server has to be started manually before running this test.
|
|
|
|
class HTTPWSTest : public CPPUNIT_NS::TestFixture
|
|
|
|
{
|
2016-01-24 13:58:08 -06:00
|
|
|
const Poco::URI _uri;
|
2015-11-19 04:11:47 -06:00
|
|
|
Poco::Net::HTTPResponse _response;
|
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE(HTTPWSTest);
|
2016-03-25 13:23:26 -05:00
|
|
|
CPPUNIT_TEST(testLoad);
|
2016-03-29 20:29:53 -05:00
|
|
|
CPPUNIT_TEST(testBadLoad);
|
2016-03-25 13:23:26 -05:00
|
|
|
CPPUNIT_TEST(testReload);
|
2016-03-29 20:29:53 -05:00
|
|
|
//CPPUNIT_TEST(testSaveOnDisconnect);
|
2016-03-25 13:23:26 -05:00
|
|
|
CPPUNIT_TEST(testExcelLoad);
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST(testPaste);
|
2016-01-18 04:44:35 -06:00
|
|
|
CPPUNIT_TEST(testLargePaste);
|
2015-11-19 04:01:34 -06:00
|
|
|
CPPUNIT_TEST(testRenderingOptions);
|
2016-03-03 09:31:13 -06:00
|
|
|
CPPUNIT_TEST(testPasswordProtectedDocumentWithoutPassword);
|
|
|
|
CPPUNIT_TEST(testPasswordProtectedDocumentWithWrongPassword);
|
|
|
|
CPPUNIT_TEST(testPasswordProtectedDocumentWithCorrectPassword);
|
|
|
|
CPPUNIT_TEST(testPasswordProtectedDocumentWithCorrectPasswordAgain);
|
2016-02-20 15:13:35 -06:00
|
|
|
CPPUNIT_TEST(testImpressPartCountChanged);
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2016-03-25 13:23:26 -05:00
|
|
|
void testLoad();
|
2016-03-29 20:29:53 -05:00
|
|
|
void testBadLoad();
|
2016-03-25 13:23:26 -05:00
|
|
|
void testReload();
|
2016-03-29 20:29:53 -05:00
|
|
|
void testSaveOnDisconnect();
|
2016-03-25 13:23:26 -05:00
|
|
|
void testExcelLoad();
|
2015-10-28 04:34:20 -05:00
|
|
|
void testPaste();
|
2016-01-18 04:44:35 -06:00
|
|
|
void testLargePaste();
|
2015-11-19 04:01:34 -06:00
|
|
|
void testRenderingOptions();
|
2016-03-03 09:31:13 -06:00
|
|
|
void testPasswordProtectedDocumentWithoutPassword();
|
|
|
|
void testPasswordProtectedDocumentWithWrongPassword();
|
|
|
|
void testPasswordProtectedDocumentWithCorrectPassword();
|
|
|
|
void testPasswordProtectedDocumentWithCorrectPasswordAgain();
|
2016-02-20 15:13:35 -06:00
|
|
|
void testImpressPartCountChanged();
|
2015-10-28 04:34:20 -05:00
|
|
|
|
2016-01-24 13:58:08 -06:00
|
|
|
static
|
2015-10-28 04:34:20 -05:00
|
|
|
void sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string);
|
2016-01-24 13:58:08 -06:00
|
|
|
|
2016-02-18 15:11:01 -06:00
|
|
|
static
|
|
|
|
bool isDocumentLoaded(Poco::Net::WebSocket& socket);
|
|
|
|
|
2016-02-20 15:13:35 -06:00
|
|
|
static
|
|
|
|
void getResponseMessage(Poco::Net::WebSocket& socket,
|
|
|
|
const std::string& prefix,
|
|
|
|
std::string& response,
|
|
|
|
const bool isLine);
|
2015-11-19 04:11:47 -06:00
|
|
|
public:
|
|
|
|
HTTPWSTest()
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-04-04 02:08:18 -05:00
|
|
|
: _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
: _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
|
|
|
|
#endif
|
2015-11-19 04:11:47 -06:00
|
|
|
{
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-21 03:37:39 -05:00
|
|
|
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(0, invalidCertHandler, sslContext);
|
2016-04-08 04:24:52 -05:00
|
|
|
#endif
|
2016-03-21 03:37:39 -05:00
|
|
|
}
|
|
|
|
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-21 03:37:39 -05:00
|
|
|
~HTTPWSTest()
|
|
|
|
{
|
|
|
|
Poco::Net::uninitializeSSL();
|
2015-11-19 04:11:47 -06:00
|
|
|
}
|
2016-04-08 04:24:52 -05:00
|
|
|
#endif
|
2016-01-24 13:58:08 -06:00
|
|
|
|
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
}
|
2015-10-28 04:34:20 -05:00
|
|
|
};
|
|
|
|
|
2016-03-25 13:23:26 -05:00
|
|
|
void HTTPWSTest::testLoad()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get its status.
|
2016-03-29 20:29:53 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
|
2016-03-25 13:23:26 -05:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
|
|
|
|
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
std::string status;
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
2016-03-29 20:29:53 -05:00
|
|
|
std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << std::endl;
|
2016-03-25 13:23:26 -05:00
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
|
|
|
{
|
2016-03-29 20:29:53 -05:00
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl;
|
|
|
|
const std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
|
|
|
const std::string prefix = "status: ";
|
2016-03-25 13:23:26 -05:00
|
|
|
if (line.find(prefix) == 0)
|
|
|
|
{
|
|
|
|
status = line.substr(prefix.length());
|
|
|
|
// Might be too strict, consider something flexible instread.
|
2016-03-29 20:29:53 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=1 current=0 width=12808 height=16408"), status);
|
2016-03-25 13:23:26 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
2016-03-29 20:29:53 -05:00
|
|
|
|
|
|
|
sendTextFrame(socket, "disconnect");
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPWSTest::testBadLoad()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get its status.
|
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
|
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-29 20:29:53 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-29 20:29:53 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
|
|
|
|
|
|
|
// Before loading request status.
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
|
|
|
std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << std::endl;
|
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
|
|
|
{
|
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl;
|
|
|
|
const std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
2016-04-11 02:00:45 -05:00
|
|
|
|
|
|
|
// For some reason the server claims a client has the 'edit lock' even if no
|
|
|
|
// document has been successfully loaded
|
|
|
|
if (LOOLProtocol::getFirstToken(buffer, n) == "editlock:")
|
|
|
|
continue;
|
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("error: cmd=status kind=nodocloaded"), line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
|
|
|
|
sendTextFrame(socket, "disconnect");
|
2016-03-25 13:23:26 -05:00
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-03-25 13:23:26 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-25 13:23:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPWSTest::testReload()
|
|
|
|
{
|
|
|
|
for (auto i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
testLoad();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
void HTTPWSTest::testSaveOnDisconnect()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get its status.
|
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
|
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-29 20:29:53 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-29 20:29:53 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
|
|
|
|
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
sendTextFrame(socket, "uno .uno:SelectAll");
|
|
|
|
sendTextFrame(socket, "uno .uno:Delete");
|
|
|
|
sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc");
|
|
|
|
|
|
|
|
socket.shutdown();
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load the same document and check that the last changes (pasted text) is saved.
|
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
|
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-29 20:29:53 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-29 20:29:53 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
|
|
|
|
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
// Check if the document contains the pasted text.
|
|
|
|
sendTextFrame(socket, "uno .uno:SelectAll");
|
|
|
|
sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8");
|
|
|
|
std::string selection;
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
|
|
|
std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
|
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
|
|
|
{
|
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
|
|
|
|
const std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
|
|
|
const std::string prefix = "textselectioncontent: ";
|
|
|
|
if (line.find(prefix) == 0)
|
|
|
|
{
|
|
|
|
selection = line.substr(prefix.length());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-03-29 20:29:53 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection);
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 13:23:26 -05:00
|
|
|
void HTTPWSTest::testExcelLoad()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and make it empty.
|
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "timeline.xlsx");
|
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
|
|
|
|
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
std::string status;
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
|
|
|
std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
|
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
|
|
|
{
|
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
|
|
|
|
const std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
|
|
|
std::string prefix = "status: ";
|
|
|
|
if (line.find(prefix) == 0)
|
|
|
|
{
|
|
|
|
status = line.substr(prefix.length());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-03-25 13:23:26 -05:00
|
|
|
// Expected format is something like 'type=text parts=2 current=0 width=12808 height=1142'.
|
|
|
|
Poco::StringTokenizer tokens(status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count());
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-25 13:23:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
void HTTPWSTest::testPaste()
|
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
try
|
2015-10-28 04:34:20 -05:00
|
|
|
{
|
2016-03-29 20:29:53 -05:00
|
|
|
// Load a document and make it empty, then paste some text into it.
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
|
2016-02-18 15:11:01 -06:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
2016-03-13 12:23:12 -05:00
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-03-13 12:23:12 -05:00
|
|
|
|
2016-02-18 15:11:01 -06:00
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
sendTextFrame(socket, "uno .uno:SelectAll");
|
|
|
|
sendTextFrame(socket, "uno .uno:Delete");
|
|
|
|
|
|
|
|
// Paste some text into it.
|
|
|
|
sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc");
|
|
|
|
|
|
|
|
// Check if the document contains the pasted text.
|
|
|
|
sendTextFrame(socket, "uno .uno:SelectAll");
|
|
|
|
sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8");
|
|
|
|
std::string selection;
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
2015-10-28 04:34:20 -05:00
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
|
2016-02-22 05:48:15 -06:00
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
2015-10-28 04:34:20 -05:00
|
|
|
{
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
|
2016-02-18 15:11:01 -06:00
|
|
|
const std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
|
|
|
const std::string prefix = "textselectioncontent: ";
|
|
|
|
if (line.find(prefix) == 0)
|
|
|
|
{
|
|
|
|
selection = line.substr(prefix.length());
|
|
|
|
break;
|
|
|
|
}
|
2015-10-28 04:34:20 -05:00
|
|
|
}
|
|
|
|
}
|
2016-02-18 15:11:01 -06:00
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
socket.shutdown();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection);
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-02-18 15:11:01 -06:00
|
|
|
}
|
2016-02-19 01:37:29 -06:00
|
|
|
catch (const Poco::Exception& exc)
|
2016-02-18 15:11:01 -06:00
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2015-10-28 04:34:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-18 04:44:35 -06:00
|
|
|
void HTTPWSTest::testLargePaste()
|
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
try
|
2016-01-18 04:44:35 -06:00
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
// Load a document and make it empty.
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
|
2016-03-13 12:23:12 -05:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-02-18 15:11:01 -06:00
|
|
|
|
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
sendTextFrame(socket, "uno .uno:SelectAll");
|
|
|
|
sendTextFrame(socket, "uno .uno:Delete");
|
|
|
|
|
|
|
|
// Paste some text into it.
|
|
|
|
std::ifstream documentStream(documentPath);
|
|
|
|
std::string documentContents((std::istreambuf_iterator<char>(documentStream)), std::istreambuf_iterator<char>());
|
|
|
|
sendTextFrame(socket, "paste mimetype=text/html\n" + documentContents);
|
|
|
|
|
|
|
|
// Check if the server is still alive.
|
|
|
|
// This resulted first in a hang, as respose for the message never arrived, then a bit later in a Poco::TimeoutException.
|
|
|
|
sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8");
|
|
|
|
std::string selection;
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
2016-01-18 04:44:35 -06:00
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
2016-02-22 05:48:15 -06:00
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
2016-02-18 15:11:01 -06:00
|
|
|
{
|
2016-02-25 02:31:36 -06:00
|
|
|
std::cout << "Received message length " << n << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
|
2016-02-18 15:11:01 -06:00
|
|
|
std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
|
|
|
std::string prefix = "textselectioncontent: ";
|
|
|
|
if (line.find(prefix) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2016-01-18 04:44:35 -06:00
|
|
|
}
|
2016-02-18 15:11:01 -06:00
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-02-18 15:11:01 -06:00
|
|
|
}
|
2016-02-19 01:37:29 -06:00
|
|
|
catch (const Poco::Exception& exc)
|
2016-02-18 15:11:01 -06:00
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-01-18 04:44:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-19 04:01:34 -06:00
|
|
|
void HTTPWSTest::testRenderingOptions()
|
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
try
|
2015-11-19 04:01:34 -06:00
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
// Load a document and get its size.
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "hide-whitespace.odt");
|
2016-02-18 15:11:01 -06:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
const std::string options = "{\"rendering\":{\".uno:HideWhitespace\":{\"type\":\"boolean\",\"value\":\"true\"}}}";
|
2016-03-13 12:23:12 -05:00
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-03-13 12:23:12 -05:00
|
|
|
|
2016-02-18 15:11:01 -06:00
|
|
|
sendTextFrame(socket, "load url=" + documentURL + " options=" + options);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
|
|
|
|
std::string status;
|
|
|
|
int flags;
|
|
|
|
int n;
|
|
|
|
do
|
2015-11-19 04:01:34 -06:00
|
|
|
{
|
2016-02-18 15:11:01 -06:00
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
|
2016-02-22 05:48:15 -06:00
|
|
|
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
2015-11-19 04:01:34 -06:00
|
|
|
{
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
|
2016-02-18 15:11:01 -06:00
|
|
|
std::string line = LOOLProtocol::getFirstLine(buffer, n);
|
|
|
|
std::string prefix = "status: ";
|
|
|
|
if (line.find(prefix) == 0)
|
|
|
|
{
|
|
|
|
status = line.substr(prefix.length());
|
|
|
|
break;
|
|
|
|
}
|
2015-11-19 04:01:34 -06:00
|
|
|
}
|
|
|
|
}
|
2016-02-18 15:11:01 -06:00
|
|
|
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
|
|
|
|
2016-02-18 15:11:01 -06:00
|
|
|
// Expected format is something like 'type=text parts=2 current=0 width=12808 height=1142'.
|
|
|
|
Poco::StringTokenizer tokens(status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count());
|
|
|
|
|
|
|
|
const std::string token = tokens[4];
|
|
|
|
const std::string prefix = "height=";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), token.find(prefix));
|
|
|
|
const int height = std::stoi(token.substr(prefix.size()));
|
|
|
|
// HideWhitespace was ignored, this was 32532, should be around 16706.
|
|
|
|
CPPUNIT_ASSERT(height < 20000);
|
|
|
|
}
|
2016-02-19 01:37:29 -06:00
|
|
|
catch (const Poco::Exception& exc)
|
2016-02-18 15:11:01 -06:00
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2015-11-19 04:01:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-03 09:31:13 -06:00
|
|
|
void HTTPWSTest::testPasswordProtectedDocumentWithoutPassword()
|
2016-02-17 15:15:28 -06:00
|
|
|
{
|
2016-03-01 02:55:06 -06:00
|
|
|
try
|
|
|
|
{
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "password-protected.ods");
|
2016-02-19 16:22:22 -06:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
2016-03-13 12:23:12 -05:00
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-03-13 12:23:12 -05:00
|
|
|
|
2016-02-19 16:22:22 -06:00
|
|
|
// Send a load request without password first
|
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
2016-02-21 08:50:40 -06:00
|
|
|
std::string response;
|
2016-02-19 16:22:22 -06:00
|
|
|
|
2016-02-21 08:50:40 -06:00
|
|
|
getResponseMessage(socket, "error:", response, true);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command load: ", !response.empty());
|
2016-02-17 15:15:28 -06:00
|
|
|
{
|
2016-02-21 08:50:40 -06:00
|
|
|
Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tokens.count());
|
|
|
|
|
|
|
|
std::string errorCommand;
|
|
|
|
std::string errorKind;
|
|
|
|
LOOLProtocol::getTokenString(tokens[0], "cmd", errorCommand);
|
|
|
|
LOOLProtocol::getTokenString(tokens[1], "kind", errorKind);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("passwordrequired:to-view"), errorKind);
|
|
|
|
}
|
2016-02-25 03:02:35 -06:00
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-02-25 03:02:35 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-02-25 03:02:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-03 09:31:13 -06:00
|
|
|
void HTTPWSTest::testPasswordProtectedDocumentWithWrongPassword()
|
2016-02-25 03:02:35 -06:00
|
|
|
{
|
2016-03-01 02:55:06 -06:00
|
|
|
try
|
|
|
|
{
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "password-protected.ods");
|
2016-02-25 03:02:35 -06:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
2016-03-13 12:23:12 -05:00
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-02-17 15:15:28 -06:00
|
|
|
|
2016-02-25 03:02:35 -06:00
|
|
|
// Send a load request with incorrect password
|
2016-02-21 08:50:40 -06:00
|
|
|
sendTextFrame(socket, "load url=" + documentURL + " password=2");
|
2016-02-17 15:15:28 -06:00
|
|
|
|
2016-03-13 12:23:12 -05:00
|
|
|
std::string response;
|
2016-02-21 08:50:40 -06:00
|
|
|
getResponseMessage(socket, "error:", response, true);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command load: ", !response.empty());
|
|
|
|
{
|
|
|
|
Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tokens.count());
|
|
|
|
|
|
|
|
std::string errorCommand;
|
|
|
|
std::string errorKind;
|
|
|
|
LOOLProtocol::getTokenString(tokens[0], "cmd", errorCommand);
|
|
|
|
LOOLProtocol::getTokenString(tokens[1], "kind", errorKind);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("wrongpassword"), errorKind);
|
|
|
|
}
|
2016-02-25 03:02:35 -06:00
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-02-25 03:02:35 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-02-25 03:02:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-03 09:31:13 -06:00
|
|
|
void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPassword()
|
2016-02-25 03:02:35 -06:00
|
|
|
{
|
2016-03-01 02:55:06 -06:00
|
|
|
try
|
|
|
|
{
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "password-protected.ods");
|
2016-02-25 03:02:35 -06:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
2016-03-13 12:23:12 -05:00
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-02-21 08:50:40 -06:00
|
|
|
|
2016-02-25 03:02:35 -06:00
|
|
|
// Send a load request with correct password
|
2016-02-21 08:50:40 -06:00
|
|
|
sendTextFrame(socket, "load url=" + documentURL + " password=1");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL, isDocumentLoaded(socket));
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-02-19 16:22:22 -06:00
|
|
|
}
|
2016-02-21 08:50:40 -06:00
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-02-17 15:15:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-03 09:31:13 -06:00
|
|
|
void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPasswordAgain()
|
2016-03-03 09:13:57 -06:00
|
|
|
{
|
2016-03-03 09:31:13 -06:00
|
|
|
testPasswordProtectedDocumentWithCorrectPassword();
|
2016-03-03 09:13:57 -06:00
|
|
|
}
|
|
|
|
|
2016-02-20 15:13:35 -06:00
|
|
|
void HTTPWSTest::testImpressPartCountChanged()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document
|
2016-03-19 16:35:24 -05:00
|
|
|
const std::string documentPath = Util::getTempFilePath(TDOC, "insert-delete.odp");
|
2016-02-20 15:13:35 -06:00
|
|
|
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
|
|
|
|
|
2016-03-13 12:23:12 -05:00
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2016-04-08 04:24:52 -05:00
|
|
|
#ifdef ENABLE_SSL
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
|
2016-04-08 04:24:52 -05:00
|
|
|
#else
|
|
|
|
Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
|
|
|
#endif
|
2016-03-25 13:23:26 -05:00
|
|
|
Poco::Net::WebSocket socket(session, request, _response);
|
2016-03-13 12:23:12 -05:00
|
|
|
|
2016-02-20 15:13:35 -06:00
|
|
|
sendTextFrame(socket, "load url=" + documentURL);
|
|
|
|
sendTextFrame(socket, "status");
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
|
|
|
|
|
|
|
|
// check total slides 1
|
|
|
|
sendTextFrame(socket, "status");
|
2016-03-13 12:23:12 -05:00
|
|
|
|
|
|
|
std::string response;
|
2016-02-20 15:13:35 -06:00
|
|
|
getResponseMessage(socket, "status:", response, true);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command status: ", !response.empty());
|
|
|
|
{
|
|
|
|
Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count());
|
|
|
|
|
|
|
|
// Expected format is something like 'type= parts= current= width= height='.
|
|
|
|
const std::string prefix = "parts=";
|
|
|
|
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(totalParts, 1);
|
|
|
|
}
|
|
|
|
|
2016-03-03 04:13:34 -06:00
|
|
|
/* FIXME partscountchanged: was removed, update accordingly
|
2016-02-20 15:13:35 -06:00
|
|
|
// insert 10 slides
|
2016-03-01 02:55:06 -06:00
|
|
|
for (unsigned it = 1; it <= 10; it++)
|
2016-02-20 15:13:35 -06:00
|
|
|
{
|
|
|
|
sendTextFrame(socket, "uno .uno:InsertPage");
|
|
|
|
getResponseMessage(socket, "partscountchanged:", response, false);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command partscountchanged: ", !response.empty());
|
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
Poco::Dynamic::Var result = parser.parse(response);
|
|
|
|
Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
CPPUNIT_ASSERT(values["action"] == "PartInserted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete 10 slides
|
2016-03-01 02:55:06 -06:00
|
|
|
for (unsigned it = 1; it <= 10; it++)
|
2016-02-20 15:13:35 -06:00
|
|
|
{
|
|
|
|
sendTextFrame(socket, "uno .uno:DeletePage");
|
|
|
|
getResponseMessage(socket, "partscountchanged:", response, false);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command partscountchanged: ", !response.empty());
|
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
Poco::Dynamic::Var result = parser.parse(response);
|
|
|
|
Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
CPPUNIT_ASSERT(values["action"] == "PartDeleted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// undo delete slides
|
2016-03-01 02:55:06 -06:00
|
|
|
for (unsigned it = 1; it <= 10; it++)
|
2016-02-20 15:13:35 -06:00
|
|
|
{
|
|
|
|
sendTextFrame(socket, "uno .uno:Undo");
|
|
|
|
getResponseMessage(socket, "partscountchanged:", response, false);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command partscountchanged: ", !response.empty());
|
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
Poco::Dynamic::Var result = parser.parse(response);
|
|
|
|
Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
CPPUNIT_ASSERT(values["action"] == "PartInserted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// redo inserted slides
|
2016-03-01 02:55:06 -06:00
|
|
|
for (unsigned it = 1; it <= 10; it++)
|
2016-02-20 15:13:35 -06:00
|
|
|
{
|
|
|
|
sendTextFrame(socket, "uno .uno:Redo");
|
|
|
|
getResponseMessage(socket, "partscountchanged:", response, false);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("failed command partscountchanged: ", !response.empty());
|
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
Poco::Dynamic::Var result = parser.parse(response);
|
|
|
|
Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
CPPUNIT_ASSERT(values["action"] == "PartDeleted");
|
|
|
|
}
|
|
|
|
}
|
2016-03-03 04:13:34 -06:00
|
|
|
*/
|
2016-02-20 15:13:35 -06:00
|
|
|
|
|
|
|
socket.shutdown();
|
2016-04-12 13:34:25 -05:00
|
|
|
Util::removeFile(documentPath);
|
2016-02-20 15:13:35 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-02-20 15:13:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
void HTTPWSTest::sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string)
|
|
|
|
{
|
|
|
|
socket.sendFrame(string.data(), string.size());
|
|
|
|
}
|
|
|
|
|
2016-02-18 15:11:01 -06:00
|
|
|
bool HTTPWSTest::isDocumentLoaded(Poco::Net::WebSocket& ws)
|
|
|
|
{
|
|
|
|
bool isLoaded = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int bytes;
|
2016-02-25 07:58:13 -06:00
|
|
|
int retries = 30;
|
2016-02-18 15:11:01 -06:00
|
|
|
const Poco::Timespan waitTime(1000000);
|
|
|
|
|
|
|
|
ws.setReceiveTimeout(0);
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "==> isDocumentLoaded\n";
|
2016-02-18 15:11:01 -06:00
|
|
|
do
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
|
|
|
|
if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
|
|
|
|
{
|
|
|
|
bytes = ws.receiveFrame(buffer, sizeof(buffer), flags);
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
|
2016-02-22 05:48:15 -06:00
|
|
|
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
2016-02-18 15:11:01 -06:00
|
|
|
{
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << '\n';
|
2016-02-18 15:11:01 -06:00
|
|
|
const std::string line = LOOLProtocol::getFirstLine(buffer, bytes);
|
|
|
|
const std::string prefixIndicator = "statusindicatorfinish:";
|
|
|
|
const std::string prefixStatus = "status:";
|
|
|
|
if (line.find(prefixIndicator) == 0 || line.find(prefixStatus) == 0)
|
|
|
|
{
|
|
|
|
isLoaded = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-02-21 12:48:05 -06:00
|
|
|
retries = 10;
|
2016-02-18 15:11:01 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Timeout\n";
|
2016-02-18 15:11:01 -06:00
|
|
|
--retries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
}
|
|
|
|
catch (const Poco::Net::WebSocketException& exc)
|
|
|
|
{
|
|
|
|
std::cout << exc.message();
|
|
|
|
}
|
|
|
|
|
|
|
|
return isLoaded;
|
|
|
|
}
|
|
|
|
|
2016-02-20 15:13:35 -06:00
|
|
|
void HTTPWSTest::getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string& response, const bool isLine)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int bytes;
|
2016-02-25 07:57:52 -06:00
|
|
|
int retries = 20;
|
2016-02-20 15:13:35 -06:00
|
|
|
const Poco::Timespan waitTime(1000000);
|
|
|
|
|
|
|
|
response.clear();
|
|
|
|
ws.setReceiveTimeout(0);
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "==> getResponseMessage(" << prefix << ")\n";
|
2016-02-20 15:13:35 -06:00
|
|
|
do
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE];
|
|
|
|
|
|
|
|
if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
|
|
|
|
{
|
|
|
|
bytes = ws.receiveFrame(buffer, sizeof(buffer), flags);
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
|
2016-02-22 05:48:15 -06:00
|
|
|
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
2016-02-20 15:13:35 -06:00
|
|
|
{
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << '\n';
|
2016-02-20 15:13:35 -06:00
|
|
|
const std::string message = isLine ?
|
|
|
|
LOOLProtocol::getFirstLine(buffer, bytes) :
|
|
|
|
std::string(buffer, bytes);
|
|
|
|
|
|
|
|
if (message.find(prefix) == 0)
|
|
|
|
{
|
|
|
|
response = message.substr(prefix.length());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retries = 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-25 07:57:52 -06:00
|
|
|
std::cout << "Timeout\n";
|
2016-02-20 15:13:35 -06:00
|
|
|
--retries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
|
|
|
}
|
|
|
|
catch (const Poco::Net::WebSocketException& exc)
|
|
|
|
{
|
|
|
|
std::cout << exc.message();
|
|
|
|
}
|
|
|
|
}
|
2016-02-18 15:11:01 -06:00
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSTest);
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|