summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-08-17 11:47:14 +0200
committerJan Holesovsky <kendy@collabora.com>2017-08-17 13:41:07 +0200
commitf8ca17278f8d1114e37e656025bbf0bac2d59cc7 (patch)
tree4b35449970721337046dc3f1ae681ed7ad11d274 /test
parentafcfac4bef95cf7800effbc90818a0bfb8b434c2 (diff)
access_header: Pass the access_header around + unit test.
Change-Id: I5d6d93e289d8faceda59deae128e8124a0193d95 Reviewed-on: https://gerrit.libreoffice.org/41243 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Reviewed-by: pranavk <pranavk@collabora.co.uk> Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'test')
-rw-r--r--test/UnitOAuth.cpp80
1 files changed, 53 insertions, 27 deletions
diff --git a/test/UnitOAuth.cpp b/test/UnitOAuth.cpp
index 0136d0c81..ed82982e7 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: