[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - test/UnitOAuth.cpp test/WhiteBoxTests.cpp wsd/Auth.hpp
Jan Holesovsky
kendy at collabora.com
Thu Aug 17 12:09:11 UTC 2017
test/UnitOAuth.cpp | 35 ++++++++++++++++++-----------------
test/WhiteBoxTests.cpp | 18 +++++++++---------
wsd/Auth.hpp | 6 ++++--
3 files changed, 31 insertions(+), 28 deletions(-)
New commits:
commit d9a11d1bc9327de637b8b3432eacab2097e0c55b
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Aug 17 14:05:22 2017 +0200
Fix various nitpicks.
Change-Id: I41fe795bc1ea7c73527c7e1183de7098517bad7a
Reviewed-on: https://gerrit.libreoffice.org/41251
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
diff --git a/test/UnitOAuth.cpp b/test/UnitOAuth.cpp
index ed82982e..7a52c1ee 100644
--- a/test/UnitOAuth.cpp
+++ b/test/UnitOAuth.cpp
@@ -28,20 +28,21 @@ using Poco::Net::OAuth20Credentials;
class UnitOAuth : public UnitWSD
{
- enum class Phase {
- Load0, // loading the document with Bearer token
- Load1, // loading the document with Basic auth
- Polling // let the loading progress, and when it succeeds, finish
+ enum class Phase
+ {
+ LoadToken, // loading the document with Bearer token
+ LoadHeader, // loading the document with Basic auth
+ Polling // let the loading progress, and when it succeeds, finish
} _phase;
- bool _finished0;
- bool _finished1;
+ bool _finishedToken;
+ bool _finishedHeader;
public:
UnitOAuth() :
- _phase(Phase::Load0),
- _finished0(false),
- _finished1(false)
+ _phase(Phase::LoadToken),
+ _finishedToken(false),
+ _finishedHeader(false)
{
}
@@ -123,12 +124,12 @@ public:
if (uriReq.getPath() == "/wopi/files/0/contents")
{
assertRequest(request, 0);
- _finished0 = true;
+ _finishedToken = true;
}
else
{
assertRequest(request, 1);
- _finished1 = true;
+ _finishedHeader = true;
}
const std::string mimeType = "text/plain; charset=utf-8";
@@ -145,7 +146,7 @@ public:
socket->send(oss.str());
socket->shutdown();
- if (_finished0 && _finished1)
+ if (_finishedToken && _finishedHeader)
exitTest(TestResult::Ok);
return true;
@@ -160,11 +161,11 @@ public:
switch (_phase)
{
- case Phase::Load0:
- case Phase::Load1:
+ case Phase::LoadToken:
+ case Phase::LoadHeader:
{
Poco::URI wopiURL(helpers::getTestServerURI() +
- ((_phase == Phase::Load0)? "/wopi/files/0?access_token=s3hn3ct0k3v":
+ ((_phase == Phase::LoadToken)? "/wopi/files/0?access_token=s3hn3ct0k3v":
"/wopi/files/1?access_header=Authorization: Basic basic=="));
//wopiURL.setPort(_wopiSocket->address().port());
std::string wopiSrc;
@@ -178,8 +179,8 @@ public:
helpers::sendTextFrame(*ws->getLOOLWebSocket(), "load url=" + wopiSrc, testName);
- if (_phase == Phase::Load0)
- _phase = Phase::Load1;
+ if (_phase == Phase::LoadToken)
+ _phase = Phase::LoadHeader;
else
_phase = Phase::Polling;
break;
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index 07c630b8..0565dac4 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -406,15 +406,15 @@ void WhiteBoxTests::testAuthorization()
Authorization auth1(Authorization::Type::Token, "abc");
Poco::URI uri1("http://localhost");
auth1.authorizeURI(uri1);
- CPPUNIT_ASSERT_EQUAL(uri1.toString(), std::string("http://localhost/?access_token=abc"));
+ CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/?access_token=abc"), uri1.toString());
Poco::Net::HTTPRequest req1;
auth1.authorizeRequest(req1);
- CPPUNIT_ASSERT_EQUAL(req1.get("Authorization"), std::string("Bearer abc"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Bearer abc"), req1.get("Authorization"));
Authorization auth1modify(Authorization::Type::Token, "modified");
// still the same uri1, currently "http://localhost/?access_token=abc"
auth1modify.authorizeURI(uri1);
- CPPUNIT_ASSERT_EQUAL(uri1.toString(), std::string("http://localhost/?access_token=modified"));
+ CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/?access_token=modified"), uri1.toString());
Authorization auth2(Authorization::Type::Header, "def");
Poco::Net::HTTPRequest req2;
@@ -425,22 +425,22 @@ void WhiteBoxTests::testAuthorization()
Poco::URI uri2("http://localhost");
auth3.authorizeURI(uri2);
// nothing added with the Authorization header approach
- CPPUNIT_ASSERT_EQUAL(uri2.toString(), std::string("http://localhost"));
+ CPPUNIT_ASSERT_EQUAL(std::string("http://localhost"), uri2.toString());
Poco::Net::HTTPRequest req3;
auth3.authorizeRequest(req3);
- CPPUNIT_ASSERT_EQUAL(req3.get("Authorization"), std::string("Basic huhu=="));
+ CPPUNIT_ASSERT_EQUAL(std::string("Basic huhu=="), req3.get("Authorization"));
Authorization auth4(Authorization::Type::Header, " Authorization: Basic blah== \n\r X-Something: additional ");
Poco::Net::HTTPRequest req4;
auth4.authorizeRequest(req4);
- CPPUNIT_ASSERT_EQUAL(req4.get("Authorization"), std::string("Basic blah=="));
- CPPUNIT_ASSERT_EQUAL(req4.get("X-Something"), std::string("additional"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Basic blah=="), req4.get("Authorization"));
+ CPPUNIT_ASSERT_EQUAL(std::string("additional"), req4.get("X-Something"));
Authorization auth5(Authorization::Type::Header, " Authorization: Basic huh== \n\r X-Something-More: else \n\r");
Poco::Net::HTTPRequest req5;
auth5.authorizeRequest(req5);
- CPPUNIT_ASSERT_EQUAL(req5.get("Authorization"), std::string("Basic huh=="));
- CPPUNIT_ASSERT_EQUAL(req5.get("X-Something-More"), std::string("else"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Basic huh=="), req5.get("Authorization"));
+ CPPUNIT_ASSERT_EQUAL(std::string("else"), req5.get("X-Something-More"));
}
CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests);
diff --git a/wsd/Auth.hpp b/wsd/Auth.hpp
index de41aeb6..98c0a2ce 100644
--- a/wsd/Auth.hpp
+++ b/wsd/Auth.hpp
@@ -23,7 +23,8 @@
class Authorization
{
public:
- enum class Type {
+ enum class Type
+ {
None,
Token,
Header
@@ -73,7 +74,8 @@ public:
_aud(aud),
_key(Poco::Crypto::RSAKey("", keyPath)),
_digestEngine(_key, "SHA256")
- { }
+ {
+ }
const std::string getAccessToken() override;
More information about the Libreoffice-commits
mailing list