mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 20:59:45 +01:00
sources from main repository
This commit is contained in:
306
NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp
Normal file
306
NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp
Normal file
@@ -0,0 +1,306 @@
|
||||
//
|
||||
// HTTPSClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPSClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPSClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "HTTPSTestServer.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPSClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
HTTPSClientSessionTest::HTTPSClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPSClientSessionTest::~HTTPSClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testGetSmall()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/small");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == HTTPSTestServer::SMALL_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testGetLarge()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == HTTPSTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testHead()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
assert (StreamCopier::copyStream(rs, ostr) == 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostSmallIdentity()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body("this is a random request body\r\n0\r\n");
|
||||
request.setContentLength((int) body.length());
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostLargeIdentity()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(8000, 'x');
|
||||
body.append("\r\n0\r\n");
|
||||
request.setContentLength((int) body.length());
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testPostSmallChunked()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body("this is a random request body");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
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::testPostLargeChunked()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(16000, 'x');
|
||||
request.setChunkedTransferEncoding(true);
|
||||
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::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;
|
||||
HTTPSClientSession s("localhost", srv.port());
|
||||
s.setKeepAlive(true);
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/keepAlive", HTTPMessage::HTTP_1_1);
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs1 = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (response.getKeepAlive());
|
||||
std::ostringstream ostr1;
|
||||
assert (StreamCopier::copyStream(rs1, ostr1) == 0);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_GET);
|
||||
request.setURI("/small");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs2 = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length());
|
||||
assert (response.getKeepAlive());
|
||||
std::ostringstream ostr2;
|
||||
StreamCopier::copyStream(rs2, ostr2);
|
||||
assert (ostr2.str() == HTTPSTestServer::SMALL_BODY);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_GET);
|
||||
request.setURI("/large");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs3 = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (response.getKeepAlive());
|
||||
std::ostringstream ostr3;
|
||||
int n = StreamCopier::copyStream(rs3, ostr3);
|
||||
assert (ostr3.str() == HTTPSTestServer::LARGE_BODY);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_HEAD);
|
||||
request.setURI("/large");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs4= s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getKeepAlive());
|
||||
std::ostringstream ostr4;
|
||||
assert (StreamCopier::copyStream(rs4, ostr4) == 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::testProxy()
|
||||
{
|
||||
HTTPSTestServer srv;
|
||||
HTTPSClientSession s("wwws.appinf.com");
|
||||
s.setProxy("proxy.aon.at", 8080);
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str().length() > 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPSClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPSClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPSClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testGetSmall);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testGetLarge);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testHead);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallChunked);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeChunked);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallClose);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeClose);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPSClientSessionTest, testProxy);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
Reference in New Issue
Block a user