summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-10-26 10:38:57 +0200
committerJan Holesovsky <kendy@collabora.com>2017-10-26 11:11:38 +0200
commit343c5bc69083c844b7896d7a62b40a44d8b06b03 (patch)
tree77d6aa772a8b205239b66d507646e9b8d65b8c97
parenta98727b536bc5232f1a78a8147034529f6c483ac (diff)
tdf#99744 SaveAs: Extend test to check that the Save As result was sent.
Change-Id: I3788b87d2599c01000af97f496ee2b840c0cae3e
-rw-r--r--common/Unit.hpp10
-rw-r--r--kit/Kit.cpp2
-rw-r--r--net/Socket.hpp15
-rw-r--r--net/WebSocketHandler.hpp25
-rw-r--r--test/UnitWOPISaveAs.cpp13
-rw-r--r--wsd/LOOLWSD.cpp4
6 files changed, 46 insertions, 23 deletions
diff --git a/common/Unit.hpp b/common/Unit.hpp
index 9885d0730..97db1c39c 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -15,7 +15,7 @@
#include <string>
#include <LOOLWebSocket.hpp>
-#include "net/WebSocketHandler.hpp"
+#include "net/Socket.hpp"
class UnitBase;
class UnitWSD;
@@ -24,6 +24,8 @@ class UnitTimeout;
class UnitHTTPServerRequest;
class UnitHTTPServerResponse;
+class WebSocketHandler;
+
// Forward declaration to avoid pulling the world here.
namespace Poco
{
@@ -95,6 +97,12 @@ public:
return false;
}
+ /// Message that is about to be sent via the websocket.
+ virtual bool filterSendMessage(const char* /* data */, const size_t /* len */, const WSOpCode /* code */, const bool /* flush */, int& /*unitReturn*/)
+ {
+ return false;
+ }
+
/// Hook the disk space check
virtual bool filterCheckDiskSpace(const std::string & /* path */,
bool & /* newResult */)
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 34aed6a1b..665ab3af4 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -1618,7 +1618,7 @@ private:
vect.assign(data, data + size);
// TODO loolnb - this is probably wrong...
- session->handleMessage(/* fin = */ false, WebSocketHandler::WSOpCode::Binary, vect);
+ session->handleMessage(/* fin = */ false, WSOpCode::Binary, vect);
return true;
}
}
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 62a743b5f..0b6af5044 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -983,6 +983,21 @@ protected:
friend class SimpleResponseClient;
};
+enum class WSOpCode : unsigned char {
+ Continuation = 0x0,
+ Text = 0x1,
+ Binary = 0x2,
+ Reserved1 = 0x3,
+ Reserved2 = 0x4,
+ Reserved3 = 0x5,
+ Reserved4 = 0x6,
+ Reserved5 = 0x7,
+ Close = 0x8,
+ Ping = 0x9,
+ Pong = 0xa
+ // ... reserved
+};
+
namespace HttpHelper
{
/// Sends file as HTTP response.
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 383f1139e..cae461bcf 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -16,6 +16,7 @@
#include "common/Common.hpp"
#include "common/Log.hpp"
+#include "common/Unit.hpp"
#include "Socket.hpp"
#include <Poco/Net/HTTPRequest.h>
@@ -72,21 +73,6 @@ public:
LOG_TRC("#" << socket->getFD() << " Connected to WS Handler 0x" << std::hex << this << std::dec);
}
- enum WSOpCode {
- Continuation, // 0x0
- Text, // 0x1
- Binary, // 0x2
- Reserved1, // 0x3
- Reserved2, // 0x4
- Reserved3, // 0x5
- Reserved4, // 0x6
- Reserved5, // 0x7
- Close, // 0x8
- Ping, // 0x9
- Pong // 0xa
- // ... reserved
- };
-
/// Status codes sent to peer on shutdown.
enum class StatusCodes : unsigned short
{
@@ -204,7 +190,7 @@ public:
socket->_inBuffer.erase(socket->_inBuffer.begin(), socket->_inBuffer.begin() + headerLen + payloadLen);
// FIXME: fin, aggregating payloads into _wsPayload etc.
- LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " << code <<
+ LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " << static_cast<unsigned>(code) <<
", fin? " << fin << ", mask? " << hasMask << ", payload length: " << _wsPayload.size() <<
", residual socket data: " << socket->_inBuffer.size() << " bytes.");
@@ -329,11 +315,14 @@ public:
/// 0 for closed/invalid socket, and -1 for other errors.
int sendMessage(const char* data, const size_t len, const WSOpCode code, const bool flush = true) const
{
+ int unitReturn = -1;
+ if (UnitWSD::get().filterSendMessage(data, len, code, flush, unitReturn))
+ return unitReturn;
+
//TODO: Support fragmented messages.
- static const unsigned char Fin = static_cast<unsigned char>(WSFrameMask::Fin);
auto socket = _socket.lock();
- return sendFrame(socket, data, len, static_cast<unsigned char>(Fin | code), flush);
+ return sendFrame(socket, data, len, static_cast<unsigned char>(WSFrameMask::Fin) | static_cast<unsigned char>(code), flush);
}
protected:
diff --git a/test/UnitWOPISaveAs.cpp b/test/UnitWOPISaveAs.cpp
index cb9ff9c3e..a0c5c3df0 100644
--- a/test/UnitWOPISaveAs.cpp
+++ b/test/UnitWOPISaveAs.cpp
@@ -35,8 +35,19 @@ public:
{
// spec says UTF-7...
CPPUNIT_ASSERT_EQUAL(std::string("/jan/hole+AWE-ovsk+AP0-/hello world.txt"), request.get("X-WOPI-SuggestedTarget"));
+ }
+
+ bool filterSendMessage(const char* data, const size_t len, const WSOpCode /* code */, const bool /* flush */, int& /*unitReturn*/) override
+ {
+ std::string message(data, len);
+ if (message == "saveas: url=https://127.0.0.1:9980/something%20wopi/files/1?access_token=anything filename=hello%20world.txt")
+ {
+ // successfully exit the test if we also got the outgoing message
+ // notifying about saving the file
+ exitTest(TestResult::Ok);
+ }
- exitTest(TestResult::Ok);
+ return false;
}
void invokeTest() override
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index f1e4c800e..879d206f2 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2012,7 +2012,7 @@ private:
URI::encode(docBroker->getPublicUri().getPath(), "", encodedFrom);
const std::string load = "load url=" + encodedFrom;
std::vector<char> loadRequest(load.begin(), load.end());
- clientSession->handleMessage(true, WebSocketHandler::WSOpCode::Text, loadRequest);
+ clientSession->handleMessage(true, WSOpCode::Text, loadRequest);
// FIXME: Check for security violations.
Path toPath(docBroker->getPublicUri().getPath());
@@ -2024,7 +2024,7 @@ private:
// Convert it to the requested format.
const auto saveas = "saveas url=" + encodedTo + " format=" + format + " options=";
std::vector<char> saveasRequest(saveas.begin(), saveas.end());
- clientSession->handleMessage(true, WebSocketHandler::WSOpCode::Text, saveasRequest);
+ clientSession->handleMessage(true, WSOpCode::Text, saveasRequest);
});
});