[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loleaflet/debug loleaflet/dist loleaflet/main.js test/UnitOAuth.cpp wsd/FileServer.cpp
Jan Holesovsky
kendy at collabora.com
Thu Aug 17 11:39:24 UTC 2017
loleaflet/debug/document/loleaflet.html | 5 ++
loleaflet/dist/loleaflet.html | 1
loleaflet/main.js | 3 +
test/UnitOAuth.cpp | 80 +++++++++++++++++++++-----------
wsd/FileServer.cpp | 6 ++
5 files changed, 67 insertions(+), 28 deletions(-)
New commits:
commit cea64133bf627fe1ee8f96c7f222f50e10aa2454
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Aug 17 11:47:14 2017 +0200
access_header: Pass the access_header around + unit test.
Change-Id: I5d6d93e289d8faceda59deae128e8124a0193d95
Reviewed-on: https://gerrit.libreoffice.org/41243
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Reviewed-by: pranavk <pranavk at collabora.co.uk>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/loleaflet/debug/document/loleaflet.html b/loleaflet/debug/document/loleaflet.html
index 33364cea..fc239f3b 100644
--- a/loleaflet/debug/document/loleaflet.html
+++ b/loleaflet/debug/document/loleaflet.html
@@ -92,9 +92,14 @@
<script>
var wopiSrc = getParameterByName('WOPISrc');
var access_token = '%ACCESS_TOKEN%';
+ var access_header = '%ACCESS_HEADER%';
if (wopiSrc !== '' && access_token !== '') {
wopiSrc += '?access_token=' + access_token;
}
+ else if (wopiSrc !== '' && access_header !== '') {
+ wopiSrc += '?access_header=' + access_header;
+ }
+
var filePath = getParameterByName('file_path');
var title = getParameterByName('title');
diff --git a/loleaflet/dist/loleaflet.html b/loleaflet/dist/loleaflet.html
index f4f5e541..13e60e54 100644
--- a/loleaflet/dist/loleaflet.html
+++ b/loleaflet/dist/loleaflet.html
@@ -91,6 +91,7 @@
window.host = '%HOST%';
window.access_token = '%ACCESS_TOKEN%';
window.access_token_ttl = '%ACCESS_TOKEN_TTL%';
+ window.access_header = '%ACCESS_HEADER%';
window.loleaflet_logging = '%LOLEAFLET_LOGGING%';
window.outOfFocusTimeoutSecs = %OUT_OF_FOCUS_TIMEOUT_SECS%;
window.idleTimeoutSecs = %IDLE_TIMEOUT_SECS%;
diff --git a/loleaflet/main.js b/loleaflet/main.js
index 48200cd9..42660a13 100644
--- a/loleaflet/main.js
+++ b/loleaflet/main.js
@@ -60,6 +60,9 @@ var wopiSrc = getParameterByName('WOPISrc');
if (wopiSrc !== '' && access_token !== '') {
var wopiParams = { 'access_token': access_token, 'access_token_ttl': access_token_ttl };
}
+else if (wopiSrc !== '' && access_header !== '') {
+ var wopiParams = { 'access_header': access_header };
+}
var filePath = getParameterByName('file_path');
var title = getParameterByName('title');
diff --git a/test/UnitOAuth.cpp b/test/UnitOAuth.cpp
index 0136d0c8..ed82982e 100644
--- a/test/UnitOAuth.cpp
+++ b/test/UnitOAuth.cpp
@@ -29,16 +29,44 @@ using Poco::Net::OAuth20Credentials;
class UnitOAuth : public UnitWSD
{
enum class Phase {
- Load, // loading the document
+ Load0, // loading the document with Bearer token
+ Load1, // loading the document with Basic auth
Polling // let the loading progress, and when it succeeds, finish
} _phase;
+ bool _finished0;
+ bool _finished1;
+
public:
UnitOAuth() :
- _phase(Phase::Load)
+ _phase(Phase::Load0),
+ _finished0(false),
+ _finished1(false)
{
}
+ void assertRequest(const Poco::Net::HTTPRequest& request, int fileIndex)
+ {
+ // check that the request contains the Authorization: header
+ try {
+ if (fileIndex == 0)
+ {
+ OAuth20Credentials creds(request);
+ CPPUNIT_ASSERT_EQUAL(std::string("s3hn3ct0k3v"), creds.getBearerToken());
+ }
+ else
+ {
+ OAuth20Credentials creds(request, "Basic");
+ CPPUNIT_ASSERT_EQUAL(std::string("basic=="), creds.getBearerToken());
+ }
+ }
+ catch (const std::exception&)
+ {
+ // fail as fast as possible
+ exit(1);
+ }
+ }
+
/// Here we act as a WOPI server, so that we have a server that responds to
/// the wopi requests without additional expensive setup.
virtual bool handleHttpRequest(const Poco::Net::HTTPRequest& request, std::shared_ptr<StreamSocket>& socket) override
@@ -49,20 +77,11 @@ public:
LOG_INF("Fake wopi host request: " << uriReq.toString());
// CheckFileInfo
- if (uriReq.getPath() == "/wopi/files/0")
+ if (uriReq.getPath() == "/wopi/files/0" || uriReq.getPath() == "/wopi/files/1")
{
- LOG_INF("Fake wopi host request, handling CheckFileInfo.");
+ LOG_INF("Fake wopi host request, handling CheckFileInfo: " << uriReq.getPath());
- // check that the request contains the Authorization: header
- try {
- OAuth20Credentials creds(request);
- CPPUNIT_ASSERT_EQUAL(creds.getBearerToken(), std::string("s3hn3ct0k3v"));
- }
- catch (const std::exception&)
- {
- // fail as fast as possible
- exit(1);
- }
+ assertRequest(request, (uriReq.getPath() == "/wopi/files/0")? 0: 1);
Poco::LocalDateTime now;
Poco::JSON::Object::Ptr fileInfo = new Poco::JSON::Object();
@@ -97,19 +116,19 @@ public:
return true;
}
// GetFile
- else if (uriReq.getPath() == "/wopi/files/0/contents")
+ else if (uriReq.getPath() == "/wopi/files/0/contents" || uriReq.getPath() == "/wopi/files/1/contents")
{
- LOG_INF("Fake wopi host request, handling GetFile.");
+ LOG_INF("Fake wopi host request, handling GetFile: " << uriReq.getPath());
- // check that the request contains the Authorization: header
- try {
- OAuth20Credentials creds(request);
- CPPUNIT_ASSERT_EQUAL(creds.getBearerToken(), std::string("s3hn3ct0k3v"));
+ if (uriReq.getPath() == "/wopi/files/0/contents")
+ {
+ assertRequest(request, 0);
+ _finished0 = true;
}
- catch (const std::exception&)
+ else
{
- // fail as fast as possible
- exit(1);
+ assertRequest(request, 1);
+ _finished1 = true;
}
const std::string mimeType = "text/plain; charset=utf-8";
@@ -126,7 +145,8 @@ public:
socket->send(oss.str());
socket->shutdown();
- exitTest(TestResult::Ok);
+ if (_finished0 && _finished1)
+ exitTest(TestResult::Ok);
return true;
}
@@ -140,9 +160,12 @@ public:
switch (_phase)
{
- case Phase::Load:
+ case Phase::Load0:
+ case Phase::Load1:
{
- Poco::URI wopiURL(helpers::getTestServerURI() + "/wopi/files/0?access_token=s3hn3ct0k3v");
+ Poco::URI wopiURL(helpers::getTestServerURI() +
+ ((_phase == Phase::Load0)? "/wopi/files/0?access_token=s3hn3ct0k3v":
+ "/wopi/files/1?access_header=Authorization: Basic basic=="));
//wopiURL.setPort(_wopiSocket->address().port());
std::string wopiSrc;
Poco::URI::encode(wopiURL.toString(), ":/?", wopiSrc);
@@ -155,7 +178,10 @@ public:
helpers::sendTextFrame(*ws->getLOOLWebSocket(), "load url=" + wopiSrc, testName);
- _phase = Phase::Polling;
+ if (_phase == Phase::Load0)
+ _phase = Phase::Load1;
+ else
+ _phase = Phase::Polling;
break;
}
case Phase::Polling:
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index c34ac9e6..8b40706d 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -336,12 +336,15 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
const std::string& accessToken = form.get("access_token", "");
const std::string& accessTokenTtl = form.get("access_token_ttl", "");
LOG_TRC("access_token=" << accessToken << ", access_token_ttl=" << accessTokenTtl);
+ const std::string& accessHeader = form.get("access_header", "");
+ LOG_TRC("access_header=" << accessHeader);
// Escape bad characters in access token.
// This is placed directly in javascript in loleaflet.html, we need to make sure
// that no one can do anything nasty with their clever inputs.
- std::string escapedAccessToken;
+ std::string escapedAccessToken, escapedAccessHeader;
Poco::URI::encode(accessToken, "'", escapedAccessToken);
+ Poco::URI::encode(accessHeader, "'", escapedAccessHeader);
unsigned long tokenTtl = 0;
if (accessToken != "")
@@ -365,6 +368,7 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN%"), escapedAccessToken);
Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN_TTL%"), std::to_string(tokenTtl));
+ Poco::replaceInPlace(preprocess, std::string("%ACCESS_HEADER%"), escapedAccessHeader);
Poco::replaceInPlace(preprocess, std::string("%HOST%"), host);
Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION_HASH));
More information about the Libreoffice-commits
mailing list