mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 02:06:04 +02:00
fix tests on macOS
This commit is contained in:
@@ -51,7 +51,7 @@ public:
|
|||||||
TestRequestHandler()
|
TestRequestHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||||
{
|
{
|
||||||
response.setChunkedTransferEncoding(true);
|
response.setChunkedTransferEncoding(true);
|
||||||
@@ -90,7 +90,7 @@ HTTPSClientSessionTest::~HTTPSClientSessionTest()
|
|||||||
void HTTPSClientSessionTest::testGetSmall()
|
void HTTPSClientSessionTest::testGetSmall()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/small");
|
HTTPRequest request(HTTPRequest::HTTP_GET, "/small");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
@@ -106,7 +106,7 @@ void HTTPSClientSessionTest::testGetSmall()
|
|||||||
void HTTPSClientSessionTest::testGetLarge()
|
void HTTPSClientSessionTest::testGetLarge()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
@@ -122,7 +122,7 @@ void HTTPSClientSessionTest::testGetLarge()
|
|||||||
void HTTPSClientSessionTest::testHead()
|
void HTTPSClientSessionTest::testHead()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large");
|
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
@@ -137,7 +137,7 @@ void HTTPSClientSessionTest::testHead()
|
|||||||
void HTTPSClientSessionTest::testPostSmallIdentity()
|
void HTTPSClientSessionTest::testPostSmallIdentity()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||||
std::string body("this is a random request body\r\n0\r\n");
|
std::string body("this is a random request body\r\n0\r\n");
|
||||||
request.setContentLength((int) body.length());
|
request.setContentLength((int) body.length());
|
||||||
@@ -154,7 +154,7 @@ void HTTPSClientSessionTest::testPostSmallIdentity()
|
|||||||
void HTTPSClientSessionTest::testPostLargeIdentity()
|
void HTTPSClientSessionTest::testPostLargeIdentity()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||||
std::string body(8000, 'x');
|
std::string body(8000, 'x');
|
||||||
body.append("\r\n0\r\n");
|
body.append("\r\n0\r\n");
|
||||||
@@ -172,7 +172,7 @@ void HTTPSClientSessionTest::testPostLargeIdentity()
|
|||||||
void HTTPSClientSessionTest::testPostSmallChunked()
|
void HTTPSClientSessionTest::testPostSmallChunked()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||||
std::string body("this is a random request body");
|
std::string body("this is a random request body");
|
||||||
request.setChunkedTransferEncoding(true);
|
request.setChunkedTransferEncoding(true);
|
||||||
@@ -190,7 +190,7 @@ void HTTPSClientSessionTest::testPostSmallChunked()
|
|||||||
void HTTPSClientSessionTest::testPostLargeChunked()
|
void HTTPSClientSessionTest::testPostLargeChunked()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||||
std::string body(16000, 'x');
|
std::string body(16000, 'x');
|
||||||
request.setChunkedTransferEncoding(true);
|
request.setChunkedTransferEncoding(true);
|
||||||
@@ -212,7 +212,7 @@ void HTTPSClientSessionTest::testPostLargeChunkedKeepAlive()
|
|||||||
srv.start();
|
srv.start();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
s.setKeepAlive(true);
|
s.setKeepAlive(true);
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
@@ -241,7 +241,7 @@ void HTTPSClientSessionTest::testPostLargeChunkedKeepAlive()
|
|||||||
void HTTPSClientSessionTest::testKeepAlive()
|
void HTTPSClientSessionTest::testKeepAlive()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
s.setKeepAlive(true);
|
s.setKeepAlive(true);
|
||||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/keepAlive", HTTPMessage::HTTP_1_1);
|
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/keepAlive", HTTPMessage::HTTP_1_1);
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
@@ -252,7 +252,7 @@ void HTTPSClientSessionTest::testKeepAlive()
|
|||||||
assert (response.getKeepAlive());
|
assert (response.getKeepAlive());
|
||||||
std::ostringstream ostr1;
|
std::ostringstream ostr1;
|
||||||
assert (StreamCopier::copyStream(rs1, ostr1) == 0);
|
assert (StreamCopier::copyStream(rs1, ostr1) == 0);
|
||||||
|
|
||||||
request.setMethod(HTTPRequest::HTTP_GET);
|
request.setMethod(HTTPRequest::HTTP_GET);
|
||||||
request.setURI("/small");
|
request.setURI("/small");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
@@ -262,7 +262,7 @@ void HTTPSClientSessionTest::testKeepAlive()
|
|||||||
std::ostringstream ostr2;
|
std::ostringstream ostr2;
|
||||||
StreamCopier::copyStream(rs2, ostr2);
|
StreamCopier::copyStream(rs2, ostr2);
|
||||||
assert (ostr2.str() == HTTPSTestServer::SMALL_BODY);
|
assert (ostr2.str() == HTTPSTestServer::SMALL_BODY);
|
||||||
|
|
||||||
request.setMethod(HTTPRequest::HTTP_GET);
|
request.setMethod(HTTPRequest::HTTP_GET);
|
||||||
request.setURI("/large");
|
request.setURI("/large");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
@@ -307,7 +307,7 @@ void HTTPSClientSessionTest::testProxy()
|
|||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("secure.appinf.com");
|
HTTPSClientSession s("secure.appinf.com");
|
||||||
s.setProxy(
|
s.setProxy(
|
||||||
Application::instance().config().getString("testsuite.proxy.host"),
|
Application::instance().config().getString("testsuite.proxy.host"),
|
||||||
Application::instance().config().getInt("testsuite.proxy.port")
|
Application::instance().config().getInt("testsuite.proxy.port")
|
||||||
);
|
);
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/public/poco/NetSSL.txt");
|
HTTPRequest request(HTTPRequest::HTTP_GET, "/public/poco/NetSSL.txt");
|
||||||
@@ -328,16 +328,16 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
// ensure OpenSSL machinery is fully setup
|
// ensure OpenSSL machinery is fully setup
|
||||||
Context::Ptr pDefaultServerContext = SSLManager::instance().defaultServerContext();
|
Context::Ptr pDefaultServerContext = SSLManager::instance().defaultServerContext();
|
||||||
Context::Ptr pDefaultClientContext = SSLManager::instance().defaultClientContext();
|
Context::Ptr pDefaultClientContext = SSLManager::instance().defaultClientContext();
|
||||||
|
|
||||||
Context::Ptr pServerContext = new Context(
|
Context::Ptr pServerContext = new Context(
|
||||||
Context::SERVER_USE,
|
Context::SERVER_USE,
|
||||||
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.server.caConfig"),
|
Application::instance().config().getString("openSSL.server.caConfig"),
|
||||||
Context::VERIFY_NONE,
|
Context::VERIFY_NONE,
|
||||||
9,
|
9,
|
||||||
true,
|
true,
|
||||||
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||||
pServerContext->enableSessionCache(true, "TestSuite");
|
pServerContext->enableSessionCache(true, "TestSuite");
|
||||||
pServerContext->setSessionTimeout(10);
|
pServerContext->setSessionTimeout(10);
|
||||||
pServerContext->setSessionCacheSize(1000);
|
pServerContext->setSessionCacheSize(1000);
|
||||||
@@ -346,7 +346,7 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
HTTPSTestServer srv(pServerContext);
|
HTTPSTestServer srv(pServerContext);
|
||||||
|
|
||||||
Context::Ptr pClientContext = new Context(
|
Context::Ptr pClientContext = new Context(
|
||||||
Context::CLIENT_USE,
|
Context::CLIENT_USE,
|
||||||
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.client.caConfig"),
|
Application::instance().config().getString("openSSL.client.caConfig"),
|
||||||
@@ -356,7 +356,7 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||||
pClientContext->enableSessionCache(true);
|
pClientContext->enableSessionCache(true);
|
||||||
|
|
||||||
HTTPSClientSession s1("localhost", srv.port(), pClientContext);
|
HTTPSClientSession s1("127.0.0.1", srv.port(), pClientContext);
|
||||||
HTTPRequest request1(HTTPRequest::HTTP_GET, "/small");
|
HTTPRequest request1(HTTPRequest::HTTP_GET, "/small");
|
||||||
s1.sendRequest(request1);
|
s1.sendRequest(request1);
|
||||||
Session::Ptr pSession1 = s1.sslSession();
|
Session::Ptr pSession1 = s1.sslSession();
|
||||||
@@ -368,7 +368,7 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
StreamCopier::copyStream(rs1, ostr1);
|
StreamCopier::copyStream(rs1, ostr1);
|
||||||
assert (ostr1.str() == HTTPSTestServer::SMALL_BODY);
|
assert (ostr1.str() == HTTPSTestServer::SMALL_BODY);
|
||||||
|
|
||||||
HTTPSClientSession s2("localhost", srv.port(), pClientContext, pSession1);
|
HTTPSClientSession s2("127.0.0.1", srv.port(), pClientContext, pSession1);
|
||||||
HTTPRequest request2(HTTPRequest::HTTP_GET, "/small");
|
HTTPRequest request2(HTTPRequest::HTTP_GET, "/small");
|
||||||
s2.sendRequest(request2);
|
s2.sendRequest(request2);
|
||||||
Session::Ptr pSession2 = s2.sslSession();
|
Session::Ptr pSession2 = s2.sslSession();
|
||||||
@@ -379,7 +379,7 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
std::ostringstream ostr2;
|
std::ostringstream ostr2;
|
||||||
StreamCopier::copyStream(rs2, ostr2);
|
StreamCopier::copyStream(rs2, ostr2);
|
||||||
assert (ostr2.str() == HTTPSTestServer::SMALL_BODY);
|
assert (ostr2.str() == HTTPSTestServer::SMALL_BODY);
|
||||||
|
|
||||||
assert (pSession1 == pSession2);
|
assert (pSession1 == pSession2);
|
||||||
|
|
||||||
HTTPRequest request3(HTTPRequest::HTTP_GET, "/small");
|
HTTPRequest request3(HTTPRequest::HTTP_GET, "/small");
|
||||||
@@ -397,7 +397,7 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
|
|
||||||
Thread::sleep(15000); // wait for session to expire
|
Thread::sleep(15000); // wait for session to expire
|
||||||
pServerContext->flushSessionCache();
|
pServerContext->flushSessionCache();
|
||||||
|
|
||||||
HTTPRequest request4(HTTPRequest::HTTP_GET, "/small");
|
HTTPRequest request4(HTTPRequest::HTTP_GET, "/small");
|
||||||
s2.sendRequest(request4);
|
s2.sendRequest(request4);
|
||||||
Session::Ptr pSession4 = s2.sslSession();
|
Session::Ptr pSession4 = s2.sslSession();
|
||||||
@@ -416,7 +416,7 @@ void HTTPSClientSessionTest::testCachedSession()
|
|||||||
void HTTPSClientSessionTest::testUnknownContentLength()
|
void HTTPSClientSessionTest::testUnknownContentLength()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/nolength");
|
HTTPRequest request(HTTPRequest::HTTP_GET, "/nolength");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
@@ -432,7 +432,7 @@ void HTTPSClientSessionTest::testUnknownContentLength()
|
|||||||
void HTTPSClientSessionTest::testServerAbort()
|
void HTTPSClientSessionTest::testServerAbort()
|
||||||
{
|
{
|
||||||
HTTPSTestServer srv;
|
HTTPSTestServer srv;
|
||||||
HTTPSClientSession s("localhost", srv.port());
|
HTTPSClientSession s("127.0.0.1", srv.port());
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/nolength/connection/abort");
|
HTTPRequest request(HTTPRequest::HTTP_GET, "/nolength/connection/abort");
|
||||||
s.sendRequest(request);
|
s.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
|
|||||||
@@ -50,15 +50,15 @@ namespace
|
|||||||
response.setChunkedTransferEncoding(true);
|
response.setChunkedTransferEncoding(true);
|
||||||
else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
|
else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
|
||||||
response.setContentLength(request.getContentLength());
|
response.setContentLength(request.getContentLength());
|
||||||
|
|
||||||
response.setContentType(request.getContentType());
|
response.setContentType(request.getContentType());
|
||||||
|
|
||||||
std::istream& istr = request.stream();
|
std::istream& istr = request.stream();
|
||||||
std::ostream& ostr = response.send();
|
std::ostream& ostr = response.send();
|
||||||
StreamCopier::copyStream(istr, ostr);
|
StreamCopier::copyStream(istr, ostr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class EchoHeaderRequestHandler: public HTTPRequestHandler
|
class EchoHeaderRequestHandler: public HTTPRequestHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -92,7 +92,7 @@ namespace
|
|||||||
response.send();
|
response.send();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class RequestHandlerFactory: public HTTPRequestHandlerFactory
|
class RequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -130,8 +130,8 @@ void HTTPSServerTest::testIdentityRequest()
|
|||||||
pParams->setKeepAlive(false);
|
pParams->setKeepAlive(false);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
std::string body(5000, 'x');
|
std::string body(5000, 'x');
|
||||||
HTTPRequest request("POST", "/echoBody");
|
HTTPRequest request("POST", "/echoBody");
|
||||||
request.setContentLength((int) body.length());
|
request.setContentLength((int) body.length());
|
||||||
@@ -153,8 +153,8 @@ void HTTPSServerTest::testChunkedRequest()
|
|||||||
pParams->setKeepAlive(false);
|
pParams->setKeepAlive(false);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
std::string body(5000, 'x');
|
std::string body(5000, 'x');
|
||||||
HTTPRequest request("POST", "/echoBody");
|
HTTPRequest request("POST", "/echoBody");
|
||||||
request.setContentType("text/plain");
|
request.setContentType("text/plain");
|
||||||
@@ -177,8 +177,8 @@ void HTTPSServerTest::testIdentityRequestKeepAlive()
|
|||||||
pParams->setKeepAlive(true);
|
pParams->setKeepAlive(true);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
cs.setKeepAlive(true);
|
cs.setKeepAlive(true);
|
||||||
std::string body(5000, 'x');
|
std::string body(5000, 'x');
|
||||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||||
@@ -192,7 +192,7 @@ void HTTPSServerTest::testIdentityRequestKeepAlive()
|
|||||||
assert (response.getContentType() == "text/plain");
|
assert (response.getContentType() == "text/plain");
|
||||||
assert (response.getKeepAlive());
|
assert (response.getKeepAlive());
|
||||||
assert (rbody == body);
|
assert (rbody == body);
|
||||||
|
|
||||||
body.assign(1000, 'y');
|
body.assign(1000, 'y');
|
||||||
request.setContentLength((int) body.length());
|
request.setContentLength((int) body.length());
|
||||||
request.setKeepAlive(false);
|
request.setKeepAlive(false);
|
||||||
@@ -211,8 +211,8 @@ void HTTPSServerTest::testChunkedRequestKeepAlive()
|
|||||||
pParams->setKeepAlive(true);
|
pParams->setKeepAlive(true);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
cs.setKeepAlive(true);
|
cs.setKeepAlive(true);
|
||||||
std::string body(5000, 'x');
|
std::string body(5000, 'x');
|
||||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||||
@@ -246,8 +246,8 @@ void HTTPSServerTest::test100Continue()
|
|||||||
pParams->setKeepAlive(false);
|
pParams->setKeepAlive(false);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
std::string body(5000, 'x');
|
std::string body(5000, 'x');
|
||||||
HTTPRequest request("POST", "/echoBody");
|
HTTPRequest request("POST", "/echoBody");
|
||||||
request.setContentLength((int) body.length());
|
request.setContentLength((int) body.length());
|
||||||
@@ -270,8 +270,8 @@ void HTTPSServerTest::testRedirect()
|
|||||||
pParams->setKeepAlive(false);
|
pParams->setKeepAlive(false);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
HTTPRequest request("GET", "/redirect");
|
HTTPRequest request("GET", "/redirect");
|
||||||
cs.sendRequest(request);
|
cs.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
@@ -290,8 +290,8 @@ void HTTPSServerTest::testAuth()
|
|||||||
pParams->setKeepAlive(false);
|
pParams->setKeepAlive(false);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
HTTPRequest request("GET", "/auth");
|
HTTPRequest request("GET", "/auth");
|
||||||
cs.sendRequest(request);
|
cs.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
@@ -310,8 +310,8 @@ void HTTPSServerTest::testNotImpl()
|
|||||||
pParams->setKeepAlive(false);
|
pParams->setKeepAlive(false);
|
||||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
|
|
||||||
HTTPSClientSession cs("localhost", svs.address().port());
|
HTTPSClientSession cs("127.0.0.1", svs.address().port());
|
||||||
HTTPRequest request("GET", "/notImpl");
|
HTTPRequest request("GET", "/notImpl");
|
||||||
cs.sendRequest(request);
|
cs.sendRequest(request);
|
||||||
HTTPResponse response;
|
HTTPResponse response;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ void HTTPSStreamFactoryTest::testNoRedirect()
|
|||||||
{
|
{
|
||||||
HTTPSTestServer server;
|
HTTPSTestServer server;
|
||||||
HTTPSStreamFactory factory;
|
HTTPSStreamFactory factory;
|
||||||
URI uri("https://localhost/large");
|
URI uri("https://127.0.0.1/large");
|
||||||
uri.setPort(server.port());
|
uri.setPort(server.port());
|
||||||
#ifndef POCO_ENABLE_CPP11
|
#ifndef POCO_ENABLE_CPP11
|
||||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||||
@@ -62,7 +62,7 @@ void HTTPSStreamFactoryTest::testEmptyPath()
|
|||||||
{
|
{
|
||||||
HTTPSTestServer server;
|
HTTPSTestServer server;
|
||||||
HTTPSStreamFactory factory;
|
HTTPSStreamFactory factory;
|
||||||
URI uri("https://localhost");
|
URI uri("https://127.0.0.1");
|
||||||
uri.setPort(server.port());
|
uri.setPort(server.port());
|
||||||
#ifndef POCO_ENABLE_CPP11
|
#ifndef POCO_ENABLE_CPP11
|
||||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||||
@@ -79,7 +79,7 @@ void HTTPSStreamFactoryTest::testRedirect()
|
|||||||
{
|
{
|
||||||
HTTPSTestServer server;
|
HTTPSTestServer server;
|
||||||
HTTPSStreamFactory factory;
|
HTTPSStreamFactory factory;
|
||||||
URI uri("https://localhost/redirect");
|
URI uri("https://127.0.0.1/redirect");
|
||||||
uri.setPort(server.port());
|
uri.setPort(server.port());
|
||||||
#ifndef POCO_ENABLE_CPP11
|
#ifndef POCO_ENABLE_CPP11
|
||||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||||
@@ -96,7 +96,7 @@ void HTTPSStreamFactoryTest::testProxy()
|
|||||||
{
|
{
|
||||||
HTTPSTestServer server;
|
HTTPSTestServer server;
|
||||||
HTTPSStreamFactory factory(
|
HTTPSStreamFactory factory(
|
||||||
Application::instance().config().getString("testsuite.proxy.host"),
|
Application::instance().config().getString("testsuite.proxy.host"),
|
||||||
Application::instance().config().getInt("testsuite.proxy.port")
|
Application::instance().config().getInt("testsuite.proxy.port")
|
||||||
);
|
);
|
||||||
URI uri("https://secure.appinf.com/public/poco/NetSSL.txt");
|
URI uri("https://secure.appinf.com/public/poco/NetSSL.txt");
|
||||||
@@ -115,7 +115,7 @@ void HTTPSStreamFactoryTest::testError()
|
|||||||
{
|
{
|
||||||
HTTPSTestServer server;
|
HTTPSTestServer server;
|
||||||
HTTPSStreamFactory factory;
|
HTTPSStreamFactory factory;
|
||||||
URI uri("https://localhost/notfound");
|
URI uri("https://127.0.0.1/notfound");
|
||||||
uri.setPort(server.port());
|
uri.setPort(server.port());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace
|
|||||||
EchoConnection(const StreamSocket& s): TCPServerConnection(s)
|
EchoConnection(const StreamSocket& s): TCPServerConnection(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
StreamSocket& ss = socket();
|
StreamSocket& ss = socket();
|
||||||
@@ -92,8 +92,8 @@ void TCPServerTest::testOneConnection()
|
|||||||
assert (srv.currentThreads() == 0);
|
assert (srv.currentThreads() == 0);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 0);
|
assert (srv.totalConnections() == 0);
|
||||||
|
|
||||||
SocketAddress sa("localhost", svs.address().port());
|
SocketAddress sa("127.0.0.1", svs.address().port());
|
||||||
SecureStreamSocket ss1(sa);
|
SecureStreamSocket ss1(sa);
|
||||||
std::string data("hello, world");
|
std::string data("hello, world");
|
||||||
ss1.sendBytes(data.data(), (int) data.size());
|
ss1.sendBytes(data.data(), (int) data.size());
|
||||||
@@ -120,8 +120,8 @@ void TCPServerTest::testTwoConnections()
|
|||||||
assert (srv.currentThreads() == 0);
|
assert (srv.currentThreads() == 0);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 0);
|
assert (srv.totalConnections() == 0);
|
||||||
|
|
||||||
SocketAddress sa("localhost", svs.address().port());
|
SocketAddress sa("127.0.0.1", svs.address().port());
|
||||||
SecureStreamSocket ss1(sa);
|
SecureStreamSocket ss1(sa);
|
||||||
SecureStreamSocket ss2(sa);
|
SecureStreamSocket ss2(sa);
|
||||||
std::string data("hello, world");
|
std::string data("hello, world");
|
||||||
@@ -136,7 +136,7 @@ void TCPServerTest::testTwoConnections()
|
|||||||
n = ss2.receiveBytes(buffer, sizeof(buffer));
|
n = ss2.receiveBytes(buffer, sizeof(buffer));
|
||||||
assert (n > 0);
|
assert (n > 0);
|
||||||
assert (std::string(buffer, n) == data);
|
assert (std::string(buffer, n) == data);
|
||||||
|
|
||||||
assert (srv.currentConnections() == 2);
|
assert (srv.currentConnections() == 2);
|
||||||
assert (srv.currentThreads() == 2);
|
assert (srv.currentThreads() == 2);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
@@ -167,8 +167,8 @@ void TCPServerTest::testMultiConnections()
|
|||||||
assert (srv.currentThreads() == 0);
|
assert (srv.currentThreads() == 0);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 0);
|
assert (srv.totalConnections() == 0);
|
||||||
|
|
||||||
SocketAddress sa("localhost", svs.address().port());
|
SocketAddress sa("127.0.0.1", svs.address().port());
|
||||||
SecureStreamSocket ss1(sa);
|
SecureStreamSocket ss1(sa);
|
||||||
SecureStreamSocket ss2(sa);
|
SecureStreamSocket ss2(sa);
|
||||||
SecureStreamSocket ss3(sa);
|
SecureStreamSocket ss3(sa);
|
||||||
@@ -195,12 +195,12 @@ void TCPServerTest::testMultiConnections()
|
|||||||
n = ss4.receiveBytes(buffer, sizeof(buffer));
|
n = ss4.receiveBytes(buffer, sizeof(buffer));
|
||||||
assert (n > 0);
|
assert (n > 0);
|
||||||
assert (std::string(buffer, n) == data);
|
assert (std::string(buffer, n) == data);
|
||||||
|
|
||||||
assert (srv.currentConnections() == 4);
|
assert (srv.currentConnections() == 4);
|
||||||
assert (srv.currentThreads() == 4);
|
assert (srv.currentThreads() == 4);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 4);
|
assert (srv.totalConnections() == 4);
|
||||||
|
|
||||||
SecureStreamSocket ss5;
|
SecureStreamSocket ss5;
|
||||||
ss5.setLazyHandshake();
|
ss5.setLazyHandshake();
|
||||||
ss5.connect(sa);
|
ss5.connect(sa);
|
||||||
@@ -211,7 +211,7 @@ void TCPServerTest::testMultiConnections()
|
|||||||
ss6.connect(sa);
|
ss6.connect(sa);
|
||||||
Thread::sleep(200);
|
Thread::sleep(200);
|
||||||
assert (srv.queuedConnections() == 2);
|
assert (srv.queuedConnections() == 2);
|
||||||
|
|
||||||
ss1.close();
|
ss1.close();
|
||||||
Thread::sleep(300);
|
Thread::sleep(300);
|
||||||
assert (srv.currentConnections() == 4);
|
assert (srv.currentConnections() == 4);
|
||||||
@@ -225,7 +225,7 @@ void TCPServerTest::testMultiConnections()
|
|||||||
assert (srv.currentThreads() == 4);
|
assert (srv.currentThreads() == 4);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 6);
|
assert (srv.totalConnections() == 6);
|
||||||
|
|
||||||
ss3.close();
|
ss3.close();
|
||||||
Thread::sleep(300);
|
Thread::sleep(300);
|
||||||
assert (srv.currentConnections() == 3);
|
assert (srv.currentConnections() == 3);
|
||||||
@@ -256,8 +256,8 @@ void TCPServerTest::testReuseSocket()
|
|||||||
assert (srv.currentThreads() == 0);
|
assert (srv.currentThreads() == 0);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 0);
|
assert (srv.totalConnections() == 0);
|
||||||
|
|
||||||
SocketAddress sa("localhost", svs.address().port());
|
SocketAddress sa("127.0.0.1", svs.address().port());
|
||||||
SecureStreamSocket ss1(sa);
|
SecureStreamSocket ss1(sa);
|
||||||
std::string data("hello, world");
|
std::string data("hello, world");
|
||||||
ss1.sendBytes(data.data(), (int) data.size());
|
ss1.sendBytes(data.data(), (int) data.size());
|
||||||
@@ -292,21 +292,21 @@ void TCPServerTest::testReuseSession()
|
|||||||
// ensure OpenSSL machinery is fully setup
|
// ensure OpenSSL machinery is fully setup
|
||||||
Context::Ptr pDefaultServerContext = SSLManager::instance().defaultServerContext();
|
Context::Ptr pDefaultServerContext = SSLManager::instance().defaultServerContext();
|
||||||
Context::Ptr pDefaultClientContext = SSLManager::instance().defaultClientContext();
|
Context::Ptr pDefaultClientContext = SSLManager::instance().defaultClientContext();
|
||||||
|
|
||||||
Context::Ptr pServerContext = new Context(
|
Context::Ptr pServerContext = new Context(
|
||||||
Context::SERVER_USE,
|
Context::SERVER_USE,
|
||||||
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
Application::instance().config().getString("openSSL.server.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.server.caConfig"),
|
Application::instance().config().getString("openSSL.server.caConfig"),
|
||||||
Context::VERIFY_NONE,
|
Context::VERIFY_NONE,
|
||||||
9,
|
9,
|
||||||
true,
|
true,
|
||||||
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||||
pServerContext->enableSessionCache(true, "TestSuite");
|
pServerContext->enableSessionCache(true, "TestSuite");
|
||||||
pServerContext->setSessionTimeout(10);
|
pServerContext->setSessionTimeout(10);
|
||||||
pServerContext->setSessionCacheSize(1000);
|
pServerContext->setSessionCacheSize(1000);
|
||||||
pServerContext->disableStatelessSessionResumption();
|
pServerContext->disableStatelessSessionResumption();
|
||||||
|
|
||||||
SecureServerSocket svs(0, 64, pServerContext);
|
SecureServerSocket svs(0, 64, pServerContext);
|
||||||
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
|
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
|
||||||
srv.start();
|
srv.start();
|
||||||
@@ -314,9 +314,9 @@ void TCPServerTest::testReuseSession()
|
|||||||
assert (srv.currentThreads() == 0);
|
assert (srv.currentThreads() == 0);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 0);
|
assert (srv.totalConnections() == 0);
|
||||||
|
|
||||||
Context::Ptr pClientContext = new Context(
|
Context::Ptr pClientContext = new Context(
|
||||||
Context::CLIENT_USE,
|
Context::CLIENT_USE,
|
||||||
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
Application::instance().config().getString("openSSL.client.privateKeyFile"),
|
||||||
Application::instance().config().getString("openSSL.client.caConfig"),
|
Application::instance().config().getString("openSSL.client.caConfig"),
|
||||||
@@ -325,8 +325,8 @@ void TCPServerTest::testReuseSession()
|
|||||||
true,
|
true,
|
||||||
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||||
pClientContext->enableSessionCache(true);
|
pClientContext->enableSessionCache(true);
|
||||||
|
|
||||||
SocketAddress sa("localhost", svs.address().port());
|
SocketAddress sa("127.0.0.1", svs.address().port());
|
||||||
SecureStreamSocket ss1(sa, pClientContext);
|
SecureStreamSocket ss1(sa, pClientContext);
|
||||||
assert (!ss1.sessionWasReused());
|
assert (!ss1.sessionWasReused());
|
||||||
std::string data("hello, world");
|
std::string data("hello, world");
|
||||||
@@ -339,9 +339,9 @@ void TCPServerTest::testReuseSession()
|
|||||||
assert (srv.currentThreads() == 1);
|
assert (srv.currentThreads() == 1);
|
||||||
assert (srv.queuedConnections() == 0);
|
assert (srv.queuedConnections() == 0);
|
||||||
assert (srv.totalConnections() == 1);
|
assert (srv.totalConnections() == 1);
|
||||||
|
|
||||||
Session::Ptr pSession = ss1.currentSession();
|
Session::Ptr pSession = ss1.currentSession();
|
||||||
|
|
||||||
ss1.close();
|
ss1.close();
|
||||||
Thread::sleep(300);
|
Thread::sleep(300);
|
||||||
assert (srv.currentConnections() == 0);
|
assert (srv.currentConnections() == 0);
|
||||||
@@ -363,7 +363,7 @@ void TCPServerTest::testReuseSession()
|
|||||||
|
|
||||||
Thread::sleep(15000); // wait for session to expire
|
Thread::sleep(15000); // wait for session to expire
|
||||||
pServerContext->flushSessionCache();
|
pServerContext->flushSessionCache();
|
||||||
|
|
||||||
ss1.useSession(pSession);
|
ss1.useSession(pSession);
|
||||||
ss1.connect(sa);
|
ss1.connect(sa);
|
||||||
assert (!ss1.sessionWasReused());
|
assert (!ss1.sessionWasReused());
|
||||||
|
|||||||
Reference in New Issue
Block a user