test: ProxyProtocol can tolerate proxying things.
Change-Id: Ib54f4d640b5e95fa9a97459203b932624c88765d Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
parent
8b665983f3
commit
17ae1f2ffe
2 changed files with 73 additions and 0 deletions
|
@ -33,6 +33,7 @@ AM_CXXFLAGS = $(CPPUNIT_CFLAGS) -DTDOC=\"$(abs_top_srcdir)/test/data\" -DTDIST=\
|
|||
# When adding new tests, please maintain order.
|
||||
all_la_unit_tests = \
|
||||
unit-perf.la \
|
||||
unit-proxy.la \
|
||||
unit-synthetic-lok.la \
|
||||
unit-wopi-async-slow.la \
|
||||
unit-tiletest.la \
|
||||
|
@ -311,6 +312,8 @@ unit_quarantine_la_SOURCES = UnitQuarantine.cpp
|
|||
unit_quarantine_la_LIBADD = $(CPPUNIT_LIBS)
|
||||
unit_perf_la_SOURCES = UnitPerf.cpp
|
||||
unit_perf_la_LIBADD = $(CPPUNIT_LIBS) $(LIBPFM_LIBS)
|
||||
unit_proxy_la_SOURCES = UnitProxy.cpp
|
||||
unit_proxy_la_LIBADD = $(CPPUNIT_LIBS) $(LIBPFM_LIBS)
|
||||
|
||||
if HAVE_LO_PATH
|
||||
SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
|
||||
|
|
70
test/UnitProxy.cpp
Normal file
70
test/UnitProxy.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* Copyright the Collabora Online contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <Common.hpp>
|
||||
#include <Protocol.hpp>
|
||||
#include <Unit.hpp>
|
||||
#include <Util.hpp>
|
||||
#include <FileUtil.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <net/HttpRequest.hpp>
|
||||
|
||||
// Inside the WSD process
|
||||
class UnitProxy : public UnitWSD
|
||||
{
|
||||
std::thread _worker;
|
||||
SocketPoll _poll;
|
||||
http::Request _req;
|
||||
bool _sentRequest;
|
||||
|
||||
public:
|
||||
UnitProxy()
|
||||
: UnitWSD("UnitProxy"),
|
||||
_poll("proxy-poll"),
|
||||
_sentRequest(false)
|
||||
{
|
||||
setTimeout(std::chrono::seconds(5));
|
||||
}
|
||||
|
||||
void invokeWSDTest() override
|
||||
{
|
||||
if (_sentRequest)
|
||||
return; // be more patient.
|
||||
_sentRequest = true;
|
||||
|
||||
auto httpSession = http::Session::create(helpers::getTestServerURI());
|
||||
|
||||
httpSession->setTimeout(std::chrono::seconds(5));
|
||||
|
||||
TST_LOG("Attempt proxy URL fetch");
|
||||
|
||||
_req = http::Request("/browser/a90f83c/foo/remote/static/lokit-extra-img.svg");
|
||||
LOK_ASSERT_EQUAL(true, httpSession->asyncRequest(_req, _poll));
|
||||
|
||||
httpSession->setFinishedHandler([&](const std::shared_ptr<http::Session>&) {
|
||||
TST_LOG("Got a valid response from the proxy");
|
||||
// any result short of server choking is fine - we may be off-line
|
||||
exitTest(TestResult::Ok);
|
||||
});
|
||||
_poll.startThread();
|
||||
}
|
||||
};
|
||||
|
||||
UnitBase *unit_create_wsd(void)
|
||||
{
|
||||
return new UnitProxy();
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
Loading…
Reference in a new issue