[Libreoffice-commits] online.git: 4 commits - loolwsd/Connect.cpp loolwsd/LOOLTool.cpp loolwsd/test

Jan Holesovsky kendy at collabora.com
Mon May 2 16:43:12 UTC 2016


 loolwsd/Connect.cpp                      |    1 
 loolwsd/LOOLTool.cpp                     |    1 
 loolwsd/test/UnitAdmin.cpp               |   14 +++-
 loolwsd/test/httpwstest.cpp              |   20 ++----
 loolwsd/test/integration-http-server.cpp |   89 ++++++++++---------------------
 5 files changed, 50 insertions(+), 75 deletions(-)

New commits:
commit 511b6c1039a82b2ad95f14f0bcd1d8b6332ee945
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Mon May 2 18:41:57 2016 +0200

    Reduce #ifdef ENABLE_SSL's.

diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index c0bc549..082ecdb 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -180,11 +180,7 @@ void HTTPWSTest::testBadRequest()
 
         Poco::Net::HTTPResponse response;
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
-#if ENABLE_SSL
-        Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-        Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
+        std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
         // This should result in Bad Request, but results in:
         // WebSocket Exception: Missing Sec-WebSocket-Key in handshake request
         // So Service Unavailable is returned.
@@ -194,9 +190,9 @@ void HTTPWSTest::testBadRequest()
         request.set("Sec-WebSocket-Version", "13");
         request.set("Sec-WebSocket-Key", "");
         request.setChunkedTransferEncoding(false);
-        session.setKeepAlive(true);
-        session.sendRequest(request);
-        session.receiveResponse(response);
+        session->setKeepAlive(true);
+        session->sendRequest(request);
+        session->receiveResponse(response);
         CPPUNIT_ASSERT(response.getStatus() == Poco::Net::HTTPResponse::HTTPResponse::HTTP_SERVICE_UNAVAILABLE);
     }
     catch (const Poco::Exception& exc)
@@ -218,12 +214,8 @@ void HTTPWSTest::testHandShake()
 
         Poco::Net::HTTPResponse response;
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
-#if ENABLE_SSL
-        Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-        Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
-        Poco::Net::WebSocket socket(session, request, response);
+        std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
+        Poco::Net::WebSocket socket(*session, request, response);
 
         const char* fail = "error:";
         std::string payload("statusindicator: find");
diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index 4d67757..3494aeb 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -27,6 +27,7 @@
 #include <Util.hpp>
 
 #include "countloolkits.hpp"
+#include "helpers.hpp"
 
 /// Tests the HTTP GET API of loolwsd.
 class HTTPServerTest : public CPPUNIT_NS::TestFixture
