mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-21 15:51:43 +02:00
NetSSL library refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/Driver.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/Driver.cpp#10 $
|
||||
//
|
||||
// Console-based test driver for Poco NetSSL.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp#10 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
|
||||
#include "HTTPSClientSessionTest.h"
|
||||
#include "HTTPSClientTestSuite.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPSClientSession.h"
|
||||
@@ -46,6 +45,8 @@
|
||||
#include "Poco/Net/SecureStreamSocket.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "HTTPSTestServer.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
@@ -53,11 +54,9 @@
|
||||
|
||||
|
||||
using namespace Poco::Net;
|
||||
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
|
||||
class TestRequestHandler: public HTTPRequestHandler
|
||||
/// Return a HTML document with the current date and time.
|
||||
{
|
||||
@@ -252,40 +251,6 @@ void HTTPSClientSessionTest::testPostLargeChunkedKeepAlive()
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostSmallClose()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body("this is a random request body");
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostLargeClose()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(8000, 'x');
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testKeepAlive()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
@@ -334,37 +299,40 @@ void HTTPSClientSessionTest::testKeepAlive()
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testProxy()
|
||||
void HTTPSClientSessionTest::testInterop()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s(TESTSERVERNAME);
|
||||
s.setProxy("proxy.aon.at", 8080);
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
HTTPSClientSession s("secure.appinf.com");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/public/poco/NetSSL.txt");
|
||||
s.sendRequest(request);
|
||||
X509Certificate cert = s.serverCertificate();
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str().length() > 0);
|
||||
std::string str(ostr.str());
|
||||
assert (str == "This is a test file for NetSSL.\n");
|
||||
assert (cert.commonName() == "secure.appinf.com");
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testConnectNB()
|
||||
void HTTPSClientSessionTest::testProxy()
|
||||
{
|
||||
SecureStreamSocket sock;
|
||||
sock.connectNB(SocketAddress(TESTSERVERNAME, 443));
|
||||
char buf[512];
|
||||
std::string msg("GET / HTTP/1.0\r\n\r\n");
|
||||
sock.sendBytes(msg.c_str(), (int)msg.length());
|
||||
Socket::SocketList read;
|
||||
Socket::SocketList write;
|
||||
Socket::SocketList exec;
|
||||
read.push_back(sock);
|
||||
Socket::select(read, write, exec, Poco::Timespan(30, 0) );
|
||||
int rc = sock.receiveBytes(buf, 512);
|
||||
assert (rc > 0);
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("secure.appinf.com");
|
||||
s.setProxy("proxy.aon.at", 8080);
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/public/poco/NetSSL.txt");
|
||||
s.sendRequest(request);
|
||||
X509Certificate cert = s.serverCertificate();
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
std::string str(ostr.str());
|
||||
assert (str == "This is a test file for NetSSL.\n");
|
||||
assert (cert.commonName() == "secure.appinf.com");
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -387,11 +355,9 @@ CppUnit::Test* HTTPSClientSessionTest::suite()
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallChunked);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeChunked);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeChunkedKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallClose);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeClose);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testInterop);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testProxy);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testConnectNB);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h#10 $
|
||||
//
|
||||
// Definition of the HTTPSClientSessionTest class.
|
||||
//
|
||||
@@ -54,11 +54,9 @@ public:
|
||||
void testPostSmallChunked();
|
||||
void testPostLargeChunked();
|
||||
void testPostLargeChunkedKeepAlive();
|
||||
void testPostSmallClose();
|
||||
void testPostLargeClose();
|
||||
void testKeepAlive();
|
||||
void testInterop();
|
||||
void testProxy();
|
||||
void testConnectNB();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.cpp#7 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSClientTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.h#7 $
|
||||
//
|
||||
// Definition of the HTTPSClientTestSuite class.
|
||||
//
|
||||
@@ -39,8 +39,6 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
#define TESTSERVERNAME "secure.appinf.com"
|
||||
|
||||
class HTTPSClientTestSuite
|
||||
{
|
||||
public:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSServerTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.cpp#9 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -192,29 +192,6 @@ void HTTPSServerTest::testChunkedRequest()
|
||||
}
|
||||
|
||||
|
||||
void HTTPSServerTest::testClosedRequest()
|
||||
{
|
||||
SecureServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPSClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSServerTest::testIdentityRequestKeepAlive()
|
||||
{
|
||||
SecureServerSocket svs(0);
|
||||
@@ -284,31 +261,6 @@ void HTTPSServerTest::testChunkedRequestKeepAlive()
|
||||
}
|
||||
|
||||
|
||||
void HTTPSServerTest::testClosedRequestKeepAlive()
|
||||
{
|
||||
SecureServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPSClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (!response.getKeepAlive());
|
||||
assert (rbody == body);
|
||||
int n = (int) rbody.size();
|
||||
}
|
||||
|
||||
|
||||
void HTTPSServerTest::test100Continue()
|
||||
{
|
||||
SecureServerSocket svs(0);
|
||||
@@ -408,10 +360,8 @@ CppUnit::Test* HTTPSServerTest::suite()
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testIdentityRequest);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testChunkedRequest);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testClosedRequest);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testIdentityRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testChunkedRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testClosedRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, test100Continue);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPSServerTest, testAuth);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSServerTest.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.h#8 $
|
||||
//
|
||||
// Definition of the HTTPSServerTest class.
|
||||
//
|
||||
@@ -48,10 +48,8 @@ public:
|
||||
|
||||
void testIdentityRequest();
|
||||
void testChunkedRequest();
|
||||
void testClosedRequest();
|
||||
void testIdentityRequestKeepAlive();
|
||||
void testChunkedRequestKeepAlive();
|
||||
void testClosedRequestKeepAlive();
|
||||
void test100Continue();
|
||||
void testRedirect();
|
||||
void testAuth();
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSServerTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.cpp#7 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSServerTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.h#7 $
|
||||
//
|
||||
// Definition of the HTTPSServerTestSuite class.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSStreamFactoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.cpp#8 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
|
||||
#include "HTTPSStreamFactoryTest.h"
|
||||
#include "HTTPSClientTestSuite.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPSStreamFactory.h"
|
||||
@@ -104,7 +103,7 @@ void HTTPSStreamFactoryTest::testProxy()
|
||||
{
|
||||
HTTPSTestServer server;
|
||||
HTTPSStreamFactory factory("proxy.aon.at", 8080);
|
||||
URI uri(std::string("https://") + TESTSERVERNAME + "/");
|
||||
URI uri("https://sourceforge.net/");
|
||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSStreamFactoryTest.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.h#7 $
|
||||
//
|
||||
// Definition of the HTTPSStreamFactoryTest class.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSTestServer.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp#9 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSTestServer.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.h#7 $
|
||||
//
|
||||
// Definition of the HTTPSTestServer class.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// OpenSSLTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.cpp#7 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// NetSSLTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.h#7 $
|
||||
//
|
||||
// Definition of the NetSSLTestSuite class.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// TCPServerTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/TCPServerTest.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/TCPServerTest.cpp#7 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// TCPServerTest.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/TCPServerTest.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/TCPServerTest.h#7 $
|
||||
//
|
||||
// Definition of the TCPServerTest class.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// TCPServerTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.cpp#7 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// TCPServerTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.h#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.h#7 $
|
||||
//
|
||||
// Definition of the TCPServerTestSuite class.
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/svn/NetSSL_OpenSSL/testsuite/src/WinDriver.cpp#1 $
|
||||
// $Id: //poco/Main/NetSSL_OpenSSL/testsuite/src/WinDriver.cpp#8 $
|
||||
//
|
||||
// Windows test driver for Poco OpenSSL.
|
||||
//
|
||||
|
Reference in New Issue
Block a user