diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2020-06-20 15:12:13 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2020-07-01 07:35:00 +0200 |
commit | 5cf0273c7fcc10b85a4aeaaef20d602dd1bd1969 (patch) | |
tree | 34f7bd1a9fa2dbf61ae81138c44147686fe43232 | |
parent | wsd: Authorization parsing and creation improvements (diff) | |
download | online-5cf0273c7fcc10b85a4aeaaef20d602dd1bd1969.tar.gz online-5cf0273c7fcc10b85a4aeaaef20d602dd1bd1969.zip |
wsd: parse the URI params of the URI and DocumentURI
Change-Id: Iefc8c10ff85270aa95f255cef29b3427a0efcfe6
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96826
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | test/WhiteBoxTests.cpp | 16 | ||||
-rw-r--r-- | wsd/RequestDetails.cpp | 35 | ||||
-rw-r--r-- | wsd/RequestDetails.hpp | 3 |
3 files changed, 44 insertions, 10 deletions
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index dd32dbdd65..13a4ac5720 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -1509,6 +1509,22 @@ void WhiteBoxTests::testRequestDetails() // LOK_ASSERT_EQUAL(docUri, details.getLegacyDocumentURI()); // Broken. LOK_ASSERT_EQUAL(docUri, details.getDocumentURI()); + const std::map<std::string, std::string>& params = details.getDocumentURIParams(); + LOK_ASSERT_EQUAL(static_cast<std::size_t>(3), params.size()); + auto it = params.find("access_header"); + const std::string access_header + = "Authorization: Bearer poiuytrewq\r\n\r\nX-Requested-With: XMLHttpRequest"; + LOK_ASSERT_EQUAL(access_header, it != params.end() ? it->second : ""); + it = params.find("reuse_cookies"); + const std::string reuse_cookies + = "lang=en-us:_ga_LMX4TVJ02K=GS1.1:Token=eyJhbGciOiJIUzUxMiJ9.vajknfkfajksdljfiwjek-" + "W90fmgVb3C-00-eSkJBDqDNSYA:PublicToken=abc:ZNPCQ003-32383700=e9c71c3b:JSESSIONID=" + "node0.node0"; + LOK_ASSERT_EQUAL(reuse_cookies, it != params.end() ? it->second : ""); + it = params.find("permission"); + const std::string permission = "edit"; + LOK_ASSERT_EQUAL(permission, it != params.end() ? it->second : ""); + LOK_ASSERT_EQUAL(static_cast<std::size_t>(11), details.size()); LOK_ASSERT_EQUAL(std::string("lool"), details[0]); LOK_ASSERT(details.equals(0, "lool")); diff --git a/wsd/RequestDetails.cpp b/wsd/RequestDetails.cpp index 9caf03f294..edb5c1c8c8 100644 --- a/wsd/RequestDetails.cpp +++ b/wsd/RequestDetails.cpp @@ -15,6 +15,27 @@ #include <Poco/URI.h> #include "Exceptions.hpp" +namespace +{ + +std::map<std::string, std::string> getParams(const std::string& uri) +{ + std::map<std::string, std::string> result; + for (const auto& param : Poco::URI(uri).getQueryParameters()) + { + std::string key; + Poco::URI::decode(param.first, key); + std::string value; + Poco::URI::decode(param.second, value); + LOG_TRC("Decoding param [" << param.first << "] = [" << param.second << "] -> [" << key + << "] = [" << value << "]."); + + result.emplace(key, value); + } + + return result; +} + /// Returns true iff the two containers are equal. template <typename T> bool equal(const T& lhs, const T& rhs) { @@ -42,6 +63,7 @@ template <typename T> bool equal(const T& lhs, const T& rhs) return true; } +} RequestDetails::RequestDetails(Poco::Net::HTTPRequest &request, const std::string& serviceRoot) : _isMobile(false) @@ -86,16 +108,7 @@ RequestDetails::RequestDetails(const std::string &mobileURI) void RequestDetails::processURI() { // Poco::SyntaxException is thrown when the syntax is invalid. - Poco::URI uri(_uriString); - for (const auto& param : uri.getQueryParameters()) - { - LOG_TRC("Decoding param [" << param.first << "] = [" << param.second << "]."); - - std::string value; - Poco::URI::decode(param.second, value); - - _params.emplace(param.first, value); - } + _params = getParams(_uriString); // First tokenize by '/' then by '?'. std::vector<StringToken> tokens; @@ -169,6 +182,8 @@ void RequestDetails::processURI() _fields[Field::DocumentURI] = _uriString; } + _docUriParams = getParams(_fields[Field::DocumentURI]); + _fields[Field::WOPISrc] = getParam("WOPISrc"); // &compat= diff --git a/wsd/RequestDetails.hpp b/wsd/RequestDetails.hpp index e55f28535a..93dd4ff50f 100644 --- a/wsd/RequestDetails.hpp +++ b/wsd/RequestDetails.hpp @@ -119,6 +119,7 @@ private: StringVector _pathSegs; std::map<std::string, std::string> _params; std::map<Field, std::string> _fields; + std::map<std::string, std::string> _docUriParams; void processURI(); @@ -134,6 +135,8 @@ public: /// The DocumentURI, decoded. Doesn't contain WOPISrc or any other appendages. std::string getDocumentURI() const { return getField(Field::DocumentURI); } + const std::map<std::string, std::string>& getDocumentURIParams() const { return _docUriParams; } + std::string getURI() const { return _uriString; |