@@ -94,35 +95,27 @@ void HTTPServerTest::testCountHowManyLoolkits()
 
 void HTTPServerTest::testDiscovery()
 {
-#if ENABLE_SSL
-    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
+    std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
-    session.sendRequest(request);
+    session->sendRequest(request);
 
     Poco::Net::HTTPResponse response;
-    session.receiveResponse(response);
+    session->receiveResponse(response);
     CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
     CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
 }
 
 void HTTPServerTest::testLoleafletGet()
 {
-#if ENABLE_SSL
-    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
+    std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html?access_token=111111111");
     Poco::Net::HTMLForm param(request);
-    session.sendRequest(request);
+    session->sendRequest(request);
 
     Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
+    std::istream& rs = session->receiveResponse(response);
     CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
     CPPUNIT_ASSERT_EQUAL(std::string("text/html"), response.getContentType());
 
@@ -136,21 +129,17 @@ void HTTPServerTest::testLoleafletGet()
 
 void HTTPServerTest::testLoleafletPost()
 {
-#if ENABLE_SSL
-    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
+    std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/loleaflet/dist/loleaflet.html");
     Poco::Net::HTMLForm form;
     form.set("access_token", "2222222222");
     form.prepareSubmit(request);
-    std::ostream& ostr = session.sendRequest(request);
+    std::ostream& ostr = session->sendRequest(request);
     form.write(ostr);
 
     Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
+    std::istream& rs = session->receiveResponse(response);
     CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
 
     std::string html;
@@ -182,17 +171,13 @@ void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, c
 	    if (scriptString.find("/branding.") != std::string::npos)
 		continue;
 
-#if ENABLE_SSL
-	    Poco::Net::HTTPSClientSession sessionScript(uri.getHost(), uri.getPort());
-#else
-	    Poco::Net::HTTPClientSession sessionScript(uri.getHost(), uri.getPort());
-#endif
+            std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
 
 	    Poco::Net::HTTPRequest requestScript(Poco::Net::HTTPRequest::HTTP_GET, scriptString);
-	    sessionScript.sendRequest(requestScript);
+	    session->sendRequest(requestScript);
 
 	    Poco::Net::HTTPResponse responseScript;
-	    sessionScript.receiveResponse(responseScript);
+	    session->receiveResponse(responseScript);
 	    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseScript.getStatus());
 
 	    if (!mimetype.empty())
@@ -207,17 +192,13 @@ void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, c
 
 void HTTPServerTest::testScriptsAndLinksGet()
 {
-#if ENABLE_SSL
-    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
+    std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html");
-    session.sendRequest(request);
+    session->sendRequest(request);
 
     Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
+    std::istream& rs = session->receiveResponse(response);
     CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
 
     std::string html;
@@ -232,19 +213,15 @@ void HTTPServerTest::testScriptsAndLinksGet()
 
 void HTTPServerTest::testScriptsAndLinksPost()
 {
-#if ENABLE_SSL
-    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
-#else
-    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
-#endif
+    std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/loleaflet/dist/loleaflet.html");
     std::string body;
     request.setContentLength((int) body.length());
-    session.sendRequest(request) << body;
+    session->sendRequest(request) << body;
 
     Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
+    std::istream& rs = session->receiveResponse(response);
     CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
 
     std::string html;
commit e2be97f14aa227a4c32e13b1c73f619043b79a62
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Mon May 2 18:25:39 2016 +0200

    Centralize the server URI.

diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index fff7ad4..4d67757 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -31,6 +31,7 @@
 /// Tests the HTTP GET API of loolwsd.
 class HTTPServerTest : public CPPUNIT_NS::TestFixture
 {
+    const Poco::URI _uri;
     static int _initialLoolKitCount;
 
     CPPUNIT_TEST_SUITE(HTTPServerTest);
@@ -62,6 +63,11 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
 #if ENABLE_SSL
 public:
     HTTPServerTest()
+#if ENABLE_SSL
+        : _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
+#else
+        : _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
+#endif
     {
         Poco::Net::initializeSSL();
         // Just accept the certificate anyway for testing purposes
@@ -89,11 +95,9 @@ void HTTPServerTest::testCountHowManyLoolkits()
 void HTTPServerTest::testDiscovery()
 {
 #if ENABLE_SSL
-    Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
 #else
-    Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
 #endif
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
@@ -108,11 +112,9 @@ void HTTPServerTest::testDiscovery()
 void HTTPServerTest::testLoleafletGet()
 {
 #if ENABLE_SSL
-    Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
 #else
-    Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
 #endif
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html?access_token=111111111");
@@ -128,18 +130,16 @@ void HTTPServerTest::testLoleafletGet()
     Poco::StreamCopier::copyToString(rs, html);
 
     CPPUNIT_ASSERT(html.find(param["access_token"]) != std::string::npos);
-    CPPUNIT_ASSERT(html.find(uri.getHost()) != std::string::npos);
+    CPPUNIT_ASSERT(html.find(_uri.getHost()) != std::string::npos);
     CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
 }
 
 void HTTPServerTest::testLoleafletPost()
 {
 #if ENABLE_SSL
-    Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
 #else
-    Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
 #endif
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/loleaflet/dist/loleaflet.html");
@@ -157,7 +157,7 @@ void HTTPServerTest::testLoleafletPost()
     Poco::StreamCopier::copyToString(rs, html);
 
     CPPUNIT_ASSERT(html.find(form["access_token"]) != std::string::npos);
-    CPPUNIT_ASSERT(html.find(uri.getHost()) != std::string::npos);
+    CPPUNIT_ASSERT(html.find(_uri.getHost()) != std::string::npos);
     CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
 }
 
@@ -208,11 +208,9 @@ void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, c
 void HTTPServerTest::testScriptsAndLinksGet()
 {
 #if ENABLE_SSL
-    Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
 #else
-    Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
 #endif
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html");
@@ -226,20 +224,18 @@ void HTTPServerTest::testScriptsAndLinksGet()
     Poco::StreamCopier::copyToString(rs, html);
 
     Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
-    assertHTTPFilesExist(uri, script, html, "application/javascript");
+    assertHTTPFilesExist(_uri, script, html, "application/javascript");
 
     Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
-    assertHTTPFilesExist(uri, link, html);
+    assertHTTPFilesExist(_uri, link, html);
 }
 
 void HTTPServerTest::testScriptsAndLinksPost()
 {
 #if ENABLE_SSL
-    Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
 #else
-    Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
-    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+    Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
 #endif
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/loleaflet/dist/loleaflet.html");
@@ -255,10 +251,10 @@ void HTTPServerTest::testScriptsAndLinksPost()
     Poco::StreamCopier::copyToString(rs, html);
 
     Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
-    assertHTTPFilesExist(uri, script, html, "application/javascript");
+    assertHTTPFilesExist(_uri, script, html, "application/javascript");
 
     Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
-    assertHTTPFilesExist(uri, link, html);
+    assertHTTPFilesExist(_uri, link, html);
 }
 
 void HTTPServerTest::testNoExtraLoolKitsLeft()
commit c3cb14d2585925c6d89cbcc0c39d1d4c8a5bee89
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Mon May 2 18:19:08 2016 +0200

    Centralize the server URI.

diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 2383fd1..d0eb2b9 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -195,7 +195,7 @@ private:
         const std::string documentURL1 = "file://" + Poco::Path(documentPath1).makeAbsolute().toString();
         HTTPRequest request1(HTTPRequest::HTTP_GET, documentURL1);
         HTTPResponse response1;
-        const Poco::URI docUri1("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
+        const Poco::URI docUri1(getServerURI());
         const std::string loadMessage1 = "load url=" + documentURL1;
         std::unique_ptr<HTTPClientSession> session1(helpers::createSession(docUri1));
         std::unique_ptr<HTTPClientSession> session2(helpers::createSession(docUri1));
@@ -265,7 +265,7 @@ private:
         const std::string documentURL2 = "file://" + Poco::Path(documentPath2).makeAbsolute().toString();
         HTTPRequest request2(HTTPRequest::HTTP_GET, documentURL2);
         HTTPResponse response2;
-        const Poco::URI docUri2("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
+        const Poco::URI docUri2(getServerURI());
         const std::string loadMessage2 = "load url=" + documentURL2;
         std::unique_ptr<HTTPClientSession> session3(helpers::createSession(docUri1));
         _docWs3 = std::make_shared<Poco::Net::WebSocket>(*session3, request2, response2);
@@ -390,10 +390,18 @@ private:
         return TestResult::TEST_OK;
     }
 
+    std::string getServerURI()
+    {
+#if ENABLE_SSL
+        return "https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER);
+#else
+        return "http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER);
+#endif
+    }
 
 public:
     UnitAdmin()
-        : _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/loleaflet/dist/admin/admin.html")
+        : _uri(getServerURI() + "/loleaflet/dist/admin/admin.html")
     {
         // Register tests here.
         _tests.push_back(&UnitAdmin::testIncorrectPassword);
commit a27a22b56379e03ab68caf79e8de0ab4481b8156
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Mon May 2 18:03:09 2016 +0200

    Add purpose comments.

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index e1255bf..0dc064a 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -132,6 +132,7 @@ public:
     WebSocket& _ws;
 };
 
+/** Program for interactive or scripted testing of a lool server. */
 class Connect: public Poco::Util::Application
 {
 public:
diff --git a/loolwsd/LOOLTool.cpp b/loolwsd/LOOLTool.cpp
index 7429ed2..fbcaf78 100644
--- a/loolwsd/LOOLTool.cpp
+++ b/loolwsd/LOOLTool.cpp
@@ -46,6 +46,7 @@
 #include <Poco/Util/Application.h>
 #include <Poco/Util/OptionSet.h>
 
+/** Simple command-line tool for file format conversion. */
 class Tool: public Poco::Util::Application
 {
 public:


More information about the Libreoffice-commits mailing list