mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 20:59:45 +01:00
NetSSL library refactoring
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user