mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-24 19:17:12 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
203
vendor/POCO/Net/testsuite/src/DNSTest.cpp
vendored
Normal file
203
vendor/POCO/Net/testsuite/src/DNSTest.cpp
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
//
|
||||
// DNSTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "DNSTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/DNS.h"
|
||||
#include "Poco/Net/HostEntry.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::DNS;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::HostEntry;
|
||||
using Poco::Net::InvalidAddressException;
|
||||
using Poco::Net::HostNotFoundException;
|
||||
using Poco::Net::ServiceNotFoundException;
|
||||
using Poco::Net::NoAddressFoundException;
|
||||
|
||||
|
||||
DNSTest::DNSTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DNSTest::~DNSTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testHostByName()
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("aliastest.pocoproject.org");
|
||||
// different systems report different canonical names, unfortunately.
|
||||
assertTrue (he1.name() == "dnstest.pocoproject.org" || he1.name() == "aliastest.pocoproject.org");
|
||||
#if !defined(POCO_HAVE_ADDRINFO)
|
||||
// getaddrinfo() does not report any aliases
|
||||
assertTrue (!he1.aliases().empty());
|
||||
assertTrue (he1.aliases()[0] == "aliastest.pocoproject.org");
|
||||
#endif
|
||||
assertTrue (he1.addresses().size() >= 1);
|
||||
assertTrue (he1.addresses()[0].toString() == "1.2.3.4");
|
||||
|
||||
try
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("nohost.pocoproject.org");
|
||||
fail("host not found - must throw");
|
||||
}
|
||||
catch (HostNotFoundException&)
|
||||
{
|
||||
}
|
||||
catch (NoAddressFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testHostByAddress()
|
||||
{
|
||||
IPAddress ip1("80.122.195.86");
|
||||
HostEntry he1 = DNS::hostByAddress(ip1);
|
||||
assertTrue (he1.name() == "mailhost.appinf.com");
|
||||
assertTrue (he1.aliases().empty());
|
||||
assertTrue (he1.addresses().size() >= 1);
|
||||
assertTrue (he1.addresses()[0].toString() == "80.122.195.86");
|
||||
|
||||
IPAddress ip2("10.0.244.253");
|
||||
try
|
||||
{
|
||||
HostEntry he2 = DNS::hostByAddress(ip2);
|
||||
fail("host not found - must throw");
|
||||
}
|
||||
catch (HostNotFoundException&)
|
||||
{
|
||||
}
|
||||
catch (NoAddressFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testResolve()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testEncodeIDN()
|
||||
{
|
||||
std::string idn("d\xc3\xb6m\xc3\xa4in.example"); // d"om"ain.example
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--dmin-moa0i.example");
|
||||
|
||||
idn = ".d\xc3\xb6m\xc3\xa4in.example"; // .d"om"ain.example
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == ".xn--dmin-moa0i.example");
|
||||
|
||||
idn = "d\xc3\xb6m\xc3\xa4in.example."; // .d"om"ain.example.
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--dmin-moa0i.example.");
|
||||
|
||||
idn = "d\xc3\xb6m\xc3\xa4in"; // d"om"ain
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--dmin-moa0i");
|
||||
|
||||
idn = "\xc3\xa4""aaa.example"; // "aaaa.example
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--aaa-pla.example");
|
||||
|
||||
idn = "a\xc3\xa4""aa.example"; // a"aaa.example
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--aaa-qla.example");
|
||||
|
||||
idn = "foo.\xc3\xa2""bcd\xc3\xa9""f.example"; // foo.^abcd'ef.example
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "foo.xn--bcdf-9na9b.example");
|
||||
|
||||
idn = "\xe2\x98\x83.example"; // <snowman>.example
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--n3h.example");
|
||||
|
||||
idn = "\xe2\x98\x83."; // <snowman>.
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--n3h.");
|
||||
|
||||
idn = "\xe2\x98\x83"; // <snowman>
|
||||
assertTrue (DNS::isIDN(idn));
|
||||
assertTrue (DNS::encodeIDN(idn) == "xn--n3h");
|
||||
|
||||
std::string dn = "www.pocoproject.org";
|
||||
assertTrue (!DNS::isIDN(dn));
|
||||
assertTrue (DNS::encodeIDN(dn) == "www.pocoproject.org");
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testDecodeIDN()
|
||||
{
|
||||
std::string enc("xn--dmin-moa0i.example");
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "d\xc3\xb6m\xc3\xa4in.example"); // d"om"ain.example
|
||||
|
||||
enc = ".xn--dmin-moa0i.example";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == ".d\xc3\xb6m\xc3\xa4in.example"); // .d"om"ain.example
|
||||
|
||||
enc = "xn--dmin-moa0i.example.";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "d\xc3\xb6m\xc3\xa4in.example."); // d"om"ain.example.
|
||||
|
||||
enc = "xn--dmin-moa0i";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "d\xc3\xb6m\xc3\xa4in"); // d"om"ain
|
||||
|
||||
enc = "foo.xn--bcdf-9na9b.example";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "foo.\xc3\xa2""bcd\xc3\xa9""f.example"); // foo.^abcd'ef.example
|
||||
|
||||
enc = "xn--n3h.example";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "\xe2\x98\x83.example"); // <snowman>.example
|
||||
|
||||
enc = "xn--n3h.";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "\xe2\x98\x83."); // <snowman>.
|
||||
|
||||
enc = "xn--n3h";
|
||||
assertTrue (DNS::isEncodedIDN(enc));
|
||||
assertTrue (DNS::decodeIDN(enc) == "\xe2\x98\x83"); // <snowman>
|
||||
|
||||
std::string dn = "www.pocoproject.org";
|
||||
assertTrue (!DNS::isEncodedIDN(dn));
|
||||
assertTrue (DNS::decodeIDN(dn) == "www.pocoproject.org");
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DNSTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DNSTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DNSTest, testHostByName);
|
||||
CppUnit_addTest(pSuite, DNSTest, testHostByAddress);
|
||||
CppUnit_addTest(pSuite, DNSTest, testResolve);
|
||||
CppUnit_addTest(pSuite, DNSTest, testEncodeIDN);
|
||||
CppUnit_addTest(pSuite, DNSTest, testDecodeIDN);
|
||||
|
||||
return pSuite;
|
||||
}
|
42
vendor/POCO/Net/testsuite/src/DNSTest.h
vendored
Normal file
42
vendor/POCO/Net/testsuite/src/DNSTest.h
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// DNSTest.h
|
||||
//
|
||||
// Definition of the DNSTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef DNSTest_INCLUDED
|
||||
#define DNSTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DNSTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DNSTest(const std::string& name);
|
||||
~DNSTest();
|
||||
|
||||
void testHostByName();
|
||||
void testHostByAddress();
|
||||
void testResolve();
|
||||
void testEncodeIDN();
|
||||
void testDecodeIDN();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DNSTest_INCLUDED
|
620
vendor/POCO/Net/testsuite/src/DatagramSocketTest.cpp
vendored
Normal file
620
vendor/POCO/Net/testsuite/src/DatagramSocketTest.cpp
vendored
Normal file
@ -0,0 +1,620 @@
|
||||
//
|
||||
// DatagramSocketTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "DatagramSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "UDPEchoServer.h"
|
||||
#include "Poco/Net/DatagramSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetworkInterface.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::DatagramSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
using Poco::Net::NetworkInterface;
|
||||
#endif
|
||||
using Poco::Timespan;
|
||||
using Poco::Buffer;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::IOException;
|
||||
|
||||
|
||||
DatagramSocketTest::DatagramSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DatagramSocketTest::~DatagramSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testEcho()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
char buffer[256];
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes("hello", 5);
|
||||
assertTrue (n == 5);
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testEchoBuffer()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
Buffer<char> buffer(0);
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.receiveBytes(buffer);
|
||||
assertTrue (n == 0);
|
||||
assertTrue (buffer.size() == 0);
|
||||
n = ss.sendBytes("hello", 5);
|
||||
assertTrue (n == 5);
|
||||
n = ss.receiveBytes(buffer);
|
||||
assertTrue (n == 5);
|
||||
assertTrue (buffer.size() == 5);
|
||||
assertTrue (std::string(buffer.begin(), n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testSendToReceiveFrom()
|
||||
{
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss(SocketAddress::IPv4);
|
||||
int n = ss.sendTo("hello", 5, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 5);
|
||||
char buffer[256];
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(buffer, sizeof(buffer), sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testUnbound()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
char buffer[256];
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes("hello", 5);
|
||||
assertTrue (n == 5);
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testBroadcast()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss(IPAddress::IPv4);
|
||||
|
||||
#if defined(POCO_NET_HAS_INTERFACE) && (POCO_OS == POCO_OS_FREE_BSD)
|
||||
NetworkInterface ni = NetworkInterface::forName("em0");
|
||||
SocketAddress sa(ni.broadcastAddress(1), echoServer.port());
|
||||
#else
|
||||
SocketAddress sa("255.255.255.255", echoServer.port());
|
||||
#endif
|
||||
// not all socket implementations fail if broadcast option is not set
|
||||
/*
|
||||
try
|
||||
{
|
||||
int n = ss.sendTo("hello", 5, sa);
|
||||
fail ("broadcast option not set - must throw");
|
||||
}
|
||||
catch (IOException&)
|
||||
{
|
||||
}
|
||||
*/
|
||||
ss.setBroadcast(true);
|
||||
|
||||
#if (POCO_OS == POCO_OS_FREE_BSD)
|
||||
int opt = 1;
|
||||
poco_socklen_t len = sizeof(opt);
|
||||
ss.impl()->setRawOption(IPPROTO_IP, IP_ONESBCAST, (const char*) &opt, len);
|
||||
ss.impl()->getRawOption(IPPROTO_IP, IP_ONESBCAST, &opt, len);
|
||||
assertTrue (opt == 1);
|
||||
#endif
|
||||
|
||||
int n = ss.sendTo("hello", 5, sa);
|
||||
assertTrue (n == 5);
|
||||
char buffer[256] = { 0 };
|
||||
n = ss.receiveBytes(buffer, 5);
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterFixed()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
testGatherScatterFixedWin();
|
||||
testGatherScatterSTRFFixedWin();
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
testGatherScatterFixedUNIX();
|
||||
testGatherScatterSTRFFixedUNIX();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterFixedWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].buf, "1234567890", 10);
|
||||
std::memcpy(sbv[1].buf, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].buf, "helloworld", 10);
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].buf, 0, 10);
|
||||
std::memset(sbv[1].buf, 0, 10);
|
||||
std::memset(sbv[2].buf, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, empty, 10));
|
||||
|
||||
n = ss.receiveBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFFixedWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].buf, "1234567890", 10);
|
||||
std::memcpy(sbv[1].buf, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].buf, "helloworld", 10);
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendTo(sbv, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].buf, 0, 10);
|
||||
std::memset(sbv[1].buf, 0, 10);
|
||||
std::memset(sbv[2].buf, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, empty, 10));
|
||||
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(sbv, sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterFixedUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].iov_base, "1234567890", 10);
|
||||
std::memcpy(sbv[1].iov_base, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].iov_base, "helloworld", 10);
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].iov_base, 0, 10);
|
||||
std::memset(sbv[1].iov_base, 0, 10);
|
||||
std::memset(sbv[2].iov_base, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, empty, 10));
|
||||
|
||||
n = ss.receiveBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFFixedUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].iov_base, "1234567890", 10);
|
||||
std::memcpy(sbv[1].iov_base, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].iov_base, "helloworld", 10);
|
||||
|
||||
int n = ss.sendTo(sbv, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].iov_base, 0, 10);
|
||||
std::memset(sbv[1].iov_base, 0, 10);
|
||||
std::memset(sbv[2].iov_base, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, empty, 10));
|
||||
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(sbv, sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterVariable()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
testGatherScatterVariableWin();
|
||||
testGatherScatterSTRFVariableWin();
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
testGatherScatterVariableUNIX();
|
||||
testGatherScatterSTRFVariableUNIX();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterVariableWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].len == 3);
|
||||
assertTrue (sbvOut[1].len == 6);
|
||||
assertTrue (sbvOut[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].buf, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendTo(sbvOut, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = (char*) calloc(4, 1);
|
||||
strIn[1] = (char*) calloc(7, 1);
|
||||
strIn[2] = (char*) calloc(11, 1);
|
||||
std::memcpy(strIn[0], "321", 3);
|
||||
std::memcpy(strIn[1], "fedcba", 6);
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10);
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].len == 3);
|
||||
assertTrue (sbvIn[1].len == 6);
|
||||
assertTrue (sbvIn[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "dlrowolleh", 10));
|
||||
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(sbvIn, sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "helloworld", 10));
|
||||
|
||||
n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::reverse(sbvIn.begin(), sbvIn.end());
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123abcdefh", 10));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "ellowo", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "rld", 3));
|
||||
|
||||
free(strIn[0]);
|
||||
free(strIn[1]);
|
||||
free(strIn[2]);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFVariableWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].len == 3);
|
||||
assertTrue (sbvOut[1].len == 6);
|
||||
assertTrue (sbvOut[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].buf, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = new char[4];
|
||||
strIn[1] = new char[7];
|
||||
strIn[2] = new char[11];
|
||||
std::memcpy(strIn[0], "321", 3); strIn[0][3] = '\0';
|
||||
std::memcpy(strIn[1], "fedcba", 6); strIn[1][6] = '\0';
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10); strIn[2][10] = '\0';
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].len == 3);
|
||||
assertTrue (sbvIn[1].len == 6);
|
||||
assertTrue (sbvIn[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "dlrowolleh", 10));
|
||||
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "helloworld", 10));
|
||||
|
||||
n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::reverse(sbvIn.begin(), sbvIn.end());
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123abcdefh", 10));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "ellowo", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "rld", 3));
|
||||
|
||||
delete [] strIn[0];
|
||||
delete [] strIn[1];
|
||||
delete [] strIn[2];
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFVariableUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].iov_len == 3);
|
||||
assertTrue (sbvOut[1].iov_len == 6);
|
||||
assertTrue (sbvOut[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].iov_base, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = new char[4];
|
||||
strIn[1] = new char[7];
|
||||
strIn[2] = new char[11];
|
||||
std::memcpy(strIn[0], "321", 3); strIn[0][3] = '\0';
|
||||
std::memcpy(strIn[1], "fedcba", 6); strIn[1][6] = '\0';
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10); strIn[2][10] = '\0';
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].iov_len == 3);
|
||||
assertTrue (sbvIn[1].iov_len == 6);
|
||||
assertTrue (sbvIn[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "dlrowolleh", 10));
|
||||
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "helloworld", 10));
|
||||
|
||||
n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::reverse(sbvIn.begin(), sbvIn.end());
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "123abcdefh", 10));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "ellowo", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "rld", 3));
|
||||
|
||||
delete [] strIn[0];
|
||||
delete [] strIn[1];
|
||||
delete [] strIn[2];
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterVariableUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].iov_len == 3);
|
||||
assertTrue (sbvOut[1].iov_len == 6);
|
||||
assertTrue (sbvOut[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].iov_base, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = new char[4];
|
||||
strIn[1] = new char[7];
|
||||
strIn[2] = new char[11];
|
||||
std::memcpy(strIn[0], "321", 3); strIn[0][3] = '\0';
|
||||
std::memcpy(strIn[1], "fedcba", 6); strIn[1][6] = '\0';
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10); strIn[2][10] = '\0';
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].iov_len == 3);
|
||||
assertTrue (sbvIn[1].iov_len == 6);
|
||||
assertTrue (sbvIn[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "dlrowolleh", 10));
|
||||
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "helloworld", 10));
|
||||
|
||||
delete [] strIn[0];
|
||||
delete [] strIn[1];
|
||||
delete [] strIn[2];
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DatagramSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DatagramSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testEcho);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testEchoBuffer);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testSendToReceiveFrom);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testUnbound);
|
||||
#if (POCO_OS != POCO_OS_FREE_BSD) // works only with local net bcast and very randomly
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testBroadcast);
|
||||
#endif
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testGatherScatterFixed);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testGatherScatterVariable);
|
||||
|
||||
return pSuite;
|
||||
}
|
54
vendor/POCO/Net/testsuite/src/DatagramSocketTest.h
vendored
Normal file
54
vendor/POCO/Net/testsuite/src/DatagramSocketTest.h
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// DatagramSocketTest.h
|
||||
//
|
||||
// Definition of the DatagramSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef DatagramSocketTest_INCLUDED
|
||||
#define DatagramSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DatagramSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DatagramSocketTest(const std::string& name);
|
||||
~DatagramSocketTest();
|
||||
|
||||
void testEcho();
|
||||
void testEchoBuffer();
|
||||
void testSendToReceiveFrom();
|
||||
void testUnbound();
|
||||
void testBroadcast();
|
||||
void testGatherScatterFixed();
|
||||
void testGatherScatterVariable();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
// "STRF" are sendto/recvfrom versions of the same functionality
|
||||
void testGatherScatterFixedWin();
|
||||
void testGatherScatterSTRFFixedWin();
|
||||
void testGatherScatterVariableWin();
|
||||
void testGatherScatterSTRFVariableWin();
|
||||
|
||||
void testGatherScatterFixedUNIX();
|
||||
void testGatherScatterSTRFFixedUNIX();
|
||||
void testGatherScatterVariableUNIX();
|
||||
void testGatherScatterSTRFVariableUNIX();
|
||||
};
|
||||
|
||||
|
||||
#endif // DatagramSocketTest_INCLUDED
|
168
vendor/POCO/Net/testsuite/src/DialogServer.cpp
vendored
Normal file
168
vendor/POCO/Net/testsuite/src/DialogServer.cpp
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
//
|
||||
// DialogServer.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "DialogServer.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::FastMutex;
|
||||
using Poco::Thread;
|
||||
|
||||
|
||||
DialogServer::DialogServer(bool acceptCommands):
|
||||
_socket(SocketAddress()),
|
||||
_thread("DialogServer"),
|
||||
_stop(false),
|
||||
_acceptCommands(acceptCommands),
|
||||
_log(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
DialogServer::~DialogServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 DialogServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
DialogSocket ds = _socket.acceptConnection();
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
if (!_nextResponses.empty())
|
||||
{
|
||||
ds.sendMessage(_nextResponses.front());
|
||||
_nextResponses.erase(_nextResponses.begin());
|
||||
}
|
||||
}
|
||||
if (_acceptCommands)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string command;
|
||||
while (ds.receiveMessage(command))
|
||||
{
|
||||
if (_log) std::cout << ">> " << command << std::endl;
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
_lastCommands.push_back(command);
|
||||
if (!_nextResponses.empty())
|
||||
{
|
||||
if (_log) std::cout << "<< " << _nextResponses.front() << std::endl;
|
||||
ds.sendMessage(_nextResponses.front());
|
||||
_nextResponses.erase(_nextResponses.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "DialogServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::string& DialogServer::lastCommand() const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
static const std::string EMPTY;
|
||||
if (_lastCommands.empty())
|
||||
return EMPTY;
|
||||
else
|
||||
return _lastCommands.back();
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::string>& DialogServer::lastCommands() const
|
||||
{
|
||||
return _lastCommands;
|
||||
}
|
||||
|
||||
|
||||
std::string DialogServer::popCommand()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::string command;
|
||||
if (!_lastCommands.empty())
|
||||
{
|
||||
command = _lastCommands.front();
|
||||
_lastCommands.erase(_lastCommands.begin());
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
|
||||
std::string DialogServer::popCommandWait()
|
||||
{
|
||||
std::string result(popCommand());
|
||||
while (result.empty())
|
||||
{
|
||||
Thread::sleep(100);
|
||||
result = popCommand();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::addResponse(const std::string& response)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_nextResponses.push_back(response);
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::clearCommands()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_lastCommands.clear();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::clearResponses()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_nextResponses.clear();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::log(bool flag)
|
||||
{
|
||||
_log = flag;
|
||||
}
|
81
vendor/POCO/Net/testsuite/src/DialogServer.h
vendored
Normal file
81
vendor/POCO/Net/testsuite/src/DialogServer.h
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
//
|
||||
// DialogServer.h
|
||||
//
|
||||
// Definition of the DialogServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef DialogServer_INCLUDED
|
||||
#define DialogServer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
class DialogServer: public Poco::Runnable
|
||||
/// A server for testing FTPClientSession and friends.
|
||||
{
|
||||
public:
|
||||
DialogServer(bool acceptCommands = true);
|
||||
/// Creates the DialogServer.
|
||||
|
||||
~DialogServer();
|
||||
/// Destroys the DialogServer.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const std::string& lastCommand() const;
|
||||
/// Returns the last command received by the server.
|
||||
|
||||
std::string popCommand();
|
||||
/// Pops the next command from the list of received commands.
|
||||
|
||||
std::string popCommandWait();
|
||||
/// Pops the next command from the list of received commands.
|
||||
/// Waits until a command is available.
|
||||
|
||||
const std::vector<std::string>& lastCommands() const;
|
||||
/// Returns the last command received by the server.
|
||||
|
||||
void addResponse(const std::string& response);
|
||||
/// Sets the next response returned by the server.
|
||||
|
||||
void clearCommands();
|
||||
/// Clears all commands.
|
||||
|
||||
void clearResponses();
|
||||
/// Clears all responses.
|
||||
|
||||
void log(bool flag);
|
||||
/// Enables or disables logging to stdout.
|
||||
|
||||
private:
|
||||
Poco::Net::ServerSocket _socket;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
bool _stop;
|
||||
std::vector<std::string> _nextResponses;
|
||||
std::vector<std::string> _lastCommands;
|
||||
bool _acceptCommands;
|
||||
bool _log;
|
||||
};
|
||||
|
||||
|
||||
#endif // DialogServer_INCLUDED
|
110
vendor/POCO/Net/testsuite/src/DialogSocketTest.cpp
vendored
Normal file
110
vendor/POCO/Net/testsuite/src/DialogSocketTest.cpp
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
//
|
||||
// DialogSocketTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "DialogSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "EchoServer.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
|
||||
|
||||
DialogSocketTest::DialogSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DialogSocketTest::~DialogSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::testDialogSocket()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
DialogSocket ds;
|
||||
ds.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
|
||||
ds.sendMessage("Hello, world!");
|
||||
std::string str;
|
||||
ds.receiveMessage(str);
|
||||
assertTrue (str == "Hello, world!");
|
||||
|
||||
ds.sendString("Hello, World!\n");
|
||||
ds.receiveMessage(str);
|
||||
assertTrue (str == "Hello, World!");
|
||||
|
||||
ds.sendMessage("EHLO", "appinf.com");
|
||||
ds.receiveMessage(str);
|
||||
assertTrue (str == "EHLO appinf.com");
|
||||
|
||||
ds.sendMessage("PUT", "local.txt", "remote.txt");
|
||||
ds.receiveMessage(str);
|
||||
assertTrue (str == "PUT local.txt remote.txt");
|
||||
|
||||
ds.sendMessage("220 Hello, world!");
|
||||
int status = ds.receiveStatusMessage(str);
|
||||
assertTrue (status == 220);
|
||||
assertTrue (str == "220 Hello, world!");
|
||||
|
||||
ds.sendString("220-line1\r\n220 line2\r\n");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assertTrue (status == 220);
|
||||
assertTrue (str == "220-line1\n220 line2");
|
||||
|
||||
ds.sendString("220-line1\r\nline2\r\n220 line3\r\n");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assertTrue (status == 220);
|
||||
assertTrue (str == "220-line1\nline2\n220 line3");
|
||||
|
||||
ds.sendMessage("Hello, world!");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assertTrue (status == 0);
|
||||
assertTrue (str == "Hello, world!");
|
||||
|
||||
ds.sendString("Header\nMore Bytes");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assertTrue (status == 0);
|
||||
assertTrue (str == "Header");
|
||||
char buffer[16];
|
||||
int n = ds.receiveRawBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 10);
|
||||
assertTrue (std::memcmp(buffer, "More Bytes", 10) == 0);
|
||||
|
||||
ds.sendString("Even More Bytes");
|
||||
n = ds.receiveRawBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 15);
|
||||
assertTrue (std::memcmp(buffer, "Even More Bytes", 15) == 0);
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DialogSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DialogSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DialogSocketTest, testDialogSocket);
|
||||
|
||||
return pSuite;
|
||||
}
|
38
vendor/POCO/Net/testsuite/src/DialogSocketTest.h
vendored
Normal file
38
vendor/POCO/Net/testsuite/src/DialogSocketTest.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// DialogSocketTest.h
|
||||
//
|
||||
// Definition of the DialogSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef DialogSocketTest_INCLUDED
|
||||
#define DialogSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DialogSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DialogSocketTest(const std::string& name);
|
||||
~DialogSocketTest();
|
||||
|
||||
void testDialogSocket();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DialogSocketTest_INCLUDED
|
17
vendor/POCO/Net/testsuite/src/Driver.cpp
vendored
Normal file
17
vendor/POCO/Net/testsuite/src/Driver.cpp
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// Console-based test driver for Poco Net.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "NetTestSuite.h"
|
||||
|
||||
|
||||
CppUnitMain(NetTestSuite)
|
82
vendor/POCO/Net/testsuite/src/EchoServer.cpp
vendored
Normal file
82
vendor/POCO/Net/testsuite/src/EchoServer.cpp
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// EchoServer.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "EchoServer.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
|
||||
|
||||
EchoServer::EchoServer():
|
||||
_socket(SocketAddress()),
|
||||
_thread("EchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
EchoServer::EchoServer(const Poco::Net::SocketAddress& address):
|
||||
_socket(address),
|
||||
_thread("EchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
EchoServer::~EchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 EchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void EchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
StreamSocket ss = _socket.acceptConnection();
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
while (n > 0 && !_stop)
|
||||
{
|
||||
ss.sendBytes(buffer, n);
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
}
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "EchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
vendor/POCO/Net/testsuite/src/EchoServer.h
vendored
Normal file
51
vendor/POCO/Net/testsuite/src/EchoServer.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// EchoServer.h
|
||||
//
|
||||
// Definition of the EchoServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef EchoServer_INCLUDED
|
||||
#define EchoServer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
class EchoServer: public Poco::Runnable
|
||||
/// A simple sequential echo server.
|
||||
{
|
||||
public:
|
||||
EchoServer();
|
||||
/// Creates the EchoServer.
|
||||
|
||||
EchoServer(const Poco::Net::SocketAddress& address);
|
||||
/// Creates the EchoServer using the given address.
|
||||
|
||||
~EchoServer();
|
||||
/// Destroys the EchoServer.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
private:
|
||||
Poco::Net::ServerSocket _socket;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // EchoServer_INCLUDED
|
603
vendor/POCO/Net/testsuite/src/FTPClientSessionTest.cpp
vendored
Normal file
603
vendor/POCO/Net/testsuite/src/FTPClientSessionTest.cpp
vendored
Normal file
@ -0,0 +1,603 @@
|
||||
//
|
||||
// FTPClientSessionTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "FTPClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Poco/Net/FTPClientSession.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::FTPClientSession;
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::FTPException;
|
||||
using Poco::ActiveMethod;
|
||||
using Poco::ActiveResult;
|
||||
using Poco::StreamCopier;
|
||||
using Poco::Thread;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class ActiveDownloader
|
||||
{
|
||||
public:
|
||||
ActiveDownloader(FTPClientSession& session):
|
||||
download(this, &ActiveDownloader::downloadImp),
|
||||
_session(session)
|
||||
{
|
||||
}
|
||||
|
||||
ActiveMethod<std::string, std::string, ActiveDownloader> download;
|
||||
|
||||
protected:
|
||||
std::string downloadImp(const std::string& path)
|
||||
{
|
||||
std::istream& istr = _session.beginDownload(path);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(istr, ostr);
|
||||
_session.endDownload();
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
private:
|
||||
FTPClientSession& _session;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
FTPClientSessionTest::FTPClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FTPClientSessionTest::~FTPClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::login(DialogServer& server, FTPClientSession& session)
|
||||
{
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
session.login("user", "password");
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "USER user");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "PASS password");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "TYPE I");
|
||||
|
||||
assertTrue (session.getFileType() == FTPClientSession::TYPE_BINARY);
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin1()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
assertTrue (session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
login(server, session);
|
||||
assertTrue (session.isOpen());
|
||||
assertTrue (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.logout();
|
||||
assertTrue (session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
|
||||
server.clearCommands();
|
||||
server.clearResponses();
|
||||
login(server, session);
|
||||
assertTrue (session.isOpen());
|
||||
assertTrue (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assertTrue (!session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin2()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
Poco::UInt16 serverPort = server.port();
|
||||
FTPClientSession session("127.0.0.1", serverPort, "user", "password");
|
||||
assertTrue (session.isOpen());
|
||||
assertTrue (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assertTrue (!session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
|
||||
server.clearCommands();
|
||||
server.clearResponses();
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
session.open("127.0.0.1", serverPort, "user", "password");
|
||||
assertTrue (session.isOpen());
|
||||
assertTrue (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assertTrue (!session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin3()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session;
|
||||
assertTrue (!session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
session.open("127.0.0.1", server.port(), "user", "password");
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assertTrue (!session.isOpen());
|
||||
assertTrue (!session.isLoggedIn());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLoginFailed1()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("421 localhost FTP not ready");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
try
|
||||
{
|
||||
session.login("user", "password");
|
||||
fail("server not ready - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLoginFailed2()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("530 Login incorrect");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
try
|
||||
{
|
||||
session.login("user", "password");
|
||||
fail("login incorrect - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testCommands()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "password");
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "USER user");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "PASS password");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "TYPE I");
|
||||
|
||||
// systemType
|
||||
server.clearCommands();
|
||||
server.addResponse("215 UNIX Type: L8 Version: dummyFTP 1.0");
|
||||
std::string type = session.systemType();
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "SYST");
|
||||
assertTrue (type == "UNIX Type: L8 Version: dummyFTP 1.0");
|
||||
|
||||
// getWorkingDirectory
|
||||
server.addResponse("257 \"/usr/test\" is current directory");
|
||||
std::string cwd = session.getWorkingDirectory();
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "PWD");
|
||||
assertTrue (cwd == "/usr/test");
|
||||
|
||||
// getWorkingDirectory (quotes in filename)
|
||||
server.addResponse("257 \"\"\"quote\"\"\" is current directory");
|
||||
cwd = session.getWorkingDirectory();
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "PWD");
|
||||
assertTrue (cwd == "\"quote\"");
|
||||
|
||||
// setWorkingDirectory
|
||||
server.addResponse("250 CWD OK");
|
||||
session.setWorkingDirectory("test");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "CWD test");
|
||||
|
||||
server.addResponse("250 CDUP OK");
|
||||
session.cdup();
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "CDUP");
|
||||
|
||||
// rename
|
||||
server.addResponse("350 File exists, send destination name");
|
||||
server.addResponse("250 Rename OK");
|
||||
session.rename("old.txt", "new.txt");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "RNFR old.txt");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "RNTO new.txt");
|
||||
|
||||
// rename (failing)
|
||||
server.addResponse("550 not found");
|
||||
try
|
||||
{
|
||||
session.rename("old.txt", "new.txt");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
// remove
|
||||
server.addResponse("250 delete ok");
|
||||
session.remove("test.txt");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "DELE test.txt");
|
||||
|
||||
// remove (failing)
|
||||
server.addResponse("550 not found");
|
||||
try
|
||||
{
|
||||
session.remove("test.txt");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
// createDirectory
|
||||
server.addResponse("257 dir created");
|
||||
session.createDirectory("foo");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "MKD foo");
|
||||
|
||||
// createDirectory (failing)
|
||||
server.addResponse("550 exists");
|
||||
try
|
||||
{
|
||||
session.createDirectory("foo");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
// removeDirectory
|
||||
server.addResponse("250 RMD OK");
|
||||
session.removeDirectory("foo");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "RMD foo");
|
||||
|
||||
// removeDirectory (failing)
|
||||
server.addResponse("550 not found");
|
||||
try
|
||||
{
|
||||
session.removeDirectory("foo");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadPORT()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.setPassive(false);
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("500 EPRT not understood");
|
||||
server.addResponse("200 PORT OK");
|
||||
server.addResponse("150 Sending data\r\n226 Transfer complete");
|
||||
|
||||
ActiveDownloader dl(session);
|
||||
ActiveResult<std::string> result = dl.download("test.txt");
|
||||
|
||||
std::string cmd = server.popCommandWait();
|
||||
assertTrue (cmd.substr(0, 4) == "EPRT");
|
||||
|
||||
cmd = server.popCommandWait();
|
||||
assertTrue (cmd.substr(0, 4) == "PORT");
|
||||
|
||||
std::string dummy;
|
||||
int x, lo, hi;
|
||||
for (std::string::iterator it = cmd.begin(); it != cmd.end(); ++it)
|
||||
{
|
||||
if (*it == ',') *it = ' ';
|
||||
}
|
||||
std::istringstream istr(cmd);
|
||||
istr >> dummy >> x >> x >> x >> x >> hi >> lo;
|
||||
int port = hi*256 + lo;
|
||||
|
||||
cmd = server.popCommandWait();
|
||||
assertTrue (cmd == "RETR test.txt");
|
||||
|
||||
SocketAddress sa("127.0.0.1", (Poco::UInt16) port);
|
||||
DialogSocket dataSock;
|
||||
dataSock.connect(sa);
|
||||
|
||||
std::string data("This is some data");
|
||||
dataSock.sendString(data);
|
||||
dataSock.close();
|
||||
|
||||
result.wait();
|
||||
std::string received = result.data();
|
||||
assertTrue (received == data);
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadEPRT()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.setPassive(false);
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("200 EPRT OK");
|
||||
server.addResponse("150 Sending data\r\n226 Transfer complete");
|
||||
|
||||
ActiveDownloader dl(session);
|
||||
ActiveResult<std::string> result = dl.download("test.txt");
|
||||
|
||||
std::string cmd = server.popCommandWait();
|
||||
assertTrue (cmd.substr(0, 4) == "EPRT");
|
||||
|
||||
std::string dummy;
|
||||
char c;
|
||||
int d;
|
||||
int port;
|
||||
std::istringstream istr(cmd);
|
||||
istr >> dummy >> c >> d >> c >> d >> c >> d >> c >> d >> c >> d >> c >> port >> c;
|
||||
|
||||
cmd = server.popCommandWait();
|
||||
assertTrue (cmd == "RETR test.txt");
|
||||
|
||||
SocketAddress sa("127.0.0.1", (Poco::UInt16) port);
|
||||
DialogSocket dataSock;
|
||||
dataSock.connect(sa);
|
||||
|
||||
std::string data("This is some data");
|
||||
dataSock.sendString(data);
|
||||
dataSock.close();
|
||||
|
||||
result.wait();
|
||||
std::string received = result.data();
|
||||
assertTrue (received == data);
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadPASV()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("500 EPSV not understood");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
Poco::UInt16 dataServerPort = dataServer.port();
|
||||
dataServer.addResponse("This is some data");
|
||||
std::ostringstream pasv;
|
||||
pasv << "227 Entering Passive Mode (127,0,0,1," << (dataServerPort/256) << "," << (dataServerPort % 256) << ")";
|
||||
server.addResponse(pasv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
|
||||
std::istream& istr = session.beginDownload("test.txt");
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(istr, dataStr);
|
||||
session.endDownload();
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "This is some data\r\n");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadEPSV()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("This is some data");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
|
||||
std::istream& istr = session.beginDownload("test.txt");
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(istr, dataStr);
|
||||
session.endDownload();
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "This is some data\r\n");
|
||||
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd.substr(0, 4) == "EPSV");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "RETR test.txt");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testUpload()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
DialogServer dataServer;
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 send data\r\n226 Transfer complete");
|
||||
|
||||
std::ostream& ostr = session.beginUpload("test.txt");
|
||||
ostr << "This is some data\r\n";
|
||||
session.endUpload();
|
||||
std::string s(dataServer.popCommandWait());
|
||||
assertTrue (s == "This is some data");
|
||||
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd.substr(0, 4) == "EPSV");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "STOR test.txt");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testList()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("file1\r\nfile2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
|
||||
std::istream& istr = session.beginList();
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(istr, dataStr);
|
||||
session.endList();
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "file1\r\nfile2\r\n");
|
||||
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd.substr(0, 4) == "EPSV");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "NLST");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* FTPClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLogin1);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLogin2);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLogin3);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLoginFailed1);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLoginFailed2);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testCommands);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadPORT);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadEPRT);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadPASV);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadEPSV);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testUpload);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testList);
|
||||
|
||||
return pSuite;
|
||||
}
|
59
vendor/POCO/Net/testsuite/src/FTPClientSessionTest.h
vendored
Normal file
59
vendor/POCO/Net/testsuite/src/FTPClientSessionTest.h
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// FTPClientSessionTest.h
|
||||
//
|
||||
// Definition of the FTPClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef FTPClientSessionTest_INCLUDED
|
||||
#define FTPClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
class FTPClientSession;
|
||||
|
||||
} }
|
||||
|
||||
class DialogServer;
|
||||
|
||||
class FTPClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FTPClientSessionTest(const std::string& name);
|
||||
~FTPClientSessionTest();
|
||||
|
||||
void testLogin1();
|
||||
void testLogin2();
|
||||
void testLogin3();
|
||||
void testLoginFailed1();
|
||||
void testLoginFailed2();
|
||||
void testCommands();
|
||||
void testDownloadPORT();
|
||||
void testDownloadEPRT();
|
||||
void testDownloadPASV();
|
||||
void testDownloadEPSV();
|
||||
void testUpload();
|
||||
void testList();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void login(DialogServer& server, Poco::Net::FTPClientSession& session);
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPClientSessionTest_INCLUDED
|
24
vendor/POCO/Net/testsuite/src/FTPClientTestSuite.cpp
vendored
Normal file
24
vendor/POCO/Net/testsuite/src/FTPClientTestSuite.cpp
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// FTPClientTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "FTPClientTestSuite.h"
|
||||
#include "FTPClientSessionTest.h"
|
||||
#include "FTPStreamFactoryTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* FTPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPClientTestSuite");
|
||||
|
||||
pSuite->addTest(FTPClientSessionTest::suite());
|
||||
pSuite->addTest(FTPStreamFactoryTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/FTPClientTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/FTPClientTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// FTPClientTestSuite.h
|
||||
//
|
||||
// Definition of the FTPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef FTPClientTestSuite_INCLUDED
|
||||
#define FTPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class FTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPClientTestSuite_INCLUDED
|
256
vendor/POCO/Net/testsuite/src/FTPStreamFactoryTest.cpp
vendored
Normal file
256
vendor/POCO/Net/testsuite/src/FTPStreamFactoryTest.cpp
vendored
Normal file
@ -0,0 +1,256 @@
|
||||
//
|
||||
// FTPStreamFactoryTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "FTPStreamFactoryTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Poco/Net/FTPStreamFactory.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using Poco::Net::FTPStreamFactory;
|
||||
using Poco::Net::FTPPasswordProvider;
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::FTPException;
|
||||
using Poco::URI;
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class TestPasswordProvider: public FTPPasswordProvider
|
||||
{
|
||||
public:
|
||||
std::string password(const std::string& username, const std::string& host)
|
||||
{
|
||||
return "secret";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
FTPStreamFactoryTest::FTPStreamFactoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FTPStreamFactoryTest::~FTPStreamFactoryTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testDownload()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("200 Type set to A");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("line1\r\nline2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("127.0.0.1");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
FTPStreamFactory sf;
|
||||
std::unique_ptr<std::istream> pStr(sf.open(uri));
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "line1\r\nline2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testList()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("250 CWD OK");
|
||||
server.addResponse("250 CWD OK");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("file1\r\nfile2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("127.0.0.1");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/usr/guest/data;type=d");
|
||||
FTPStreamFactory sf;
|
||||
std::unique_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "file1\r\nfile2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testUserInfo()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("200 Type set to A");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("line1\r\nline2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("127.0.0.1");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
uri.setUserInfo("user:secret");
|
||||
FTPStreamFactory sf;
|
||||
std::unique_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "line1\r\nline2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testPasswordProvider()
|
||||
{
|
||||
static TestPasswordProvider tpp;
|
||||
FTPStreamFactory::setPasswordProvider(&tpp);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("200 Type set to A");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("line1\r\nline2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("127.0.0.1");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
uri.setUserInfo("user");
|
||||
FTPStreamFactory sf;
|
||||
std::unique_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assertTrue (s == "line1\r\nline2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testMissingPasswordProvider()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("127.0.0.1");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
uri.setUserInfo("user");
|
||||
|
||||
try
|
||||
{
|
||||
FTPStreamFactory sf;
|
||||
std::unique_ptr<std::istream> pStr(sf.open(uri));
|
||||
fail("no password provider - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* FTPStreamFactoryTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPStreamFactoryTest");
|
||||
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testDownload);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testList);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testUserInfo);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testPasswordProvider);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testMissingPasswordProvider);
|
||||
|
||||
return pSuite;
|
||||
}
|
42
vendor/POCO/Net/testsuite/src/FTPStreamFactoryTest.h
vendored
Normal file
42
vendor/POCO/Net/testsuite/src/FTPStreamFactoryTest.h
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// FTPStreamFactoryTest.h
|
||||
//
|
||||
// Definition of the FTPStreamFactoryTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef FTPStreamFactoryTest_INCLUDED
|
||||
#define FTPStreamFactoryTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class FTPStreamFactoryTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FTPStreamFactoryTest(const std::string& name);
|
||||
~FTPStreamFactoryTest();
|
||||
|
||||
void testDownload();
|
||||
void testList();
|
||||
void testUserInfo();
|
||||
void testPasswordProvider();
|
||||
void testMissingPasswordProvider();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPStreamFactoryTest_INCLUDED
|
444
vendor/POCO/Net/testsuite/src/HTMLFormTest.cpp
vendored
Normal file
444
vendor/POCO/Net/testsuite/src/HTMLFormTest.cpp
vendored
Normal file
@ -0,0 +1,444 @@
|
||||
//
|
||||
// HTMLFormTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTMLFormTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
#include "Poco/Net/PartSource.h"
|
||||
#include "Poco/Net/StringPartSource.h"
|
||||
#include "Poco/Net/PartHandler.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTMLForm;
|
||||
using Poco::Net::PartSource;
|
||||
using Poco::Net::StringPartSource;
|
||||
using Poco::Net::PartHandler;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::MessageHeader;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class StringPartHandler: public PartHandler
|
||||
{
|
||||
public:
|
||||
StringPartHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void handlePart(const MessageHeader& header, std::istream& stream)
|
||||
{
|
||||
_disp = header["Content-Disposition"];
|
||||
_type = header["Content-Type"];
|
||||
int ch = stream.get();
|
||||
while (ch > 0)
|
||||
{
|
||||
_data += (char) ch;
|
||||
ch = stream.get();
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& data() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
const std::string& disp() const
|
||||
{
|
||||
return _disp;
|
||||
}
|
||||
|
||||
const std::string& type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _data;
|
||||
std::string _disp;
|
||||
std::string _type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
HTMLFormTest::HTMLFormTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTMLFormTest::~HTMLFormTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testWriteUrl()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
form.set("field5", "value+5");
|
||||
|
||||
std::ostringstream ostr;
|
||||
form.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "field1=value1&field2=value%202&field3=value%3D3&field4=value%264&field5=value%2B5");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testWriteMultipart()
|
||||
{
|
||||
HTMLForm form(HTMLForm::ENCODING_MULTIPART);
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
form.addPart("attachment1", new StringPartSource("This is an attachment"));
|
||||
StringPartSource* pSPS = new StringPartSource("This is another attachment", "text/plain", "att2.txt");
|
||||
pSPS->headers().set("Content-ID", "1234abcd");
|
||||
form.addPart("attachment2", pSPS);
|
||||
|
||||
std::ostringstream ostr;
|
||||
form.write(ostr, "MIME_boundary_0123456789");
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s ==
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
||||
"\r\n"
|
||||
"value1\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field2\"\r\n"
|
||||
"\r\n"
|
||||
"value 2\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field3\"\r\n"
|
||||
"\r\n"
|
||||
"value=3\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field4\"\r\n"
|
||||
"\r\n"
|
||||
"value&4\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"attachment1\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is an attachment\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-ID: 1234abcd\r\n"
|
||||
"Content-Disposition: form-data; name=\"attachment2\"; filename=\"att2.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is another attachment\r\n"
|
||||
"--MIME_boundary_0123456789--\r\n"
|
||||
);
|
||||
assertTrue (s.length() == form.calculateContentLength());
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrlGET()
|
||||
{
|
||||
HTTPRequest req("GET", "/form.cgi?field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form(req);
|
||||
assertTrue (form.size() == 4);
|
||||
assertTrue (form["field1"] == "value1");
|
||||
assertTrue (form["field2"] == "value 2");
|
||||
assertTrue (form["field3"] == "value=3");
|
||||
assertTrue (form["field4"] == "value&4");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrlGETMultiple()
|
||||
{
|
||||
HTTPRequest req("GET", "/form.cgi?field1=value1&field1=value%202&field1=value%3D3&field1=value%264");
|
||||
HTMLForm form(req);
|
||||
assertTrue (form.size() == 4);
|
||||
|
||||
HTMLForm::ConstIterator it = form.find("field1");
|
||||
assertTrue (it != form.end());
|
||||
assertTrue (it->first == "field1" && it->second == "value1");
|
||||
++it;
|
||||
assertTrue (it != form.end());
|
||||
assertTrue (it->first == "field1" && it->second == "value 2");
|
||||
++it;
|
||||
assertTrue (it != form.end());
|
||||
assertTrue (it->first == "field1" && it->second == "value=3");
|
||||
++it;
|
||||
assertTrue (it != form.end());
|
||||
assertTrue (it->first == "field1" && it->second == "value&4");
|
||||
++it;
|
||||
assertTrue (it == form.end());
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrlPOST()
|
||||
{
|
||||
HTTPRequest req("POST", "/form.cgi?field0=value0");
|
||||
std::istringstream istr("field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form(req, istr);
|
||||
assertTrue (form.size() == 5);
|
||||
assertTrue (form["field0"] == "value0");
|
||||
assertTrue (form["field1"] == "value1");
|
||||
assertTrue (form["field2"] == "value 2");
|
||||
assertTrue (form["field3"] == "value=3");
|
||||
assertTrue (form["field4"] == "value&4");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrlPUT()
|
||||
{
|
||||
HTTPRequest req("PUT", "/form.cgi?field0=value0");
|
||||
std::istringstream istr("field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form(req, istr);
|
||||
assertTrue (form.size() == 5);
|
||||
assertTrue (form["field0"] == "value0");
|
||||
assertTrue (form["field1"] == "value1");
|
||||
assertTrue (form["field2"] == "value 2");
|
||||
assertTrue (form["field3"] == "value=3");
|
||||
assertTrue (form["field4"] == "value&4");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrlBOM()
|
||||
{
|
||||
HTTPRequest req("PUT", "/form.cgi?field0=value0");
|
||||
std::istringstream istr("\357\273\277field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form(req, istr);
|
||||
assertTrue (form.size() == 5);
|
||||
assertTrue (form["field0"] == "value0");
|
||||
assertTrue (form["field1"] == "value1");
|
||||
assertTrue (form["field2"] == "value 2");
|
||||
assertTrue (form["field3"] == "value=3");
|
||||
assertTrue (form["field4"] == "value&4");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadMultipart()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
||||
"\r\n"
|
||||
"value1\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field2\"\r\n"
|
||||
"\r\n"
|
||||
"value 2\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field3\"\r\n"
|
||||
"\r\n"
|
||||
"value=3\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field4\"\r\n"
|
||||
"\r\n"
|
||||
"value&4\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: file; name=\"attachment1\"; filename=\"att1.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is an attachment\r\n"
|
||||
"--MIME_boundary_0123456789--\r\n"
|
||||
);
|
||||
HTTPRequest req("POST", "/form.cgi");
|
||||
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=\"MIME_boundary_0123456789\"");
|
||||
StringPartHandler sah;
|
||||
HTMLForm form(req, istr, sah);
|
||||
assertTrue (form.size() == 4);
|
||||
assertTrue (form["field1"] == "value1");
|
||||
assertTrue (form["field2"] == "value 2");
|
||||
assertTrue (form["field3"] == "value=3");
|
||||
assertTrue (form["field4"] == "value&4");
|
||||
|
||||
assertTrue (sah.type() == "text/plain");
|
||||
assertTrue (sah.disp() == "file; name=\"attachment1\"; filename=\"att1.txt\"");
|
||||
assertTrue (sah.data() == "This is an attachment");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit1()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("GET", "/form.cgi");
|
||||
form.prepareSubmit(req);
|
||||
assertTrue (req.getURI() == "/form.cgi?field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit2()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("POST", "/form.cgi");
|
||||
form.prepareSubmit(req);
|
||||
assertTrue (req.getContentType() == HTMLForm::ENCODING_URL);
|
||||
assertTrue (req.getContentLength() == 64);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit3()
|
||||
{
|
||||
HTMLForm form(HTMLForm::ENCODING_MULTIPART);
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("POST", "/form.cgi", HTTPMessage::HTTP_1_1);
|
||||
form.prepareSubmit(req);
|
||||
std::string expCT(HTMLForm::ENCODING_MULTIPART);
|
||||
expCT.append("; boundary=\"");
|
||||
expCT.append(form.boundary());
|
||||
expCT.append("\"");
|
||||
assertTrue (req.getContentType() == expCT);
|
||||
assertTrue (req.getChunkedTransferEncoding());
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit4()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.add("field1", "value1");
|
||||
form.add("field1", "value 2");
|
||||
form.add("field1", "value=3");
|
||||
form.add("field1", "value&4");
|
||||
|
||||
HTTPRequest req("GET", "/form.cgi");
|
||||
form.prepareSubmit(req);
|
||||
|
||||
assertTrue (req.getURI() == "/form.cgi?field1=value1&field1=value%202&field1=value%3D3&field1=value%264");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit5()
|
||||
{
|
||||
HTMLForm form(HTMLForm::ENCODING_MULTIPART);
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("POST", "/form.cgi", HTTPMessage::HTTP_1_1);
|
||||
form.prepareSubmit(req, HTMLForm::OPT_USE_CONTENT_LENGTH);
|
||||
std::string expCT(HTMLForm::ENCODING_MULTIPART);
|
||||
expCT.append("; boundary=\"");
|
||||
expCT.append(form.boundary());
|
||||
expCT.append("\"");
|
||||
assertTrue (req.getContentType() == expCT);
|
||||
assertTrue (req.getContentLength() == 403);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testFieldLimitUrl()
|
||||
{
|
||||
HTTPRequest req("GET", "/form.cgi?field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form;
|
||||
form.setFieldLimit(3);
|
||||
try
|
||||
{
|
||||
form.load(req);
|
||||
fail("field limit violated - must throw");
|
||||
}
|
||||
catch (Poco::Net::HTMLFormException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testFieldLimitMultipart()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
||||
"\r\n"
|
||||
"value1\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field2\"\r\n"
|
||||
"\r\n"
|
||||
"value 2\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field3\"\r\n"
|
||||
"\r\n"
|
||||
"value=3\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field4\"\r\n"
|
||||
"\r\n"
|
||||
"value&4\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: file; name=\"attachment1\"; filename=\"att1.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is an attachment\r\n"
|
||||
"--MIME_boundary_0123456789--\r\n"
|
||||
);
|
||||
HTTPRequest req("POST", "/form.cgi");
|
||||
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=\"MIME_boundary_0123456789\"");
|
||||
StringPartHandler sah;
|
||||
HTMLForm form;
|
||||
form.setFieldLimit(3);
|
||||
try
|
||||
{
|
||||
form.load(req, istr, sah);
|
||||
fail("field limit violated - must throw");
|
||||
}
|
||||
catch (Poco::Net::HTMLFormException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTMLFormTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTMLFormTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testWriteUrl);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testWriteMultipart);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlGET);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlGETMultiple);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlPOST);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlPUT);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlBOM);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadMultipart);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit1);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit2);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit3);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit4);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit5);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testFieldLimitUrl);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testFieldLimitMultipart);
|
||||
|
||||
return pSuite;
|
||||
}
|
52
vendor/POCO/Net/testsuite/src/HTMLFormTest.h
vendored
Normal file
52
vendor/POCO/Net/testsuite/src/HTMLFormTest.h
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// HTMLFormTest.h
|
||||
//
|
||||
// Definition of the HTMLFormTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTMLFormTest_INCLUDED
|
||||
#define HTMLFormTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTMLFormTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTMLFormTest(const std::string& name);
|
||||
~HTMLFormTest();
|
||||
|
||||
void testWriteUrl();
|
||||
void testWriteMultipart();
|
||||
void testReadUrlGET();
|
||||
void testReadUrlGETMultiple();
|
||||
void testReadUrlPOST();
|
||||
void testReadUrlPUT();
|
||||
void testReadUrlBOM();
|
||||
void testReadMultipart();
|
||||
void testSubmit1();
|
||||
void testSubmit2();
|
||||
void testSubmit3();
|
||||
void testSubmit4();
|
||||
void testSubmit5();
|
||||
void testFieldLimitUrl();
|
||||
void testFieldLimitMultipart();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTMLFormTest_INCLUDED
|
22
vendor/POCO/Net/testsuite/src/HTMLTestSuite.cpp
vendored
Normal file
22
vendor/POCO/Net/testsuite/src/HTMLTestSuite.cpp
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// HTMLTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTMLTestSuite.h"
|
||||
#include "HTMLFormTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTMLTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTMLTestSuite");
|
||||
|
||||
pSuite->addTest(HTMLFormTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/HTMLTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/HTMLTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// HTMLTestSuite.h
|
||||
//
|
||||
// Definition of the HTMLTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTMLTestSuite_INCLUDED
|
||||
#define HTMLTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTMLTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTMLTestSuite_INCLUDED
|
373
vendor/POCO/Net/testsuite/src/HTTPClientSessionTest.cpp
vendored
Normal file
373
vendor/POCO/Net/testsuite/src/HTTPClientSessionTest.cpp
vendored
Normal file
@ -0,0 +1,373 @@
|
||||
//
|
||||
// HTTPClientSessionTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "HTTPTestServer.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
HTTPClientSessionTest::HTTPClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPClientSessionTest::~HTTPClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testGetSmall()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/small");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::SMALL_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::SMALL_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testGetLarge()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testHead()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
assertTrue (StreamCopier::copyStream(rs, ostr) == 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostSmallIdentity()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", 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);
|
||||
assertTrue (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostLargeIdentity()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", 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);
|
||||
assertTrue (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostSmallChunked()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", 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);
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostLargeChunked()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(16000, 'x');
|
||||
request.setChunkedTransferEncoding(true);
|
||||
std::ostream& os = s.sendRequest(request);
|
||||
os << body;
|
||||
os.flush();
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr, 16000);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostSmallClose()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", 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);
|
||||
assertTrue (!response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostLargeClose()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", 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);
|
||||
assertTrue (!response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testKeepAlive()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", 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);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::SMALL_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getKeepAlive());
|
||||
std::ostringstream ostr1;
|
||||
assertTrue (StreamCopier::copyStream(rs1, ostr1) == 0);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_GET);
|
||||
request.setURI("/small");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs2 = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::SMALL_BODY.length());
|
||||
assertTrue (response.getKeepAlive());
|
||||
std::ostringstream ostr2;
|
||||
StreamCopier::copyStream(rs2, ostr2);
|
||||
assertTrue (ostr2.str() == HTTPTestServer::SMALL_BODY);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_GET);
|
||||
request.setURI("/large");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs3 = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getKeepAlive());
|
||||
std::ostringstream ostr3;
|
||||
StreamCopier::copyStream(rs3, ostr3);
|
||||
assertTrue (ostr3.str() == HTTPTestServer::LARGE_BODY);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_HEAD);
|
||||
request.setURI("/large");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs4= s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (!response.getKeepAlive());
|
||||
std::ostringstream ostr4;
|
||||
assertTrue (StreamCopier::copyStream(rs4, ostr4) == 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testProxy()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("www.somehost.com");
|
||||
s.setProxy("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testProxyAuth()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("www.somehost.com");
|
||||
s.setProxy("127.0.0.1", srv.port());
|
||||
s.setProxyCredentials("user", "pass");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
std::string r = srv.lastRequest();
|
||||
assertTrue (r.find("Proxy-Authorization: Basic dXNlcjpwYXNz\r\n") != std::string::npos);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testBypassProxy()
|
||||
{
|
||||
HTTPClientSession::ProxyConfig proxyConfig;
|
||||
proxyConfig.host = "proxy.domain.com";
|
||||
proxyConfig.port = 80;
|
||||
proxyConfig.nonProxyHosts = "localhost|127\\.0\\.0\\.1";
|
||||
|
||||
HTTPClientSession s1("127.0.0.1", 80);
|
||||
s1.setProxyConfig(proxyConfig);
|
||||
assertTrue (s1.bypassProxy());
|
||||
|
||||
HTTPClientSession s2("127.0.0.1", 80);
|
||||
s2.setProxyConfig(proxyConfig);
|
||||
assertTrue (s2.bypassProxy());
|
||||
|
||||
HTTPClientSession s3("www.appinf.com", 80);
|
||||
s3.setProxyConfig(proxyConfig);
|
||||
assertTrue (!s3.bypassProxy());
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testExpectContinue()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/expect");
|
||||
std::string body("this is a random request body\r\n0\r\n");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setExpectContinue(true);
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
assertTrue (s.peekResponse(response));
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_CONTINUE);
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_OK);
|
||||
assertTrue (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testExpectContinueFail()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("127.0.0.1", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/fail");
|
||||
std::string body("this is a random request body\r\n0\r\n");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setExpectContinue(true);
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
assertTrue (!s.peekResponse(response));
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_BAD_REQUEST);
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_BAD_REQUEST);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assertTrue (ostr.str().empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testGetSmall);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testGetLarge);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testHead);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallChunked);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeChunked);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallClose);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeClose);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxy);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxyAuth);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testBypassProxy);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testExpectContinue);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testExpectContinueFail);
|
||||
|
||||
return pSuite;
|
||||
}
|
52
vendor/POCO/Net/testsuite/src/HTTPClientSessionTest.h
vendored
Normal file
52
vendor/POCO/Net/testsuite/src/HTTPClientSessionTest.h
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// HTTPClientSessionTest.h
|
||||
//
|
||||
// Definition of the HTTPClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPClientSessionTest_INCLUDED
|
||||
#define HTTPClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPClientSessionTest(const std::string& name);
|
||||
~HTTPClientSessionTest();
|
||||
|
||||
void testGetSmall();
|
||||
void testGetLarge();
|
||||
void testHead();
|
||||
void testPostSmallIdentity();
|
||||
void testPostLargeIdentity();
|
||||
void testPostSmallChunked();
|
||||
void testPostLargeChunked();
|
||||
void testPostSmallClose();
|
||||
void testPostLargeClose();
|
||||
void testKeepAlive();
|
||||
void testProxy();
|
||||
void testProxyAuth();
|
||||
void testBypassProxy();
|
||||
void testExpectContinue();
|
||||
void testExpectContinueFail();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPClientSessionTest_INCLUDED
|
24
vendor/POCO/Net/testsuite/src/HTTPClientTestSuite.cpp
vendored
Normal file
24
vendor/POCO/Net/testsuite/src/HTTPClientTestSuite.cpp
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// HTTPClientTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPClientTestSuite.h"
|
||||
#include "HTTPClientSessionTest.h"
|
||||
#include "HTTPStreamFactoryTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTTPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPClientTestSuite");
|
||||
|
||||
pSuite->addTest(HTTPClientSessionTest::suite());
|
||||
pSuite->addTest(HTTPStreamFactoryTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/HTTPClientTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/HTTPClientTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// HTTPClientTestSuite.h
|
||||
//
|
||||
// Definition of the HTTPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPClientTestSuite_INCLUDED
|
||||
#define HTTPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPClientTestSuite_INCLUDED
|
216
vendor/POCO/Net/testsuite/src/HTTPCookieTest.cpp
vendored
Normal file
216
vendor/POCO/Net/testsuite/src/HTTPCookieTest.cpp
vendored
Normal file
@ -0,0 +1,216 @@
|
||||
//
|
||||
// HTTPCookieTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPCookieTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPCookie.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Timestamp;
|
||||
using Poco::Timespan;
|
||||
using Poco::DateTimeFormatter;
|
||||
using Poco::DateTimeFormat;
|
||||
using Poco::DateTimeParser;
|
||||
using Poco::DateTime;
|
||||
using Poco::Net::NameValueCollection;
|
||||
using Poco::Net::HTTPCookie;
|
||||
|
||||
|
||||
HTTPCookieTest::HTTPCookieTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPCookieTest::~HTTPCookieTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testCookie()
|
||||
{
|
||||
HTTPCookie cookie("name", "value");
|
||||
assertTrue (cookie.getName() == "name");
|
||||
assertTrue (cookie.getValue() == "value");
|
||||
assertTrue (cookie.toString() == "name=value");
|
||||
cookie.setPath("/");
|
||||
assertTrue (cookie.toString() == "name=value; path=/");
|
||||
cookie.setComment("comment");
|
||||
assertTrue (cookie.toString() == "name=value; path=/");
|
||||
cookie.setDomain("appinf.com");
|
||||
assertTrue (cookie.toString() == "name=value; domain=appinf.com; path=/");
|
||||
cookie.setSecure(true);
|
||||
assertTrue (cookie.toString() == "name=value; domain=appinf.com; path=/; secure");
|
||||
cookie.setHttpOnly(true);
|
||||
assertTrue (cookie.toString() == "name=value; domain=appinf.com; path=/; secure; HttpOnly");
|
||||
cookie.setPriority("Low");
|
||||
assertTrue (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=Low; secure; HttpOnly");
|
||||
cookie.setPriority("Medium");
|
||||
assertTrue (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=Medium; secure; HttpOnly");
|
||||
cookie.setPriority("High");
|
||||
assertTrue (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=High; secure; HttpOnly");
|
||||
cookie.setPriority("");
|
||||
cookie.setHttpOnly(false);
|
||||
|
||||
cookie.setVersion(1);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; secure; Version=\"1\"");
|
||||
|
||||
cookie.setSecure(false);
|
||||
cookie.setMaxAge(100);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; Version=\"1\"");
|
||||
|
||||
cookie.setHttpOnly(true);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
|
||||
|
||||
cookie.setPriority("Low");
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"Low\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
|
||||
cookie.setPriority("Medium");
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"Medium\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
|
||||
cookie.setPriority("High");
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"High\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
|
||||
|
||||
cookie.setPriority("");
|
||||
cookie.setSameSite(HTTPCookie::SAME_SITE_NONE);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; SameSite=None; HttpOnly; Version=\"1\"");
|
||||
cookie.setSameSite(HTTPCookie::SAME_SITE_LAX);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; SameSite=Lax; HttpOnly; Version=\"1\"");
|
||||
cookie.setSameSite(HTTPCookie::SAME_SITE_STRICT);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; SameSite=Strict; HttpOnly; Version=\"1\"");
|
||||
cookie.setSameSite(HTTPCookie::SAME_SITE_NOT_SPECIFIED);
|
||||
assertTrue (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testEscape()
|
||||
{
|
||||
std::string escaped = HTTPCookie::escape("this is a test.");
|
||||
assertTrue (escaped == "this%20is%20a%20test.");
|
||||
|
||||
escaped = HTTPCookie::escape("\n\t@,;\"'");
|
||||
assertTrue (escaped == "%0A%09@%2C%3B%22%27");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testUnescape()
|
||||
{
|
||||
std::string unescaped = HTTPCookie::unescape("this%20is%20a%20test!");
|
||||
assertTrue (unescaped == "this is a test!");
|
||||
|
||||
unescaped = HTTPCookie::unescape("%0a%09@%2c%3b%22%27");
|
||||
assertTrue (unescaped == "\n\t@,;\"'");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testExpiryFuture()
|
||||
{
|
||||
DateTime future;
|
||||
//1 year from now
|
||||
future.assign(future.year() + 1,
|
||||
future.month(),
|
||||
(future.month() == 2 && future.day() == 29) ? 28 : future.day(),
|
||||
future.hour(),
|
||||
future.minute(),
|
||||
future.second(),
|
||||
future.millisecond(),
|
||||
future.microsecond());
|
||||
testCookieExpiry(future);
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testExpiryPast()
|
||||
{
|
||||
DateTime past;
|
||||
// 1 year ago
|
||||
past.assign(past.year() - 1,
|
||||
past.month(),
|
||||
(past.month() == 2 && past.day() == 29) ? 28 : past.day(),
|
||||
past.hour(),
|
||||
past.minute(),
|
||||
past.second(),
|
||||
past.millisecond(),
|
||||
past.microsecond());
|
||||
testCookieExpiry(past);
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testCookieExpiry(DateTime expiryTime)
|
||||
{
|
||||
NameValueCollection nvc;
|
||||
nvc.add("name", "value");
|
||||
std::string expiryString = DateTimeFormatter::format(expiryTime.timestamp(),DateTimeFormat::HTTP_FORMAT);
|
||||
nvc.add("expires", expiryString);
|
||||
|
||||
Timestamp before; //start of cookie lifetime
|
||||
HTTPCookie cookie(nvc); //cookie created
|
||||
std::string cookieStringV0 = cookie.toString();
|
||||
cookie.setVersion(1);
|
||||
std::string cookieStringV1 = cookie.toString();
|
||||
Timestamp now;
|
||||
//expected number of seconds until expiryTime - should be close to cookie._maxAge
|
||||
int expectedMaxAge = (int) ((expiryTime.timestamp() - now) / Timestamp::resolution()); //expected number of seconds until expiryTime
|
||||
Timestamp after; //end of cookie lifetime
|
||||
|
||||
//length of lifetime of the cookie
|
||||
Timespan delta = after - before;
|
||||
|
||||
//pull out cookie expire time string
|
||||
size_t startPos = cookieStringV0.find("expires=") + 8;
|
||||
std::string cookieExpireTimeStr = cookieStringV0.substr(startPos, cookieStringV0.find(";", startPos));
|
||||
//convert to a DateTime
|
||||
int tzd;
|
||||
DateTime cookieExpireTime = DateTimeParser::parse(cookieExpireTimeStr, tzd);
|
||||
//pull out cookie max age
|
||||
int cookieMaxAge;
|
||||
startPos = cookieStringV1.find("Max-Age=\"") + 9;
|
||||
std::string cookieMaxAgeStr = cookieStringV1.substr(startPos, cookieStringV1.find("\"", startPos));
|
||||
//convert to integer
|
||||
std::istringstream(cookieMaxAgeStr) >> cookieMaxAge;
|
||||
|
||||
//assert that the cookie's expiry time reflects the time passed to
|
||||
//its constructor, within a delta of the lifetime of the cookie
|
||||
assertTrue (cookieExpireTime - expiryTime <= delta);
|
||||
//assert that the cookie's max age is the number of seconds between
|
||||
//the creation of the cookie and the expiry time passed to its
|
||||
//constuctor, within a delta of the lifetime of the cookie
|
||||
assertTrue (cookieMaxAge - expectedMaxAge <= delta.seconds());
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPCookieTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCookieTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testCookie);
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testEscape);
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testUnescape);
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testExpiryFuture);
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testExpiryPast);
|
||||
|
||||
return pSuite;
|
||||
}
|
44
vendor/POCO/Net/testsuite/src/HTTPCookieTest.h
vendored
Normal file
44
vendor/POCO/Net/testsuite/src/HTTPCookieTest.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// HTTPCookieTest.h
|
||||
//
|
||||
// Definition of the HTTPCookieTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPCookieTest_INCLUDED
|
||||
#define HTTPCookieTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPCookieTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPCookieTest(const std::string& name);
|
||||
~HTTPCookieTest();
|
||||
|
||||
void testCookie();
|
||||
void testEscape();
|
||||
void testUnescape();
|
||||
void testExpiryFuture();
|
||||
void testExpiryPast();
|
||||
void testCookieExpiry(Poco::DateTime expiryTime);
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPCookieTest_INCLUDED
|
346
vendor/POCO/Net/testsuite/src/HTTPCredentialsTest.cpp
vendored
Normal file
346
vendor/POCO/Net/testsuite/src/HTTPCredentialsTest.cpp
vendored
Normal file
@ -0,0 +1,346 @@
|
||||
//
|
||||
// HTTPCredentialsTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPCredentialsTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPBasicCredentials.h"
|
||||
#include "Poco/Net/HTTPAuthenticationParams.h"
|
||||
#include "Poco/Net/HTTPDigestCredentials.h"
|
||||
#include "Poco/Net/HTTPCredentials.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/URI.h"
|
||||
|
||||
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPBasicCredentials;
|
||||
using Poco::Net::HTTPAuthenticationParams;
|
||||
using Poco::Net::HTTPDigestCredentials;
|
||||
using Poco::Net::HTTPCredentials;
|
||||
using Poco::Net::NotAuthenticatedException;
|
||||
|
||||
|
||||
HTTPCredentialsTest::HTTPCredentialsTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPCredentialsTest::~HTTPCredentialsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testBasicCredentials()
|
||||
{
|
||||
HTTPRequest request;
|
||||
assertTrue (!request.hasCredentials());
|
||||
|
||||
HTTPBasicCredentials cred("user", "secret");
|
||||
cred.authenticate(request);
|
||||
assertTrue (request.hasCredentials());
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
request.getCredentials(scheme, info);
|
||||
assertTrue (scheme == "Basic");
|
||||
assertTrue (info == "dXNlcjpzZWNyZXQ=");
|
||||
|
||||
HTTPBasicCredentials cred2(request);
|
||||
assertTrue (cred2.getUsername() == "user");
|
||||
assertTrue (cred2.getPassword() == "secret");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testProxyBasicCredentials()
|
||||
{
|
||||
HTTPRequest request;
|
||||
assertTrue (!request.hasProxyCredentials());
|
||||
|
||||
HTTPBasicCredentials cred("user", "secret");
|
||||
cred.proxyAuthenticate(request);
|
||||
assertTrue (request.hasProxyCredentials());
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
request.getProxyCredentials(scheme, info);
|
||||
assertTrue (scheme == "Basic");
|
||||
assertTrue (info == "dXNlcjpzZWNyZXQ=");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testBadCredentials()
|
||||
{
|
||||
HTTPRequest request;
|
||||
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
try
|
||||
{
|
||||
request.getCredentials(scheme, info);
|
||||
fail("no credentials - must throw");
|
||||
}
|
||||
catch (NotAuthenticatedException&)
|
||||
{
|
||||
}
|
||||
|
||||
request.setCredentials("Test", "SomeData");
|
||||
request.getCredentials(scheme, info);
|
||||
assertTrue (scheme == "Test");
|
||||
assertTrue (info == "SomeData");
|
||||
|
||||
try
|
||||
{
|
||||
HTTPBasicCredentials cred(request);
|
||||
fail("bad scheme - must throw");
|
||||
}
|
||||
catch (NotAuthenticatedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testAuthenticationParams()
|
||||
{
|
||||
const std::string authInfo("nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"40e4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
|
||||
HTTPAuthenticationParams params(authInfo);
|
||||
|
||||
assertTrue (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
|
||||
assertTrue (params["realm"] == "TestDigest");
|
||||
assertTrue (params["response"] == "40e4889cfbd0e561f71e3107a2863bc4");
|
||||
assertTrue (params["uri"] == "/digest/");
|
||||
assertTrue (params["username"] == "user");
|
||||
assertTrue (params.size() == 5);
|
||||
assertTrue (params.toString() == authInfo);
|
||||
|
||||
params.clear();
|
||||
HTTPRequest request;
|
||||
request.set("Authorization", "Digest " + authInfo);
|
||||
params.fromRequest(request);
|
||||
|
||||
assertTrue (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
|
||||
assertTrue (params["realm"] == "TestDigest");
|
||||
assertTrue (params["response"] == "40e4889cfbd0e561f71e3107a2863bc4");
|
||||
assertTrue (params["uri"] == "/digest/");
|
||||
assertTrue (params["username"] == "user");
|
||||
assertTrue (params.size() == 5);
|
||||
|
||||
params.clear();
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
params.fromResponse(response);
|
||||
|
||||
assertTrue (params["realm"] == "TestDigest");
|
||||
assertTrue (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
|
||||
assertTrue (params.size() == 2);
|
||||
|
||||
params.clear();
|
||||
response.set("WWW-Authenticate", "NTLM TlRMTVNTUAACAAAADAAMADAAAAABAoEAASNFZ4mrze8AAAAAAAAAAGIAYgA8AAAARABPAE0AQQBJAE4AAgAMAEQATwBNAEEASQBOAAEADABTAEUAUgBWAEUAUgAEABQAZABvAG0AYQBpAG4ALgBjAG8AbQADACIAcwBlAHIAdgBlAHIALgBkAG8AbQBhAGkAbgAuAGMAbwBtAAAAAAA");
|
||||
params.fromResponse(response);
|
||||
|
||||
assertTrue (params["NTLM"] == "TlRMTVNTUAACAAAADAAMADAAAAABAoEAASNFZ4mrze8AAAAAAAAAAGIAYgA8AAAARABPAE0AQQBJAE4AAgAMAEQATwBNAEEASQBOAAEADABTAEUAUgBWAEUAUgAEABQAZABvAG0AYQBpAG4ALgBjAG8AbQADACIAcwBlAHIAdgBlAHIALgBkAG8AbQBhAGkAbgAuAGMAbwBtAAAAAAA");
|
||||
assertTrue (params.size() == 1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testAuthenticationParamsMultipleHeaders()
|
||||
{
|
||||
HTTPResponse response;
|
||||
response.add("WWW-Authenticate", "Unsupported realm=\"TestUnsupported\"");
|
||||
response.add("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
HTTPAuthenticationParams params(response);
|
||||
|
||||
assertTrue (params["realm"] == "TestDigest");
|
||||
assertTrue (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
|
||||
assertTrue (params.size() == 2);
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testDigestCredentials()
|
||||
{
|
||||
HTTPDigestCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.authenticate(request, response);
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testDigestCredentialsQoP()
|
||||
{
|
||||
HTTPDigestCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\", opaque=\"opaque\", qop=\"auth,auth-int\"");
|
||||
creds.authenticate(request, response);
|
||||
|
||||
HTTPAuthenticationParams params(request);
|
||||
assertTrue (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
|
||||
assertTrue (params["realm"] == "TestDigest");
|
||||
assertTrue (params["response"] != "40e4889cfbd0e561f71e3107a2863bc4");
|
||||
assertTrue (params["uri"] == "/digest/");
|
||||
assertTrue (params["username"] == "user");
|
||||
assertTrue (params["opaque"] == "opaque");
|
||||
assertTrue (params["cnonce"] != "");
|
||||
assertTrue (params["nc"] == "00000001");
|
||||
assertTrue (params["qop"] == "auth");
|
||||
assertTrue (params.size() == 9);
|
||||
|
||||
std::string cnonce = params["cnonce"];
|
||||
std::string aresp = params["response"];
|
||||
|
||||
params.clear();
|
||||
|
||||
creds.updateAuthInfo(request);
|
||||
params.fromRequest(request);
|
||||
assertTrue (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
|
||||
assertTrue (params["realm"] == "TestDigest");
|
||||
assertTrue (params["response"] != aresp);
|
||||
assertTrue (params["uri"] == "/digest/");
|
||||
assertTrue (params["username"] == "user");
|
||||
assertTrue (params["opaque"] == "opaque");
|
||||
assertTrue (params["cnonce"] == cnonce);
|
||||
assertTrue (params["nc"] == "00000002");
|
||||
assertTrue (params["qop"] == "auth");
|
||||
assertTrue (params.size() == 9);
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testCredentialsBasic()
|
||||
{
|
||||
HTTPCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/basic/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Basic realm=\"TestBasic\"");
|
||||
creds.authenticate(request, response);
|
||||
assertTrue (request.get("Authorization") == "Basic dXNlcjpzM2NyM3Q=");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testProxyCredentialsBasic()
|
||||
{
|
||||
HTTPCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/basic/");
|
||||
HTTPResponse response;
|
||||
response.set("Proxy-Authenticate", "Basic realm=\"TestBasic\"");
|
||||
creds.proxyAuthenticate(request, response);
|
||||
assertTrue (request.get("Proxy-Authorization") == "Basic dXNlcjpzM2NyM3Q=");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testCredentialsDigest()
|
||||
{
|
||||
HTTPCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.authenticate(request, response);
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testCredentialsDigestMultipleHeaders()
|
||||
{
|
||||
HTTPCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.add("WWW-Authenticate", "Unsupported realm=\"TestUnsupported\"");
|
||||
response.add("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.authenticate(request, response);
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testProxyCredentialsDigest()
|
||||
{
|
||||
HTTPCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("Proxy-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.proxyAuthenticate(request, response);
|
||||
assertTrue (request.get("Proxy-Authorization") == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testExtractCredentials()
|
||||
{
|
||||
Poco::URI uri("http://user:s3cr3t@host.com/");
|
||||
std::string username;
|
||||
std::string password;
|
||||
HTTPCredentials::extractCredentials(uri, username, password);
|
||||
assertTrue (username == "user");
|
||||
assertTrue (password == "s3cr3t");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testVerifyAuthInfo()
|
||||
{
|
||||
HTTPDigestCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.authenticate(request, response);
|
||||
assertTrue (creds.verifyAuthInfo(request));
|
||||
|
||||
request.set("Authorization", "Digest nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"xxe4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
|
||||
assertTrue (!creds.verifyAuthInfo(request));
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testVerifyAuthInfoQoP()
|
||||
{
|
||||
HTTPDigestCredentials creds("user", "s3cr3t");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\", opaque=\"opaque\", qop=\"auth,auth-int\"");
|
||||
creds.authenticate(request, response);
|
||||
assertTrue (creds.verifyAuthInfo(request));
|
||||
|
||||
request.set("Authorization", "Digest cnonce=\"f9c80ffd1c3bc4ee47ed92b704ba75a4\", nc=00000001, nonce=\"212573bb90170538efad012978ab811f%lu\", opaque=\"opaque\", qop=\"auth\", realm=\"TestDigest\", response=\"ff0e90b9aa019120ea0ed6e23ce95d9a\", uri=\"/digest/\", username=\"user\"");
|
||||
assertTrue (!creds.verifyAuthInfo(request));
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPCredentialsTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCredentialsTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testBasicCredentials);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testProxyBasicCredentials);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testBadCredentials);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testAuthenticationParams);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testAuthenticationParamsMultipleHeaders);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testDigestCredentials);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testDigestCredentialsQoP);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testCredentialsBasic);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testProxyCredentialsBasic);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testCredentialsDigest);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testCredentialsDigestMultipleHeaders);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testProxyCredentialsDigest);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testExtractCredentials);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testVerifyAuthInfo);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testVerifyAuthInfoQoP);
|
||||
|
||||
return pSuite;
|
||||
}
|
52
vendor/POCO/Net/testsuite/src/HTTPCredentialsTest.h
vendored
Normal file
52
vendor/POCO/Net/testsuite/src/HTTPCredentialsTest.h
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// HTTPCredentialsTest.h
|
||||
//
|
||||
// Definition of the HTTPCredentialsTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPCredentialsTest_INCLUDED
|
||||
#define HTTPCredentialsTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPCredentialsTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPCredentialsTest(const std::string& name);
|
||||
~HTTPCredentialsTest();
|
||||
|
||||
void testBasicCredentials();
|
||||
void testProxyBasicCredentials();
|
||||
void testBadCredentials();
|
||||
void testAuthenticationParams();
|
||||
void testAuthenticationParamsMultipleHeaders();
|
||||
void testDigestCredentials();
|
||||
void testDigestCredentialsQoP();
|
||||
void testCredentialsBasic();
|
||||
void testProxyCredentialsBasic();
|
||||
void testCredentialsDigest();
|
||||
void testCredentialsDigestMultipleHeaders();
|
||||
void testProxyCredentialsDigest();
|
||||
void testExtractCredentials();
|
||||
void testVerifyAuthInfo();
|
||||
void testVerifyAuthInfoQoP();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPCredentialsTest_INCLUDED
|
267
vendor/POCO/Net/testsuite/src/HTTPRequestTest.cpp
vendored
Normal file
267
vendor/POCO/Net/testsuite/src/HTTPRequestTest.cpp
vendored
Normal file
@ -0,0 +1,267 @@
|
||||
//
|
||||
// HTTPRequestTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPRequestTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::MessageException;
|
||||
using Poco::Net::NameValueCollection;
|
||||
|
||||
|
||||
HTTPRequestTest::HTTPRequestTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPRequestTest::~HTTPRequestTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite1()
|
||||
{
|
||||
HTTPRequest request;
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "GET / HTTP/1.0\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite2()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/index.html", HTTPMessage::HTTP_1_1);
|
||||
request.setHost("localhost", 80);
|
||||
request.setKeepAlive(true);
|
||||
request.set("User-Agent", "Poco");
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "HEAD /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: Keep-Alive\r\nUser-Agent: Poco\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite3()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/test.cgi", HTTPMessage::HTTP_1_1);
|
||||
request.setHost("localhost", 8000);
|
||||
request.setKeepAlive(false);
|
||||
request.set("User-Agent", "Poco");
|
||||
request.setContentLength(100);
|
||||
request.setContentType("text/plain");
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "POST /test.cgi HTTP/1.1\r\nHost: localhost:8000\r\nConnection: Close\r\nUser-Agent: Poco\r\nContent-Length: 100\r\nContent-Type: text/plain\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite4()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/index.html", HTTPMessage::HTTP_1_1);
|
||||
request.setHost("fe80::1", 88);
|
||||
request.setKeepAlive(true);
|
||||
request.set("User-Agent", "Poco");
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "HEAD /index.html HTTP/1.1\r\nHost: [fe80::1]:88\r\nConnection: Keep-Alive\r\nUser-Agent: Poco\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead1()
|
||||
{
|
||||
std::string s("GET / HTTP/1.0\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assertTrue (request.getMethod() == HTTPRequest::HTTP_GET);
|
||||
assertTrue (request.getURI() == "/");
|
||||
assertTrue (request.getVersion() == HTTPMessage::HTTP_1_0);
|
||||
assertTrue (request.empty());
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead2()
|
||||
{
|
||||
std::string s("HEAD /index.html HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: localhost\r\nUser-Agent: Poco\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assertTrue (request.getMethod() == HTTPRequest::HTTP_HEAD);
|
||||
assertTrue (request.getURI() == "/index.html");
|
||||
assertTrue (request.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assertTrue (request.size() == 3);
|
||||
assertTrue (request["Connection"] == "Keep-Alive");
|
||||
assertTrue (request["Host"] == "localhost");
|
||||
assertTrue (request["User-Agent"] == "Poco");
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead3()
|
||||
{
|
||||
std::string s("POST /test.cgi HTTP/1.1\r\nConnection: Close\r\nContent-Length: 100\r\nContent-Type: text/plain\r\nHost: localhost:8000\r\nUser-Agent: Poco\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assertTrue (request.getMethod() == HTTPRequest::HTTP_POST);
|
||||
assertTrue (request.getURI() == "/test.cgi");
|
||||
assertTrue (request.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assertTrue (request.size() == 5);
|
||||
assertTrue (request["Connection"] == "Close");
|
||||
assertTrue (request["Host"] == "localhost:8000");
|
||||
assertTrue (request["User-Agent"] == "Poco");
|
||||
assertTrue (request.getContentType() == "text/plain");
|
||||
assertTrue (request.getContentLength() == 100);
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead4()
|
||||
{
|
||||
std::string s("POST /test.cgi HTTP/1.1\r\nConnection: Close\r\nContent-Length: 100 \r\nContent-Type: text/plain\r\nHost: localhost:8000\r\nUser-Agent: Poco\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assertTrue (request.getMethod() == HTTPRequest::HTTP_POST);
|
||||
assertTrue (request.getURI() == "/test.cgi");
|
||||
assertTrue (request.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assertTrue (request.size() == 5);
|
||||
assertTrue (request["Connection"] == "Close");
|
||||
assertTrue (request["Host"] == "localhost:8000");
|
||||
assertTrue (request["User-Agent"] == "Poco");
|
||||
assertTrue (request.getContentType() == "text/plain");
|
||||
assertTrue (request.getContentLength() == 100);
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testInvalid1()
|
||||
{
|
||||
std::string s(256, 'x');
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
try
|
||||
{
|
||||
request.read(istr);
|
||||
fail("inavalid request - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testInvalid2()
|
||||
{
|
||||
std::string s("GET ");
|
||||
s.append(8000, 'x');
|
||||
s.append("HTTP/1.0");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
try
|
||||
{
|
||||
request.read(istr);
|
||||
fail("inavalid request - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testInvalid3()
|
||||
{
|
||||
std::string s("GET / HTTP/1.10");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
try
|
||||
{
|
||||
request.read(istr);
|
||||
fail("inavalid request - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testCookies()
|
||||
{
|
||||
HTTPRequest request1;
|
||||
NameValueCollection cookies1;
|
||||
cookies1.add("cookie1", "value1");
|
||||
request1.setCookies(cookies1);
|
||||
assertTrue (request1["Cookie"] == "cookie1=value1");
|
||||
|
||||
HTTPRequest request2;
|
||||
NameValueCollection cookies2;
|
||||
cookies2.add("cookie2", "value2");
|
||||
cookies2.add("cookie3", "value3");
|
||||
request2.setCookies(cookies2);
|
||||
assertTrue (request2["Cookie"] == "cookie2=value2; cookie3=value3");
|
||||
|
||||
request1.setCookies(cookies2);
|
||||
NameValueCollection cookies3;
|
||||
request1.getCookies(cookies3);
|
||||
assertTrue (cookies3.size() == 3);
|
||||
assertTrue (cookies3["cookie1"] == "value1");
|
||||
assertTrue (cookies3["cookie2"] == "value2");
|
||||
assertTrue (cookies3["cookie3"] == "value3");
|
||||
|
||||
HTTPRequest request3;
|
||||
request3.add("Cookie", "cookie1=value1");
|
||||
request3.add("cookie", "cookie2=value2");
|
||||
NameValueCollection cookies4;
|
||||
request3.getCookies(cookies4);
|
||||
assertTrue (cookies4.size() == 2);
|
||||
assertTrue (cookies4["cookie1"] == "value1");
|
||||
assertTrue (cookies4["cookie2"] == "value2");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPRequestTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPRequestTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite4);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead4);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testCookies);
|
||||
|
||||
return pSuite;
|
||||
}
|
49
vendor/POCO/Net/testsuite/src/HTTPRequestTest.h
vendored
Normal file
49
vendor/POCO/Net/testsuite/src/HTTPRequestTest.h
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// HTTPRequestTest.h
|
||||
//
|
||||
// Definition of the HTTPRequestTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPRequestTest_INCLUDED
|
||||
#define HTTPRequestTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPRequestTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPRequestTest(const std::string& name);
|
||||
~HTTPRequestTest();
|
||||
|
||||
void testWrite1();
|
||||
void testWrite2();
|
||||
void testWrite3();
|
||||
void testWrite4();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testRead4();
|
||||
void testInvalid1();
|
||||
void testInvalid2();
|
||||
void testInvalid3();
|
||||
void testCookies();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPRequestTest_INCLUDED
|
229
vendor/POCO/Net/testsuite/src/HTTPResponseTest.cpp
vendored
Normal file
229
vendor/POCO/Net/testsuite/src/HTTPResponseTest.cpp
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
//
|
||||
// HTTPResponseTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPResponseTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPCookie.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::HTTPCookie;
|
||||
using Poco::Net::MessageException;
|
||||
|
||||
|
||||
HTTPResponseTest::HTTPResponseTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPResponseTest::~HTTPResponseTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testWrite1()
|
||||
{
|
||||
HTTPResponse response;
|
||||
std::ostringstream ostr;
|
||||
response.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "HTTP/1.0 200 OK\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testWrite2()
|
||||
{
|
||||
HTTPResponse response(HTTPMessage::HTTP_1_1, HTTPResponse::HTTP_MOVED_PERMANENTLY);
|
||||
response.set("Location", "http://www.appinf.com/index.html");
|
||||
response.set("Server", "Poco/1.0");
|
||||
std::ostringstream ostr;
|
||||
response.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.appinf.com/index.html\r\nServer: Poco/1.0\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testRead1()
|
||||
{
|
||||
std::string s("HTTP/1.1 500 Internal Server Error\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
response.read(istr);
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
||||
assertTrue (response.getReason() == "Internal Server Error");
|
||||
assertTrue (response.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assertTrue (response.empty());
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testRead2()
|
||||
{
|
||||
std::string s("HTTP/1.0 301 Moved Permanently\r\nLocation: http://www.appinf.com/index.html\r\nServer: Poco/1.0\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
response.read(istr);
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY);
|
||||
assertTrue (response.getReason() == "Moved Permanently");
|
||||
assertTrue (response.getVersion() == HTTPMessage::HTTP_1_0);
|
||||
assertTrue (response.size() == 2);
|
||||
assertTrue (response["Location"] == "http://www.appinf.com/index.html");
|
||||
assertTrue (response["Server"] == "Poco/1.0");
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testRead3()
|
||||
{
|
||||
std::string s("HTTP/1.1 200 \r\nContent-Length: 0\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
response.read(istr);
|
||||
assertTrue (response.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_OK);
|
||||
assertTrue (response.getReason() == "");
|
||||
assertTrue (response.size() == 1);
|
||||
assertTrue (response.getContentLength() == 0);
|
||||
assertTrue (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testInvalid1()
|
||||
{
|
||||
std::string s(256, 'x');
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
try
|
||||
{
|
||||
response.read(istr);
|
||||
fail("inavalid response - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testInvalid2()
|
||||
{
|
||||
std::string s("HTTP/1.1 200 ");
|
||||
s.append(1000, 'x');
|
||||
s.append("\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
try
|
||||
{
|
||||
response.read(istr);
|
||||
fail("inavalid response - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testInvalid3()
|
||||
{
|
||||
std::string s("HTTP/1.0 ");
|
||||
s.append(8000, 'x');
|
||||
s.append("\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
try
|
||||
{
|
||||
response.read(istr);
|
||||
fail("inavalid response - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testCookies()
|
||||
{
|
||||
HTTPResponse response;
|
||||
HTTPCookie cookie1("cookie1", "value1");
|
||||
response.addCookie(cookie1);
|
||||
std::vector<HTTPCookie> cookies;
|
||||
response.getCookies(cookies);
|
||||
assertTrue (cookies.size() == 1);
|
||||
assertTrue (cookie1.getVersion() == cookies[0].getVersion());
|
||||
assertTrue (cookie1.getName() == cookies[0].getName());
|
||||
assertTrue (cookie1.getValue() == cookies[0].getValue());
|
||||
assertTrue (cookie1.getComment() == cookies[0].getComment());
|
||||
assertTrue (cookie1.getDomain() == cookies[0].getDomain());
|
||||
assertTrue (cookie1.getPath() == cookies[0].getPath());
|
||||
assertTrue (cookie1.getSecure() == cookies[0].getSecure());
|
||||
assertTrue (cookie1.getMaxAge() == cookies[0].getMaxAge());
|
||||
|
||||
HTTPCookie cookie2("cookie2", "value2");
|
||||
cookie2.setVersion(1);
|
||||
cookie2.setMaxAge(42);
|
||||
cookie2.setSecure(true);
|
||||
response.addCookie(cookie2);
|
||||
response.getCookies(cookies);
|
||||
assertTrue (cookies.size() == 2);
|
||||
HTTPCookie cookie2a;
|
||||
if (cookies[0].getName() == cookie2.getName())
|
||||
cookie2a = cookies[0];
|
||||
else
|
||||
cookie2a = cookies[1];
|
||||
assertTrue (cookie2.getVersion() == cookie2a.getVersion());
|
||||
assertTrue (cookie2.getName() == cookie2a.getName());
|
||||
assertTrue (cookie2.getValue() == cookie2a.getValue());
|
||||
assertTrue (cookie2.getComment() == cookie2a.getComment());
|
||||
assertTrue (cookie2.getDomain() == cookie2a.getDomain());
|
||||
assertTrue (cookie2.getPath() == cookie2a.getPath());
|
||||
assertTrue (cookie2.getSecure() == cookie2a.getSecure());
|
||||
assertTrue (cookie2.getMaxAge() == cookie2a.getMaxAge());
|
||||
|
||||
HTTPResponse response2;
|
||||
response2.add("Set-Cookie", "name1=value1");
|
||||
response2.add("Set-cookie", "name2=value2");
|
||||
cookies.clear();
|
||||
response2.getCookies(cookies);
|
||||
assertTrue (cookies.size() == 2);
|
||||
assertTrue (((cookies[0].getName() == "name1") && (cookies[1].getName() == "name2"))
|
||||
|| ((cookies[0].getName() == "name2") && (cookies[1].getName() == "name1")));
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPResponseTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPResponseTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testWrite1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testWrite2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testRead1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testRead2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testRead3);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid3);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testCookies);
|
||||
|
||||
return pSuite;
|
||||
}
|
46
vendor/POCO/Net/testsuite/src/HTTPResponseTest.h
vendored
Normal file
46
vendor/POCO/Net/testsuite/src/HTTPResponseTest.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// HTTPResponseTest.h
|
||||
//
|
||||
// Definition of the HTTPResponseTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPResponseTest_INCLUDED
|
||||
#define HTTPResponseTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPResponseTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPResponseTest(const std::string& name);
|
||||
~HTTPResponseTest();
|
||||
|
||||
void testWrite1();
|
||||
void testWrite2();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testInvalid1();
|
||||
void testInvalid2();
|
||||
void testInvalid3();
|
||||
void testCookies();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPResponseTest_INCLUDED
|
549
vendor/POCO/Net/testsuite/src/HTTPServerTest.cpp
vendored
Normal file
549
vendor/POCO/Net/testsuite/src/HTTPServerTest.cpp
vendored
Normal file
@ -0,0 +1,549 @@
|
||||
//
|
||||
// HTTPServerTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPServerTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPServer.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
#include "Poco/Net/AbstractHTTPRequestHandler.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPServer;
|
||||
using Poco::Net::HTTPServerParams;
|
||||
using Poco::Net::HTTPRequestHandler;
|
||||
using Poco::Net::AbstractHTTPRequestHandler;
|
||||
using Poco::Net::HTTPRequestHandlerFactory;
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPServerRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPServerResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class EchoBodyRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
if (request.getChunkedTransferEncoding())
|
||||
response.setChunkedTransferEncoding(true);
|
||||
else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
|
||||
response.setContentLength(request.getContentLength());
|
||||
|
||||
response.setContentType(request.getContentType());
|
||||
|
||||
std::istream& istr = request.stream();
|
||||
std::ostream& ostr = response.send();
|
||||
StreamCopier::copyStream(istr, ostr);
|
||||
}
|
||||
};
|
||||
|
||||
class EchoHeaderRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
std::ostringstream osstr;
|
||||
request.write(osstr);
|
||||
int n = (int) osstr.str().length();
|
||||
response.setContentLength(n);
|
||||
std::ostream& ostr = response.send();
|
||||
if (request.getMethod() != HTTPRequest::HTTP_HEAD)
|
||||
request.write(ostr);
|
||||
}
|
||||
};
|
||||
|
||||
class RedirectRequestHandler: public AbstractHTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void run()
|
||||
{
|
||||
response().redirect("http://www.appinf.com/");
|
||||
}
|
||||
};
|
||||
|
||||
class AuthRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
response.requireAuthentication("/auth");
|
||||
response.send();
|
||||
}
|
||||
};
|
||||
|
||||
class BufferRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
std::string data("xxxxxxxxxx");
|
||||
response.sendBuffer(data.data(), data.length());
|
||||
}
|
||||
};
|
||||
|
||||
class RequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||
{
|
||||
public:
|
||||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||
{
|
||||
if (request.getURI() == "/echoBody")
|
||||
return new EchoBodyRequestHandler;
|
||||
else if (request.getURI() == "/echoHeader")
|
||||
return new EchoHeaderRequestHandler;
|
||||
else if (request.getURI() == "/redirect")
|
||||
return new RedirectRequestHandler();
|
||||
else if (request.getURI() == "/auth")
|
||||
return new AuthRequestHandler();
|
||||
else if (request.getURI() == "/buffer")
|
||||
return new BufferRequestHandler();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
HTTPServerTest::HTTPServerTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPServerTest::~HTTPServerTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testIdentityRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == body.size());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testPutIdentityRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("PUT", "/echoBody");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == body.size());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testChunkedRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testClosedRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", 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;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (!response.getChunkedTransferEncoding());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testIdentityRequestKeepAlive()
|
||||
{
|
||||
HTTPServer srv(new RequestHandlerFactory, 8008);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", srv.socket().address().port());
|
||||
cs.setKeepAlive(true);
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == body.size());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
|
||||
body.assign(1000, 'y');
|
||||
request.setContentLength((int) body.length());
|
||||
request.setKeepAlive(false);
|
||||
cs.sendRequest(request) << body;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == body.size());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (!response.getKeepAlive());
|
||||
assertTrue (rbody == body);}
|
||||
|
||||
|
||||
void HTTPServerTest::testChunkedRequestKeepAlive()
|
||||
{
|
||||
HTTPServer srv(new RequestHandlerFactory, 8009);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", srv.socket().address().port());
|
||||
cs.setKeepAlive(true);
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (rbody == body);
|
||||
|
||||
body.assign(1000, 'y');
|
||||
request.setKeepAlive(false);
|
||||
cs.sendRequest(request) << body;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (!response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testClosedRequestKeepAlive()
|
||||
{
|
||||
HTTPServer srv(new RequestHandlerFactory, 8010);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", srv.socket().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;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (!response.getChunkedTransferEncoding());
|
||||
assertTrue (!response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testMaxKeepAlive()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
pParams->setMaxKeepAliveRequests(4);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
cs.setKeepAlive(true);
|
||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
std::string body(5000, 'x');
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
{
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (!response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
{
|
||||
cs.setKeepAlive(false);
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (!response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testKeepAliveTimeout()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
pParams->setMaxKeepAliveRequests(4);
|
||||
pParams->setKeepAliveTimeout(Poco::Timespan(3, 0));
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
cs.setKeepAlive(true);
|
||||
cs.setKeepAliveTimeout(Poco::Timespan(2, 0));
|
||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
std::string body(5000, 'x');
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
Poco::Thread::sleep(4000);
|
||||
|
||||
{
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (response.getChunkedTransferEncoding());
|
||||
assertTrue (response.getKeepAlive());
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::test100Continue()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
request.set("Expect", "100-Continue");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getContentLength() == body.size());
|
||||
assertTrue (response.getContentType() == "text/plain");
|
||||
assertTrue (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testRedirect()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
HTTPRequest request("GET", "/redirect");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_FOUND);
|
||||
assertTrue (response.get("Location") == "http://www.appinf.com/");
|
||||
assertTrue (rbody.empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testAuth()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
HTTPRequest request("GET", "/auth");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED);
|
||||
assertTrue (response.get("WWW-Authenticate") == "Basic realm=\"/auth\"");
|
||||
assertTrue (rbody.empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testNotImpl()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
HTTPRequest request("GET", "/notImpl");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_NOT_IMPLEMENTED);
|
||||
assertTrue (rbody.empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testBuffer()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("127.0.0.1", svs.address().port());
|
||||
HTTPRequest request("GET", "/buffer");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assertTrue (response.getStatus() == HTTPResponse::HTTP_OK);
|
||||
assertTrue (rbody == "xxxxxxxxxx");
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPServerTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPServerTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testIdentityRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testPutIdentityRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testChunkedRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testClosedRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testIdentityRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testChunkedRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testClosedRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testMaxKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testKeepAliveTimeout);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, test100Continue);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testAuth);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testNotImpl);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testBuffer);
|
||||
|
||||
return pSuite;
|
||||
}
|
51
vendor/POCO/Net/testsuite/src/HTTPServerTest.h
vendored
Normal file
51
vendor/POCO/Net/testsuite/src/HTTPServerTest.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// HTTPServerTest.h
|
||||
//
|
||||
// Definition of the HTTPServerTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPServerTest_INCLUDED
|
||||
#define HTTPServerTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPServerTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPServerTest(const std::string& name);
|
||||
~HTTPServerTest();
|
||||
|
||||
void testIdentityRequest();
|
||||
void testPutIdentityRequest();
|
||||
void testChunkedRequest();
|
||||
void testClosedRequest();
|
||||
void testIdentityRequestKeepAlive();
|
||||
void testChunkedRequestKeepAlive();
|
||||
void testClosedRequestKeepAlive();
|
||||
void testMaxKeepAlive();
|
||||
void testKeepAliveTimeout();
|
||||
void test100Continue();
|
||||
void testRedirect();
|
||||
void testAuth();
|
||||
void testNotImpl();
|
||||
void testBuffer();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPServerTest_INCLUDED
|
22
vendor/POCO/Net/testsuite/src/HTTPServerTestSuite.cpp
vendored
Normal file
22
vendor/POCO/Net/testsuite/src/HTTPServerTestSuite.cpp
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// HTTPServerTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPServerTestSuite.h"
|
||||
#include "HTTPServerTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTTPServerTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPServerTestSuite");
|
||||
|
||||
pSuite->addTest(HTTPServerTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/HTTPServerTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/HTTPServerTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// HTTPServerTestSuite.h
|
||||
//
|
||||
// Definition of the HTTPServerTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPServerTestSuite_INCLUDED
|
||||
#define HTTPServerTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTTPServerTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPServerTestSuite_INCLUDED
|
133
vendor/POCO/Net/testsuite/src/HTTPStreamFactoryTest.cpp
vendored
Normal file
133
vendor/POCO/Net/testsuite/src/HTTPStreamFactoryTest.cpp
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
//
|
||||
// HTTPStreamFactoryTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPStreamFactoryTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPStreamFactory.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/URIStreamOpener.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "HTTPTestServer.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using Poco::Net::HTTPStreamFactory;
|
||||
using Poco::Net::NetException;
|
||||
using Poco::Net::HTTPException;
|
||||
using Poco::URI;
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
HTTPStreamFactoryTest::HTTPStreamFactoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPStreamFactoryTest::~HTTPStreamFactoryTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testNoRedirect()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://127.0.0.1/large");
|
||||
uri.setPort(server.port());
|
||||
std::unique_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testEmptyPath()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://127.0.0.1");
|
||||
uri.setPort(server.port());
|
||||
std::unique_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::SMALL_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testRedirect()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
Poco::URIStreamOpener opener;
|
||||
opener.registerStreamFactory("http", new HTTPStreamFactory);
|
||||
URI uri("http://127.0.0.1/redirect");
|
||||
uri.setPort(server.port());
|
||||
std::unique_ptr<std::istream> pStr(opener.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testProxy()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory("127.0.0.1", server.port());
|
||||
URI uri("http://www.somehost.com/large");
|
||||
std::unique_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assertTrue (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testError()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://127.0.0.1/notfound");
|
||||
uri.setPort(server.port());
|
||||
try
|
||||
{
|
||||
std::istream* pStr = factory.open(uri);
|
||||
fail("not found - must throw");
|
||||
pStr = pStr + 0; // to silence gcc
|
||||
}
|
||||
catch (HTTPException& exc)
|
||||
{
|
||||
std::string m = exc.displayText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPStreamFactoryTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPStreamFactoryTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testNoRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testEmptyPath);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testProxy);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testError);
|
||||
|
||||
return pSuite;
|
||||
}
|
42
vendor/POCO/Net/testsuite/src/HTTPStreamFactoryTest.h
vendored
Normal file
42
vendor/POCO/Net/testsuite/src/HTTPStreamFactoryTest.h
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// HTTPStreamFactoryTest.h
|
||||
//
|
||||
// Definition of the HTTPStreamFactoryTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPStreamFactoryTest_INCLUDED
|
||||
#define HTTPStreamFactoryTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPStreamFactoryTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPStreamFactoryTest(const std::string& name);
|
||||
~HTTPStreamFactoryTest();
|
||||
|
||||
void testNoRedirect();
|
||||
void testEmptyPath();
|
||||
void testRedirect();
|
||||
void testProxy();
|
||||
void testError();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPStreamFactoryTest_INCLUDED
|
253
vendor/POCO/Net/testsuite/src/HTTPTestServer.cpp
vendored
Normal file
253
vendor/POCO/Net/testsuite/src/HTTPTestServer.cpp
vendored
Normal file
@ -0,0 +1,253 @@
|
||||
//
|
||||
// HTTPTestServer.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPTestServer.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::NumberFormatter;
|
||||
|
||||
|
||||
const std::string HTTPTestServer::SMALL_BODY("This is some random text data returned by the server");
|
||||
const std::string HTTPTestServer::LARGE_BODY(4000, 'x');
|
||||
|
||||
|
||||
HTTPTestServer::HTTPTestServer():
|
||||
_socket(SocketAddress()),
|
||||
_thread("HTTPTestServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
_lastRequest.reserve(4000);
|
||||
}
|
||||
|
||||
|
||||
HTTPTestServer::~HTTPTestServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 HTTPTestServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
const std::string& HTTPTestServer::lastRequest() const
|
||||
{
|
||||
return _lastRequest;
|
||||
}
|
||||
|
||||
|
||||
void HTTPTestServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
StreamSocket ss = _socket.acceptConnection();
|
||||
try
|
||||
{
|
||||
_lastRequest.clear();
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
while (n > 0 && !_stop)
|
||||
{
|
||||
_lastRequest.append(buffer, n);
|
||||
if (!requestComplete())
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
std::string response = handleRequest();
|
||||
ss.sendBytes(response.data(), (int) response.size());
|
||||
Poco::Thread::sleep(1000);
|
||||
try
|
||||
{
|
||||
ss.shutdown();
|
||||
Poco::Thread::sleep(1000);
|
||||
}
|
||||
catch (Poco::Exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "HTTPTestServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool HTTPTestServer::requestComplete() const
|
||||
{
|
||||
return ((_lastRequest.substr(0, 3) == "GET" || _lastRequest.substr(0, 4) == "HEAD") &&
|
||||
(_lastRequest.find("\r\n\r\n") != std::string::npos)) ||
|
||||
(_lastRequest.find("\r\n0\r\n") != std::string::npos);
|
||||
}
|
||||
|
||||
|
||||
std::string HTTPTestServer::handleRequest() const
|
||||
{
|
||||
std::string response;
|
||||
response.reserve(16000);
|
||||
if (_lastRequest.substr(0, 10) == "GET /small" ||
|
||||
_lastRequest.substr(0, 11) == "HEAD /small")
|
||||
{
|
||||
std::string body(SMALL_BODY);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
if (_lastRequest.substr(0, 3) == "GET")
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 10) == "GET /large" ||
|
||||
_lastRequest.substr(0, 11) == "HEAD /large" ||
|
||||
_lastRequest.substr(0, 36) == "GET http://www.somehost.com:80/large")
|
||||
{
|
||||
std::string body(LARGE_BODY);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
if (_lastRequest.substr(0, 3) == "GET")
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 12) == "POST /expect")
|
||||
{
|
||||
std::string::size_type pos = _lastRequest.find("\r\n\r\n");
|
||||
pos += 4;
|
||||
std::string body = _lastRequest.substr(pos);
|
||||
response.append("HTTP/1.1 100 Continue\r\n\r\n");
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
if (_lastRequest.find("Content-Length") != std::string::npos)
|
||||
{
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.find("chunked") != std::string::npos)
|
||||
{
|
||||
response.append("Transfer-Encoding: chunked\r\n");
|
||||
}
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 10) == "POST /fail")
|
||||
{
|
||||
std::string::size_type pos = _lastRequest.find("\r\n\r\n");
|
||||
pos += 4;
|
||||
std::string body = _lastRequest.substr(pos);
|
||||
response.append("HTTP/1.1 400 Bad Request\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 4) == "POST")
|
||||
{
|
||||
std::string::size_type pos = _lastRequest.find("\r\n\r\n");
|
||||
pos += 4;
|
||||
std::string body = _lastRequest.substr(pos);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
if (_lastRequest.find("Content-Length") != std::string::npos)
|
||||
{
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.find("chunked") != std::string::npos)
|
||||
{
|
||||
response.append("Transfer-Encoding: chunked\r\n");
|
||||
}
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 15) == "HEAD /keepAlive")
|
||||
{
|
||||
std::string body(SMALL_BODY);
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: keep-alive\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n\r\n");
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: Keep-Alive\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n\r\n");
|
||||
response.append(body);
|
||||
body = LARGE_BODY;
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: keep-alive\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Transfer-Encoding: chunked\r\n\r\n");
|
||||
response.append(NumberFormatter::formatHex((unsigned) body.length()));
|
||||
response.append("\r\n");
|
||||
response.append(body);
|
||||
response.append("\r\n0\r\n\r\n");
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: close\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 13) == "GET /redirect")
|
||||
{
|
||||
response.append("HTTP/1.0 302 Found\r\n");
|
||||
response.append("Location: /large\r\n");
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 13) == "GET /notfound")
|
||||
{
|
||||
response.append("HTTP/1.0 404 Not Found\r\n");
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 5) == "GET /" ||
|
||||
_lastRequest.substr(0, 6) == "HEAD /")
|
||||
{
|
||||
std::string body(SMALL_BODY);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
if (_lastRequest.substr(0, 3) == "GET")
|
||||
response.append(body);
|
||||
}
|
||||
return response;
|
||||
}
|
59
vendor/POCO/Net/testsuite/src/HTTPTestServer.h
vendored
Normal file
59
vendor/POCO/Net/testsuite/src/HTTPTestServer.h
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// HTTPTestServer.h
|
||||
//
|
||||
// Definition of the HTTPTestServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPTestServer_INCLUDED
|
||||
#define HTTPTestServer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
class HTTPTestServer: public Poco::Runnable
|
||||
/// A simple sequential echo server.
|
||||
{
|
||||
public:
|
||||
HTTPTestServer();
|
||||
/// Creates the HTTPTestServer.
|
||||
|
||||
~HTTPTestServer();
|
||||
/// Destroys the HTTPTestServer.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const std::string& lastRequest() const;
|
||||
/// Returns the last request.
|
||||
|
||||
static const std::string SMALL_BODY;
|
||||
static const std::string LARGE_BODY;
|
||||
|
||||
protected:
|
||||
bool requestComplete() const;
|
||||
std::string handleRequest() const;
|
||||
|
||||
private:
|
||||
Poco::Net::ServerSocket _socket;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
bool _stop;
|
||||
std::string _lastRequest;
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPTestServer_INCLUDED
|
30
vendor/POCO/Net/testsuite/src/HTTPTestSuite.cpp
vendored
Normal file
30
vendor/POCO/Net/testsuite/src/HTTPTestSuite.cpp
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// HTTPTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPTestSuite.h"
|
||||
#include "HTTPRequestTest.h"
|
||||
#include "HTTPResponseTest.h"
|
||||
#include "HTTPCookieTest.h"
|
||||
#include "HTTPCredentialsTest.h"
|
||||
#include "NTLMCredentialsTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTTPTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPTestSuite");
|
||||
|
||||
pSuite->addTest(HTTPRequestTest::suite());
|
||||
pSuite->addTest(HTTPResponseTest::suite());
|
||||
pSuite->addTest(HTTPCookieTest::suite());
|
||||
pSuite->addTest(HTTPCredentialsTest::suite());
|
||||
pSuite->addTest(NTLMCredentialsTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/HTTPTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/HTTPTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// HTTPTestSuite.h
|
||||
//
|
||||
// Definition of the HTTPTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPTestSuite_INCLUDED
|
||||
#define HTTPTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTTPTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPTestSuite_INCLUDED
|
187
vendor/POCO/Net/testsuite/src/ICMPClientTest.cpp
vendored
Normal file
187
vendor/POCO/Net/testsuite/src/ICMPClientTest.cpp
vendored
Normal file
@ -0,0 +1,187 @@
|
||||
//
|
||||
// ICMPClientTest.cpp
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "ICMPClientTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/ICMPSocket.h"
|
||||
#include "Poco/Net/ICMPClient.h"
|
||||
#include "Poco/Net/ICMPEventArgs.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::ICMPSocket;
|
||||
using Poco::Net::ICMPClient;
|
||||
using Poco::Net::ICMPEventArgs;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::HostNotFoundException;
|
||||
using Poco::Delegate;
|
||||
using Poco::AutoPtr;
|
||||
|
||||
|
||||
Poco::FastMutex ICMPClientTest::_mutex;
|
||||
|
||||
|
||||
ICMPClientTest::ICMPClientTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ICMPClientTest::~ICMPClientTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::testPing()
|
||||
{
|
||||
assertTrue (ICMPClient::pingIPv4("127.0.0.1") > 0);
|
||||
|
||||
Poco::Net::ICMPClient icmpClient(IPAddress::IPv4);
|
||||
|
||||
registerDelegates(icmpClient);
|
||||
|
||||
assertTrue (icmpClient.ping("127.0.0.1") > 0);
|
||||
#if POCO_OS == POCO_OS_ANDROID
|
||||
assertTrue (icmpClient.ping("10.0.2.15", 4) > 0);
|
||||
assertTrue (icmpClient.ping("10.0.2.2", 4) > 0);
|
||||
#else
|
||||
assertTrue (icmpClient.ping("www.appinf.com", 4) > 0);
|
||||
|
||||
// warning: may fail depending on the existence of the addresses at test site
|
||||
// if so, adjust accordingly (i.e. specify non-existent or unreachable IP addresses)
|
||||
assertTrue (0 == icmpClient.ping("192.168.243.1"));
|
||||
assertTrue (0 == icmpClient.ping("10.11.12.13"));
|
||||
#endif
|
||||
|
||||
unregisterDelegates(icmpClient);
|
||||
// wait for delegates to finish printing
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::testBigPing()
|
||||
{
|
||||
assertTrue (ICMPClient::pingIPv4("127.0.0.1", 1, 96) > 0);
|
||||
|
||||
Poco::Net::ICMPClient icmpClient(IPAddress::IPv4, 96);
|
||||
|
||||
registerDelegates(icmpClient);
|
||||
|
||||
assertTrue (icmpClient.ping("127.0.0.1", 1) > 0);
|
||||
#if POCO_OS == POCO_OS_ANDROID
|
||||
assertTrue (icmpClient.ping("10.0.2.15", 4) > 0);
|
||||
assertTrue (icmpClient.ping("10.0.2.2", 4) > 0);
|
||||
#else
|
||||
assertTrue (icmpClient.ping("www.appinf.com", 4) > 0);
|
||||
|
||||
// warning: may fail depending on the existence of the addresses at test site
|
||||
// if so, adjust accordingly (i.e. specify non-existent or unreachable IP addresses)
|
||||
assertTrue (0 == icmpClient.ping("192.168.243.1"));
|
||||
assertTrue (0 == icmpClient.ping("10.11.12.13"));
|
||||
#endif
|
||||
|
||||
unregisterDelegates(icmpClient);
|
||||
// wait for delegates to finish printing
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::registerDelegates(const ICMPClient& icmpClient)
|
||||
{
|
||||
icmpClient.pingBegin += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onBegin);
|
||||
icmpClient.pingReply += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onReply);
|
||||
icmpClient.pingError += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onError);
|
||||
icmpClient.pingEnd += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onEnd);
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::unregisterDelegates(const ICMPClient& icmpClient)
|
||||
{
|
||||
icmpClient.pingBegin -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onBegin);
|
||||
icmpClient.pingReply -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onReply);
|
||||
icmpClient.pingError -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onError);
|
||||
icmpClient.pingEnd -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onEnd);
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onBegin(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
os << std::endl << "Pinging " << args.hostName() << " [" << args.hostAddress() << "] with "
|
||||
<< args.dataSize() << " bytes of data:"
|
||||
<< std::endl << "-------------------------------------------------------" << std::endl;
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onReply(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
os << "Reply from " << args.hostAddress()
|
||||
<< " bytes=" << args.dataSize()
|
||||
<< " time=" << args.replyTime() << "ms"
|
||||
<< " TTL=" << args.ttl();
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onError(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
os << args.error();
|
||||
std::cerr << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onEnd(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
int received = args.received();
|
||||
os << std::endl << "--- Ping statistics for " << args.hostAddress() << " ---"
|
||||
<< std::endl << "Packets: Sent=" << args.sent() << ", Received=" << received
|
||||
<< " Lost=" << args.repetitions() - received << " (" << 100.0 - args.percent() << "% loss),"
|
||||
<< std::endl << "Approximate round trip times in milliseconds: " << std::endl
|
||||
<< "Minimum=" << args.minRTT() << "ms, Maximum=" << args.maxRTT()
|
||||
<< "ms, Average=" << args.avgRTT() << "ms"
|
||||
<< std::endl << "-----------------------------------------------" << std::endl;
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ICMPClientTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPClientTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ICMPClientTest, testPing);
|
||||
CppUnit_addTest(pSuite, ICMPClientTest, testBigPing);
|
||||
|
||||
return pSuite;
|
||||
}
|
50
vendor/POCO/Net/testsuite/src/ICMPClientTest.h
vendored
Normal file
50
vendor/POCO/Net/testsuite/src/ICMPClientTest.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// ICMPClientTest.h
|
||||
//
|
||||
// Definition of the ICMPClientTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef ICMPClientTest_INCLUDED
|
||||
#define ICMPClientTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/Net/ICMPClient.h"
|
||||
#include "Poco/Net/ICMPEventArgs.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
class ICMPClientTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ICMPClientTest(const std::string& name);
|
||||
~ICMPClientTest();
|
||||
|
||||
void testPing();
|
||||
void testBigPing();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
void onBegin(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
void onReply(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
void onError(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
void onEnd(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
|
||||
private:
|
||||
void registerDelegates(const Poco::Net::ICMPClient& icmpClient);
|
||||
void unregisterDelegates(const Poco::Net::ICMPClient& icmpClient);
|
||||
static Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
#endif // ICMPClientTest_INCLUDED
|
24
vendor/POCO/Net/testsuite/src/ICMPClientTestSuite.cpp
vendored
Normal file
24
vendor/POCO/Net/testsuite/src/ICMPClientTestSuite.cpp
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// ICMPClientTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "ICMPClientTestSuite.h"
|
||||
#include "ICMPClientTest.h"
|
||||
#include "ICMPSocketTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* ICMPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPClientTestSuite");
|
||||
|
||||
pSuite->addTest(ICMPClientTest::suite());
|
||||
pSuite->addTest(ICMPSocketTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/ICMPClientTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/ICMPClientTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// ICMPClientTestSuite.h
|
||||
//
|
||||
// Definition of the ICMPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef ICMPClientTestSuite_INCLUDED
|
||||
#define ICMPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class ICMPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // ICMPClientTestSuite_INCLUDED
|
124
vendor/POCO/Net/testsuite/src/ICMPSocketTest.cpp
vendored
Normal file
124
vendor/POCO/Net/testsuite/src/ICMPSocketTest.cpp
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
//
|
||||
// ICMPSocketTest.cpp
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "ICMPSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "UDPEchoServer.h"
|
||||
#include "Poco/Net/ICMPSocket.h"
|
||||
#include "Poco/Net/ICMPPacketImpl.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::ICMPSocket;
|
||||
using Poco::Net::ICMPPacketImpl;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::ICMPException;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::Net::NetException;
|
||||
using Poco::Net::ICMPException;
|
||||
using Poco::Exception;
|
||||
using Poco::TimeoutException;
|
||||
|
||||
|
||||
ICMPSocketTest::ICMPSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ICMPSocketTest::~ICMPSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::testAssign()
|
||||
{
|
||||
ICMPSocket s1(IPAddress::IPv4);
|
||||
ICMPSocket s2(s1);
|
||||
}
|
||||
|
||||
void ICMPSocketTest::testSendToReceiveFrom()
|
||||
{
|
||||
ICMPSocket ss(IPAddress::IPv4);
|
||||
|
||||
SocketAddress sa("www.appinf.com", 0);
|
||||
SocketAddress sr(sa);
|
||||
|
||||
try
|
||||
{
|
||||
ss.receiveFrom(sa);
|
||||
fail("must throw");
|
||||
}
|
||||
catch (ICMPException&) { }
|
||||
catch (TimeoutException&) { }
|
||||
catch (Exception&) { }
|
||||
|
||||
ss.sendTo(sa);
|
||||
ss.receiveFrom(sa);
|
||||
|
||||
assertTrue (sr.host().toString() == sa.host().toString());
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::testMTU()
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::UInt16 sz = ICMPPacketImpl::MAX_PAYLOAD_SIZE + 1;
|
||||
SocketAddress addr("127.0.0.1:0");
|
||||
Poco::UInt16 mtu = ICMPSocket::mtu(addr, sz);
|
||||
std::cout << addr.toString() << " : MTU=" << mtu << std::endl;
|
||||
assertTrue (mtu != 0 && mtu <= ICMPPacketImpl::MAX_PAYLOAD_SIZE);
|
||||
sz = ICMPPacketImpl::MAX_PAYLOAD_SIZE;
|
||||
mtu = ICMPSocket::mtu(addr, sz);
|
||||
std::cout << addr.toString() << " : MTU=" << mtu << std::endl;
|
||||
assertTrue (mtu != 0);
|
||||
sz = 1500;
|
||||
addr = SocketAddress("www.appinf.com:0");
|
||||
mtu = ICMPSocket::mtu(addr, sz);
|
||||
std::cout << addr.toString() << " : MTU=" << mtu << std::endl;
|
||||
assertTrue (mtu != 0 && mtu <= sz);
|
||||
}
|
||||
catch (Poco::NotImplementedException& ex)
|
||||
{
|
||||
std::cerr << ex.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ICMPSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testSendToReceiveFrom);
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testAssign);
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testMTU);
|
||||
|
||||
return pSuite;
|
||||
}
|
40
vendor/POCO/Net/testsuite/src/ICMPSocketTest.h
vendored
Normal file
40
vendor/POCO/Net/testsuite/src/ICMPSocketTest.h
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// ICMPSocketTest.h
|
||||
//
|
||||
// Definition of the ICMPSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef ICMPSocketTest_INCLUDED
|
||||
#define ICMPSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class ICMPSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ICMPSocketTest(const std::string& name);
|
||||
~ICMPSocketTest();
|
||||
|
||||
void testSendToReceiveFrom();
|
||||
void testAssign();
|
||||
void testMTU();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // ICMPSocketTest_INCLUDED
|
661
vendor/POCO/Net/testsuite/src/IPAddressTest.cpp
vendored
Normal file
661
vendor/POCO/Net/testsuite/src/IPAddressTest.cpp
vendored
Normal file
@ -0,0 +1,661 @@
|
||||
//
|
||||
// IPAddressTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "IPAddressTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/IPAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::InvalidAddressException;
|
||||
|
||||
|
||||
IPAddressTest::IPAddressTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IPAddressTest::~IPAddressTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testStringConv()
|
||||
{
|
||||
IPAddress ia1("127.0.0.1");
|
||||
assertTrue (ia1.family() == IPAddress::IPv4);
|
||||
assertTrue (ia1.toString() == "127.0.0.1");
|
||||
|
||||
IPAddress ia2("192.168.1.120");
|
||||
assertTrue (ia2.family() == IPAddress::IPv4);
|
||||
assertTrue (ia2.toString() == "192.168.1.120");
|
||||
|
||||
IPAddress ia3("255.255.255.255");
|
||||
assertTrue (ia3.family() == IPAddress::IPv4);
|
||||
assertTrue (ia3.toString() == "255.255.255.255");
|
||||
|
||||
IPAddress ia4("0.0.0.0");
|
||||
assertTrue (ia4.family() == IPAddress::IPv4);
|
||||
assertTrue (ia4.toString() == "0.0.0.0");
|
||||
|
||||
IPAddress ia5(24, IPAddress::IPv4);
|
||||
assertTrue (ia5.family() == IPAddress::IPv4);
|
||||
assertTrue (ia5.toString() == "255.255.255.0");
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testStringConv6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ia0("::1");
|
||||
assertTrue (ia0.family() == IPAddress::IPv6);
|
||||
assertTrue (ia0.toString() == "::1");
|
||||
|
||||
IPAddress ia1("1080:0:0:0:8:600:200a:425c");
|
||||
assertTrue (ia1.family() == IPAddress::IPv6);
|
||||
assertTrue (ia1.toString() == "1080::8:600:200a:425c");
|
||||
|
||||
IPAddress ia2("1080::8:600:200A:425C");
|
||||
assertTrue (ia2.family() == IPAddress::IPv6);
|
||||
assertTrue (ia2.toString() == "1080::8:600:200a:425c");
|
||||
|
||||
IPAddress ia3("::192.168.1.120");
|
||||
assertTrue (ia3.family() == IPAddress::IPv6);
|
||||
assertTrue (ia3.toString() == "::192.168.1.120");
|
||||
|
||||
IPAddress ia4("::ffff:192.168.1.120");
|
||||
assertTrue (ia4.family() == IPAddress::IPv6);
|
||||
assertTrue (ia4.toString() == "::ffff:192.168.1.120");
|
||||
|
||||
IPAddress ia5(64, IPAddress::IPv6);
|
||||
assertTrue (ia5.family() == IPAddress::IPv6);
|
||||
assertTrue (ia5.toString() == "ffff:ffff:ffff:ffff::");
|
||||
|
||||
IPAddress ia6(32, IPAddress::IPv6);
|
||||
assertTrue (ia6.family() == IPAddress::IPv6);
|
||||
assertTrue (ia6.toString() == "ffff:ffff::");
|
||||
|
||||
IPAddress ia7("::");
|
||||
assertTrue (ia7.family() == IPAddress::IPv6);
|
||||
assertTrue (ia7.toString() == "::");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testParse()
|
||||
{
|
||||
IPAddress ip;
|
||||
assertTrue (IPAddress::tryParse("192.168.1.120", ip));
|
||||
|
||||
assertTrue (!IPAddress::tryParse("192.168.1.280", ip));
|
||||
|
||||
ip = IPAddress::parse("192.168.1.120");
|
||||
try
|
||||
{
|
||||
ip = IPAddress::parse("192.168.1.280");
|
||||
fail("bad address - must throw");
|
||||
}
|
||||
catch (InvalidAddressException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testClassification()
|
||||
{
|
||||
IPAddress ip1("0.0.0.0"); // wildcard
|
||||
assertTrue (ip1.isWildcard());
|
||||
assertTrue (!ip1.isBroadcast());
|
||||
assertTrue (!ip1.isLoopback());
|
||||
assertTrue (!ip1.isMulticast());
|
||||
assertTrue (!ip1.isUnicast());
|
||||
assertTrue (!ip1.isLinkLocal());
|
||||
assertTrue (!ip1.isSiteLocal());
|
||||
assertTrue (!ip1.isWellKnownMC());
|
||||
assertTrue (!ip1.isNodeLocalMC());
|
||||
assertTrue (!ip1.isLinkLocalMC());
|
||||
assertTrue (!ip1.isSiteLocalMC());
|
||||
assertTrue (!ip1.isOrgLocalMC());
|
||||
assertTrue (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip2("255.255.255.255"); // broadcast
|
||||
assertTrue (!ip2.isWildcard());
|
||||
assertTrue (ip2.isBroadcast());
|
||||
assertTrue (!ip2.isLoopback());
|
||||
assertTrue (!ip2.isMulticast());
|
||||
assertTrue (!ip2.isUnicast());
|
||||
assertTrue (!ip2.isLinkLocal());
|
||||
assertTrue (!ip2.isSiteLocal());
|
||||
assertTrue (!ip2.isWellKnownMC());
|
||||
assertTrue (!ip2.isNodeLocalMC());
|
||||
assertTrue (!ip2.isLinkLocalMC());
|
||||
assertTrue (!ip2.isSiteLocalMC());
|
||||
assertTrue (!ip2.isOrgLocalMC());
|
||||
assertTrue (!ip2.isGlobalMC());
|
||||
|
||||
IPAddress ip3("127.0.0.1"); // loopback
|
||||
assertTrue (!ip3.isWildcard());
|
||||
assertTrue (!ip3.isBroadcast());
|
||||
assertTrue (ip3.isLoopback());
|
||||
assertTrue (!ip3.isMulticast());
|
||||
assertTrue (ip3.isUnicast());
|
||||
assertTrue (!ip3.isLinkLocal());
|
||||
assertTrue (!ip3.isSiteLocal());
|
||||
assertTrue (!ip3.isWellKnownMC());
|
||||
assertTrue (!ip3.isNodeLocalMC());
|
||||
assertTrue (!ip3.isLinkLocalMC());
|
||||
assertTrue (!ip3.isSiteLocalMC());
|
||||
assertTrue (!ip3.isOrgLocalMC());
|
||||
assertTrue (!ip3.isGlobalMC());
|
||||
|
||||
IPAddress ip4("80.122.195.86"); // unicast
|
||||
assertTrue (!ip4.isWildcard());
|
||||
assertTrue (!ip4.isBroadcast());
|
||||
assertTrue (!ip4.isLoopback());
|
||||
assertTrue (!ip4.isMulticast());
|
||||
assertTrue (ip4.isUnicast());
|
||||
assertTrue (!ip4.isLinkLocal());
|
||||
assertTrue (!ip4.isSiteLocal());
|
||||
assertTrue (!ip4.isWellKnownMC());
|
||||
assertTrue (!ip4.isNodeLocalMC());
|
||||
assertTrue (!ip4.isLinkLocalMC());
|
||||
assertTrue (!ip4.isSiteLocalMC());
|
||||
assertTrue (!ip4.isOrgLocalMC());
|
||||
assertTrue (!ip4.isGlobalMC());
|
||||
|
||||
IPAddress ip5("169.254.1.20"); // link local unicast
|
||||
assertTrue (!ip5.isWildcard());
|
||||
assertTrue (!ip5.isBroadcast());
|
||||
assertTrue (!ip5.isLoopback());
|
||||
assertTrue (!ip5.isMulticast());
|
||||
assertTrue (ip5.isUnicast());
|
||||
assertTrue (ip5.isLinkLocal());
|
||||
assertTrue (!ip5.isSiteLocal());
|
||||
assertTrue (!ip5.isWellKnownMC());
|
||||
assertTrue (!ip5.isNodeLocalMC());
|
||||
assertTrue (!ip5.isLinkLocalMC());
|
||||
assertTrue (!ip5.isSiteLocalMC());
|
||||
assertTrue (!ip5.isOrgLocalMC());
|
||||
assertTrue (!ip5.isGlobalMC());
|
||||
|
||||
IPAddress ip6("192.168.1.120"); // site local unicast
|
||||
assertTrue (!ip6.isWildcard());
|
||||
assertTrue (!ip6.isBroadcast());
|
||||
assertTrue (!ip6.isLoopback());
|
||||
assertTrue (!ip6.isMulticast());
|
||||
assertTrue (ip6.isUnicast());
|
||||
assertTrue (!ip6.isLinkLocal());
|
||||
assertTrue (ip6.isSiteLocal());
|
||||
assertTrue (!ip6.isWellKnownMC());
|
||||
assertTrue (!ip6.isNodeLocalMC());
|
||||
assertTrue (!ip6.isLinkLocalMC());
|
||||
assertTrue (!ip6.isSiteLocalMC());
|
||||
assertTrue (!ip6.isOrgLocalMC());
|
||||
assertTrue (!ip6.isGlobalMC());
|
||||
|
||||
IPAddress ip7("10.0.0.138"); // site local unicast
|
||||
assertTrue (!ip7.isWildcard());
|
||||
assertTrue (!ip7.isBroadcast());
|
||||
assertTrue (!ip7.isLoopback());
|
||||
assertTrue (!ip7.isMulticast());
|
||||
assertTrue (ip7.isUnicast());
|
||||
assertTrue (!ip7.isLinkLocal());
|
||||
assertTrue (ip7.isSiteLocal());
|
||||
assertTrue (!ip7.isWellKnownMC());
|
||||
assertTrue (!ip7.isNodeLocalMC());
|
||||
assertTrue (!ip7.isLinkLocalMC());
|
||||
assertTrue (!ip7.isSiteLocalMC());
|
||||
assertTrue (!ip7.isOrgLocalMC());
|
||||
assertTrue (!ip7.isGlobalMC());
|
||||
|
||||
IPAddress ip8("172.18.1.200"); // site local unicast
|
||||
assertTrue (!ip8.isWildcard());
|
||||
assertTrue (!ip8.isBroadcast());
|
||||
assertTrue (!ip8.isLoopback());
|
||||
assertTrue (!ip8.isMulticast());
|
||||
assertTrue (ip8.isUnicast());
|
||||
assertTrue (!ip8.isLinkLocal());
|
||||
assertTrue (ip8.isSiteLocal());
|
||||
assertTrue (!ip8.isWellKnownMC());
|
||||
assertTrue (!ip8.isNodeLocalMC());
|
||||
assertTrue (!ip8.isLinkLocalMC());
|
||||
assertTrue (!ip8.isSiteLocalMC());
|
||||
assertTrue (!ip8.isOrgLocalMC());
|
||||
assertTrue (!ip8.isGlobalMC());
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testMCClassification()
|
||||
{
|
||||
IPAddress ip1("224.0.0.100"); // well-known multicast
|
||||
assertTrue (!ip1.isWildcard());
|
||||
assertTrue (!ip1.isBroadcast());
|
||||
assertTrue (!ip1.isLoopback());
|
||||
assertTrue (ip1.isMulticast());
|
||||
assertTrue (!ip1.isUnicast());
|
||||
assertTrue (!ip1.isLinkLocal());
|
||||
assertTrue (!ip1.isSiteLocal());
|
||||
assertTrue (ip1.isWellKnownMC());
|
||||
assertTrue (!ip1.isNodeLocalMC());
|
||||
assertTrue (ip1.isLinkLocalMC()); // well known are in the range of link local
|
||||
assertTrue (!ip1.isSiteLocalMC());
|
||||
assertTrue (!ip1.isOrgLocalMC());
|
||||
assertTrue (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip2("224.1.0.100"); // link local unicast
|
||||
assertTrue (!ip2.isWildcard());
|
||||
assertTrue (!ip2.isBroadcast());
|
||||
assertTrue (!ip2.isLoopback());
|
||||
assertTrue (ip2.isMulticast());
|
||||
assertTrue (!ip2.isUnicast());
|
||||
assertTrue (!ip2.isLinkLocal());
|
||||
assertTrue (!ip2.isSiteLocal());
|
||||
assertTrue (!ip2.isWellKnownMC());
|
||||
assertTrue (!ip2.isNodeLocalMC());
|
||||
assertTrue (ip2.isLinkLocalMC());
|
||||
assertTrue (!ip2.isSiteLocalMC());
|
||||
assertTrue (!ip2.isOrgLocalMC());
|
||||
assertTrue (ip2.isGlobalMC()); // link local fall in the range of global
|
||||
|
||||
IPAddress ip3("239.255.0.100"); // site local unicast
|
||||
assertTrue (!ip3.isWildcard());
|
||||
assertTrue (!ip3.isBroadcast());
|
||||
assertTrue (!ip3.isLoopback());
|
||||
assertTrue (ip3.isMulticast());
|
||||
assertTrue (!ip3.isUnicast());
|
||||
assertTrue (!ip3.isLinkLocal());
|
||||
assertTrue (!ip3.isSiteLocal());
|
||||
assertTrue (!ip3.isWellKnownMC());
|
||||
assertTrue (!ip3.isNodeLocalMC());
|
||||
assertTrue (!ip3.isLinkLocalMC());
|
||||
assertTrue (ip3.isSiteLocalMC());
|
||||
assertTrue (!ip3.isOrgLocalMC());
|
||||
assertTrue (!ip3.isGlobalMC());
|
||||
|
||||
IPAddress ip4("239.192.0.100"); // org local unicast
|
||||
assertTrue (!ip4.isWildcard());
|
||||
assertTrue (!ip4.isBroadcast());
|
||||
assertTrue (!ip4.isLoopback());
|
||||
assertTrue (ip4.isMulticast());
|
||||
assertTrue (!ip4.isUnicast());
|
||||
assertTrue (!ip4.isLinkLocal());
|
||||
assertTrue (!ip4.isSiteLocal());
|
||||
assertTrue (!ip4.isWellKnownMC());
|
||||
assertTrue (!ip4.isNodeLocalMC());
|
||||
assertTrue (!ip4.isLinkLocalMC());
|
||||
assertTrue (!ip4.isSiteLocalMC());
|
||||
assertTrue (ip4.isOrgLocalMC());
|
||||
assertTrue (!ip4.isGlobalMC());
|
||||
|
||||
IPAddress ip5("224.2.127.254"); // global unicast
|
||||
assertTrue (!ip5.isWildcard());
|
||||
assertTrue (!ip5.isBroadcast());
|
||||
assertTrue (!ip5.isLoopback());
|
||||
assertTrue (ip5.isMulticast());
|
||||
assertTrue (!ip5.isUnicast());
|
||||
assertTrue (!ip5.isLinkLocal());
|
||||
assertTrue (!ip5.isSiteLocal());
|
||||
assertTrue (!ip5.isWellKnownMC());
|
||||
assertTrue (!ip5.isNodeLocalMC());
|
||||
assertTrue (ip5.isLinkLocalMC()); // link local fall in the range of global
|
||||
assertTrue (!ip5.isSiteLocalMC());
|
||||
assertTrue (!ip5.isOrgLocalMC());
|
||||
assertTrue (ip5.isGlobalMC());
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testClassification6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ip1("::"); // wildcard
|
||||
assertTrue (ip1.isWildcard());
|
||||
assertTrue (!ip1.isBroadcast());
|
||||
assertTrue (!ip1.isLoopback());
|
||||
assertTrue (!ip1.isMulticast());
|
||||
assertTrue (!ip1.isUnicast());
|
||||
assertTrue (!ip1.isLinkLocal());
|
||||
assertTrue (!ip1.isSiteLocal());
|
||||
assertTrue (!ip1.isWellKnownMC());
|
||||
assertTrue (!ip1.isNodeLocalMC());
|
||||
assertTrue (!ip1.isLinkLocalMC());
|
||||
assertTrue (!ip1.isSiteLocalMC());
|
||||
assertTrue (!ip1.isOrgLocalMC());
|
||||
assertTrue (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip3("::1"); // loopback
|
||||
assertTrue (!ip3.isWildcard());
|
||||
assertTrue (!ip3.isBroadcast());
|
||||
assertTrue (ip3.isLoopback());
|
||||
assertTrue (!ip3.isMulticast());
|
||||
assertTrue (ip3.isUnicast());
|
||||
assertTrue (!ip3.isLinkLocal());
|
||||
assertTrue (!ip3.isSiteLocal());
|
||||
assertTrue (!ip3.isWellKnownMC());
|
||||
assertTrue (!ip3.isNodeLocalMC());
|
||||
assertTrue (!ip3.isLinkLocalMC());
|
||||
assertTrue (!ip3.isSiteLocalMC());
|
||||
assertTrue (!ip3.isOrgLocalMC());
|
||||
assertTrue (!ip3.isGlobalMC());
|
||||
|
||||
IPAddress ip4("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // unicast
|
||||
assertTrue (!ip4.isWildcard());
|
||||
assertTrue (!ip4.isBroadcast());
|
||||
assertTrue (!ip4.isLoopback());
|
||||
assertTrue (!ip4.isMulticast());
|
||||
assertTrue (ip4.isUnicast());
|
||||
assertTrue (!ip4.isLinkLocal());
|
||||
assertTrue (!ip4.isSiteLocal());
|
||||
assertTrue (!ip4.isWellKnownMC());
|
||||
assertTrue (!ip4.isNodeLocalMC());
|
||||
assertTrue (!ip4.isLinkLocalMC());
|
||||
assertTrue (!ip4.isSiteLocalMC());
|
||||
assertTrue (!ip4.isOrgLocalMC());
|
||||
assertTrue (!ip4.isGlobalMC());
|
||||
|
||||
IPAddress ip5("fe80::21f:5bff:fec6:6707"); // link local unicast
|
||||
assertTrue (!ip5.isWildcard());
|
||||
assertTrue (!ip5.isBroadcast());
|
||||
assertTrue (!ip5.isLoopback());
|
||||
assertTrue (!ip5.isMulticast());
|
||||
assertTrue (ip5.isUnicast());
|
||||
assertTrue (ip5.isLinkLocal());
|
||||
assertTrue (!ip5.isSiteLocal());
|
||||
assertTrue (!ip5.isWellKnownMC());
|
||||
assertTrue (!ip5.isNodeLocalMC());
|
||||
assertTrue (!ip5.isLinkLocalMC());
|
||||
assertTrue (!ip5.isSiteLocalMC());
|
||||
assertTrue (!ip5.isOrgLocalMC());
|
||||
assertTrue (!ip5.isGlobalMC());
|
||||
|
||||
IPAddress ip10("fe80::12"); // link local unicast
|
||||
assertTrue (!ip10.isWildcard());
|
||||
assertTrue (!ip10.isBroadcast());
|
||||
assertTrue (!ip10.isLoopback());
|
||||
assertTrue (!ip10.isMulticast());
|
||||
assertTrue (ip10.isUnicast());
|
||||
assertTrue (ip10.isLinkLocal());
|
||||
assertTrue (!ip10.isSiteLocal());
|
||||
assertTrue (!ip10.isWellKnownMC());
|
||||
assertTrue (!ip10.isNodeLocalMC());
|
||||
assertTrue (!ip10.isLinkLocalMC());
|
||||
assertTrue (!ip10.isSiteLocalMC());
|
||||
assertTrue (!ip10.isOrgLocalMC());
|
||||
assertTrue (!ip10.isGlobalMC());
|
||||
|
||||
IPAddress ip6("fec0::21f:5bff:fec6:6707"); // site local unicast (RFC 4291)
|
||||
assertTrue (!ip6.isWildcard());
|
||||
assertTrue (!ip6.isBroadcast());
|
||||
assertTrue (!ip6.isLoopback());
|
||||
assertTrue (!ip6.isMulticast());
|
||||
assertTrue (ip6.isUnicast());
|
||||
assertTrue (!ip6.isLinkLocal());
|
||||
assertTrue (ip6.isSiteLocal());
|
||||
assertTrue (!ip6.isWellKnownMC());
|
||||
assertTrue (!ip6.isNodeLocalMC());
|
||||
assertTrue (!ip6.isLinkLocalMC());
|
||||
assertTrue (!ip6.isSiteLocalMC());
|
||||
assertTrue (!ip6.isOrgLocalMC());
|
||||
assertTrue (!ip6.isGlobalMC());
|
||||
|
||||
IPAddress ip7("fc00::21f:5bff:fec6:6707"); // site local unicast (RFC 4193)
|
||||
assertTrue (!ip7.isWildcard());
|
||||
assertTrue (!ip7.isBroadcast());
|
||||
assertTrue (!ip7.isLoopback());
|
||||
assertTrue (!ip7.isMulticast());
|
||||
assertTrue (ip7.isUnicast());
|
||||
assertTrue (!ip7.isLinkLocal());
|
||||
assertTrue (ip7.isSiteLocal());
|
||||
assertTrue (!ip7.isWellKnownMC());
|
||||
assertTrue (!ip7.isNodeLocalMC());
|
||||
assertTrue (!ip7.isLinkLocalMC());
|
||||
assertTrue (!ip7.isSiteLocalMC());
|
||||
assertTrue (!ip7.isOrgLocalMC());
|
||||
assertTrue (!ip7.isGlobalMC());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testMCClassification6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ip1("ff02:0:0:0:0:0:0:c"); // well-known link-local multicast
|
||||
assertTrue (!ip1.isWildcard());
|
||||
assertTrue (!ip1.isBroadcast());
|
||||
assertTrue (!ip1.isLoopback());
|
||||
assertTrue (ip1.isMulticast());
|
||||
assertTrue (!ip1.isUnicast());
|
||||
assertTrue (!ip1.isLinkLocal());
|
||||
assertTrue (!ip1.isSiteLocal());
|
||||
assertTrue (ip1.isWellKnownMC());
|
||||
assertTrue (!ip1.isNodeLocalMC());
|
||||
assertTrue (ip1.isLinkLocalMC());
|
||||
assertTrue (!ip1.isSiteLocalMC());
|
||||
assertTrue (!ip1.isOrgLocalMC());
|
||||
assertTrue (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip2("ff01:0:0:0:0:0:0:FB"); // node-local unicast
|
||||
assertTrue (!ip2.isWildcard());
|
||||
assertTrue (!ip2.isBroadcast());
|
||||
assertTrue (!ip2.isLoopback());
|
||||
assertTrue (ip2.isMulticast());
|
||||
assertTrue (!ip2.isUnicast());
|
||||
assertTrue (!ip2.isLinkLocal());
|
||||
assertTrue (!ip2.isSiteLocal());
|
||||
assertTrue (ip2.isWellKnownMC());
|
||||
assertTrue (ip2.isNodeLocalMC());
|
||||
assertTrue (!ip2.isLinkLocalMC());
|
||||
assertTrue (!ip2.isSiteLocalMC());
|
||||
assertTrue (!ip2.isOrgLocalMC());
|
||||
assertTrue (!ip2.isGlobalMC());
|
||||
|
||||
IPAddress ip3("ff05:0:0:0:0:0:0:FB"); // site local unicast
|
||||
assertTrue (!ip3.isWildcard());
|
||||
assertTrue (!ip3.isBroadcast());
|
||||
assertTrue (!ip3.isLoopback());
|
||||
assertTrue (ip3.isMulticast());
|
||||
assertTrue (!ip3.isUnicast());
|
||||
assertTrue (!ip3.isLinkLocal());
|
||||
assertTrue (!ip3.isSiteLocal());
|
||||
assertTrue (ip3.isWellKnownMC());
|
||||
assertTrue (!ip3.isNodeLocalMC());
|
||||
assertTrue (!ip3.isLinkLocalMC());
|
||||
assertTrue (ip3.isSiteLocalMC());
|
||||
assertTrue (!ip3.isOrgLocalMC());
|
||||
assertTrue (!ip3.isGlobalMC());
|
||||
|
||||
IPAddress ip4("ff18:0:0:0:0:0:0:FB"); // org local unicast
|
||||
assertTrue (!ip4.isWildcard());
|
||||
assertTrue (!ip4.isBroadcast());
|
||||
assertTrue (!ip4.isLoopback());
|
||||
assertTrue (ip4.isMulticast());
|
||||
assertTrue (!ip4.isUnicast());
|
||||
assertTrue (!ip4.isLinkLocal());
|
||||
assertTrue (!ip4.isSiteLocal());
|
||||
assertTrue (!ip4.isWellKnownMC());
|
||||
assertTrue (!ip4.isNodeLocalMC());
|
||||
assertTrue (!ip4.isLinkLocalMC());
|
||||
assertTrue (!ip4.isSiteLocalMC());
|
||||
assertTrue (ip4.isOrgLocalMC());
|
||||
assertTrue (!ip4.isGlobalMC());
|
||||
|
||||
IPAddress ip5("ff1f:0:0:0:0:0:0:FB"); // global unicast
|
||||
assertTrue (!ip5.isWildcard());
|
||||
assertTrue (!ip5.isBroadcast());
|
||||
assertTrue (!ip5.isLoopback());
|
||||
assertTrue (ip5.isMulticast());
|
||||
assertTrue (!ip5.isUnicast());
|
||||
assertTrue (!ip5.isLinkLocal());
|
||||
assertTrue (!ip5.isSiteLocal());
|
||||
assertTrue (!ip5.isWellKnownMC());
|
||||
assertTrue (!ip5.isNodeLocalMC());
|
||||
assertTrue (!ip5.isLinkLocalMC());
|
||||
assertTrue (!ip5.isSiteLocalMC());
|
||||
assertTrue (!ip5.isOrgLocalMC());
|
||||
assertTrue (ip5.isGlobalMC());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testRelationals()
|
||||
{
|
||||
IPAddress ip1("192.168.1.120");
|
||||
IPAddress ip2(ip1);
|
||||
IPAddress ip3;
|
||||
IPAddress ip4("10.0.0.138");
|
||||
|
||||
assertTrue (ip1 != ip4);
|
||||
assertTrue (ip1 == ip2);
|
||||
assertTrue (!(ip1 != ip2));
|
||||
assertTrue (!(ip1 == ip4));
|
||||
assertTrue (ip1 > ip4);
|
||||
assertTrue (ip1 >= ip4);
|
||||
assertTrue (ip4 < ip1);
|
||||
assertTrue (ip4 <= ip1);
|
||||
assertTrue (!(ip1 < ip4));
|
||||
assertTrue (!(ip1 <= ip4));
|
||||
assertTrue (!(ip4 > ip1));
|
||||
assertTrue (!(ip4 >= ip1));
|
||||
|
||||
ip3 = ip1;
|
||||
assertTrue (ip1 == ip3);
|
||||
ip3 = ip4;
|
||||
assertTrue (ip1 != ip3);
|
||||
assertTrue (ip3 == ip4);
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testWildcard()
|
||||
{
|
||||
IPAddress wildcard = IPAddress::wildcard();
|
||||
assertTrue (wildcard.isWildcard());
|
||||
assertTrue (wildcard.toString() == "0.0.0.0");
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testBroadcast()
|
||||
{
|
||||
IPAddress broadcast = IPAddress::broadcast();
|
||||
assertTrue (broadcast.isBroadcast());
|
||||
assertTrue (broadcast.toString() == "255.255.255.255");
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testPrefixCons()
|
||||
{
|
||||
IPAddress ia1(15, IPAddress::IPv4);
|
||||
assertTrue (ia1.toString() == "255.254.0.0");
|
||||
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ia2(62, IPAddress::IPv6);
|
||||
assertTrue (ia2.toString() == "ffff:ffff:ffff:fffc::");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testPrefixLen()
|
||||
{
|
||||
IPAddress ia1(15, IPAddress::IPv4);
|
||||
assertTrue (ia1.prefixLength() == 15);
|
||||
|
||||
IPAddress ia2(16, IPAddress::IPv4);
|
||||
assertTrue (ia2.prefixLength() == 16);
|
||||
|
||||
IPAddress ia3(23, IPAddress::IPv4);
|
||||
assertTrue (ia3.prefixLength() == 23);
|
||||
|
||||
IPAddress ia4(24, IPAddress::IPv4);
|
||||
assertTrue (ia4.prefixLength() == 24);
|
||||
|
||||
IPAddress ia5(25, IPAddress::IPv4);
|
||||
assertTrue (ia5.prefixLength() == 25);
|
||||
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ia6(62, IPAddress::IPv6);
|
||||
assertTrue (ia6.prefixLength() == 62);
|
||||
|
||||
IPAddress ia7(63, IPAddress::IPv6);
|
||||
assertTrue (ia7.prefixLength() == 63);
|
||||
|
||||
IPAddress ia8(64, IPAddress::IPv6);
|
||||
assertTrue (ia8.prefixLength() == 64);
|
||||
|
||||
IPAddress ia9(65, IPAddress::IPv6);
|
||||
assertTrue (ia9.prefixLength() == 65);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testOperators()
|
||||
{
|
||||
IPAddress ip("10.0.0.51");
|
||||
IPAddress mask(24, IPAddress::IPv4);
|
||||
|
||||
IPAddress net = ip & mask;
|
||||
assertTrue (net.toString() == "10.0.0.0");
|
||||
|
||||
IPAddress host("0.0.0.51");
|
||||
assertTrue ((net | host) == ip);
|
||||
|
||||
assertTrue ((~mask).toString() == "0.0.0.255");
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testRelationals6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testByteOrderMacros()
|
||||
{
|
||||
Poco::UInt16 a16 = 0xDEAD;
|
||||
assertTrue (poco_ntoh_16(a16) == ntohs(a16));
|
||||
assertTrue (poco_hton_16(a16) == htons(a16));
|
||||
Poco::UInt32 a32 = 0xDEADBEEF;
|
||||
assertTrue (poco_ntoh_32(a32) == ntohl(a32));
|
||||
assertTrue (poco_hton_32(a32) == htonl(a32));
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* IPAddressTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("IPAddressTest");
|
||||
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testStringConv);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testStringConv6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testParse);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testClassification);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testMCClassification);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testClassification6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testMCClassification6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testRelationals);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testRelationals6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testWildcard);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testBroadcast);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testPrefixCons);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testPrefixLen);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testOperators);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testByteOrderMacros);
|
||||
|
||||
return pSuite;
|
||||
}
|
52
vendor/POCO/Net/testsuite/src/IPAddressTest.h
vendored
Normal file
52
vendor/POCO/Net/testsuite/src/IPAddressTest.h
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// IPAddressTest.h
|
||||
//
|
||||
// Definition of the IPAddressTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef IPAddressTest_INCLUDED
|
||||
#define IPAddressTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class IPAddressTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
IPAddressTest(const std::string& name);
|
||||
~IPAddressTest();
|
||||
|
||||
void testStringConv();
|
||||
void testStringConv6();
|
||||
void testParse();
|
||||
void testClassification();
|
||||
void testMCClassification();
|
||||
void testClassification6();
|
||||
void testMCClassification6();
|
||||
void testRelationals();
|
||||
void testRelationals6();
|
||||
void testWildcard();
|
||||
void testBroadcast();
|
||||
void testPrefixCons();
|
||||
void testPrefixLen();
|
||||
void testOperators();
|
||||
void testByteOrderMacros();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // IPAddressTest_INCLUDED
|
665
vendor/POCO/Net/testsuite/src/MailMessageTest.cpp
vendored
Normal file
665
vendor/POCO/Net/testsuite/src/MailMessageTest.cpp
vendored
Normal file
@ -0,0 +1,665 @@
|
||||
//
|
||||
// MailMessageTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MailMessageTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/MailRecipient.h"
|
||||
#include "Poco/Net/PartHandler.h"
|
||||
#include "Poco/Net/StringPartSource.h"
|
||||
#include "Poco/Net/PartStore.h"
|
||||
#include "Poco/Net/MediaType.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/String.h"
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using Poco::Net::MailMessage;
|
||||
using Poco::Net::MailRecipient;
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::PartHandler;
|
||||
using Poco::Net::MediaType;
|
||||
using Poco::Net::StringPartSource;
|
||||
using Poco::Net::FilePartStoreFactory;
|
||||
using Poco::Net::FilePartStore;
|
||||
using Poco::Timestamp;
|
||||
using Poco::FileInputStream;
|
||||
using Poco::replaceInPlace;
|
||||
using Poco::icompare;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class StringPartHandler: public PartHandler
|
||||
{
|
||||
public:
|
||||
StringPartHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void handlePart(const MessageHeader& header, std::istream& stream)
|
||||
{
|
||||
_disp.push_back(header["Content-Disposition"]);
|
||||
_type.push_back(header["Content-Type"]);
|
||||
std::string data;
|
||||
int ch = stream.get();
|
||||
while (ch > 0)
|
||||
{
|
||||
data += (char) ch;
|
||||
ch = stream.get();
|
||||
}
|
||||
_data.push_back(data);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& data() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& disp() const
|
||||
{
|
||||
return _disp;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> _data;
|
||||
std::vector<std::string> _disp;
|
||||
std::vector<std::string> _type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
MailMessageTest::MailMessageTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MailMessageTest::~MailMessageTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteQP()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
MailRecipient r2(MailRecipient::CC_RECIPIENT, "jane.doe@no.where", "Jane Doe");
|
||||
MailRecipient r3(MailRecipient::BCC_RECIPIENT, "walter.foo@no.where", "Frank Foo");
|
||||
MailRecipient r4(MailRecipient::BCC_RECIPIENT, "bernie.bar@no.where", "Bernie Bar");
|
||||
message.addRecipient(r1);
|
||||
message.addRecipient(r2);
|
||||
message.addRecipient(r3);
|
||||
message.addRecipient(r4);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
|
||||
"And here is some more =fe.\r\n"
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
assertTrue (!message.isMultipart());
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
|
||||
assertTrue (s ==
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"CC: Jane Doe <jane.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
|
||||
"his should be enough.\r\n"
|
||||
"And here is some more =3Dfe.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWrite8Bit()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
message.addRecipient(r1);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n",
|
||||
MailMessage::ENCODING_8BIT
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assertTrue (s ==
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteBase64()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
message.addRecipient(r1);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n",
|
||||
MailMessage::ENCODING_BASE64
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assertTrue (s ==
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"SGVsbG8sIHdvcmxkIQ0KVGhpcyBpcyBhIHRlc3QgZm9yIHRoZSBNYWlsTWVzc2FnZSBjbGFz\r\n"
|
||||
"cy4NCg=="
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteManyRecipients()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
MailRecipient r2(MailRecipient::PRIMARY_RECIPIENT, "jane.doe@no.where", "Jane Doe");
|
||||
MailRecipient r3(MailRecipient::PRIMARY_RECIPIENT, "walter.foo@no.where", "Frank Foo");
|
||||
MailRecipient r4(MailRecipient::PRIMARY_RECIPIENT, "bernie.bar@no.where", "Bernie Bar");
|
||||
MailRecipient r5(MailRecipient::PRIMARY_RECIPIENT, "joe.spammer@no.where", "Joe Spammer");
|
||||
message.addRecipient(r1);
|
||||
message.addRecipient(r2);
|
||||
message.addRecipient(r3);
|
||||
message.addRecipient(r4);
|
||||
message.addRecipient(r5);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n",
|
||||
MailMessage::ENCODING_8BIT
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assertTrue (s ==
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"To: John Doe <john.doe@no.where>, Jane Doe <jane.doe@no.where>, \r\n"
|
||||
"\tFrank Foo <walter.foo@no.where>, Bernie Bar <bernie.bar@no.where>, \r\n"
|
||||
"\tJoe Spammer <joe.spammer@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteMultiPart()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
message.addRecipient(r1);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
message.addContent(new StringPartSource("Hello World!\r\n", "text/plain"), MailMessage::ENCODING_8BIT);
|
||||
StringPartSource* pSPS = new StringPartSource("This is some binary data. Really.", "application/octet-stream", "sample.dat");
|
||||
pSPS->headers().set("Content-ID", "abcd1234");
|
||||
message.addAttachment("sample", pSPS);
|
||||
|
||||
assertTrue (message.isMultipart());
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
std::string rawMsg(
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"Content-Type: multipart/mixed; boundary=$\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"\r\n"
|
||||
"--$\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--$\r\n"
|
||||
"Content-ID: abcd1234\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--$--\r\n"
|
||||
);
|
||||
std::string::size_type p1 = s.find('=') + 1;
|
||||
std::string::size_type p2 = s.find('\r', p1);
|
||||
std::string boundary(s, p1, p2 - p1);
|
||||
std::string msg;
|
||||
for (std::string::const_iterator it = rawMsg.begin(); it != rawMsg.end(); ++it)
|
||||
{
|
||||
if (*it == '$')
|
||||
msg += boundary;
|
||||
else
|
||||
msg += *it;
|
||||
}
|
||||
|
||||
assertTrue (s == msg);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadQP()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
|
||||
"his should be enough.\r\n"
|
||||
"And here is some more =3Dfe.\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assertTrue (message.getSender() == "poco@appinf.com");
|
||||
assertTrue (message.getContentType() == "text/plain");
|
||||
assertTrue (message.getContent() ==
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
|
||||
"And here is some more =fe.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadDefaultTransferEncoding()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assertTrue (message.getSender() == "poco@appinf.com");
|
||||
assertTrue (message.getContentType() == "text/plain");
|
||||
assertTrue (message.getContent() ==
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testRead8Bit()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assertTrue (message.getSender() == "poco@appinf.com");
|
||||
assertTrue (message.getContentType() == "text/plain");
|
||||
assertTrue (message.getContent() ==
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadMultiPart()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--MIME_boundary_01234567--\r\n"
|
||||
);
|
||||
|
||||
StringPartHandler handler;
|
||||
MailMessage message;
|
||||
message.read(istr, handler);
|
||||
|
||||
assertTrue (handler.data().size() == 2);
|
||||
assertTrue (handler.data()[0] == "Hello World!\r\n");
|
||||
assertTrue (handler.type()[0] == "text/plain");
|
||||
assertTrue (handler.disp()[0] == "inline");
|
||||
|
||||
assertTrue (handler.data()[1] == "This is some binary data. Really.");
|
||||
assertTrue (handler.type()[1] == "application/octet-stream; name=sample");
|
||||
assertTrue (handler.disp()[1] == "attachment; filename=sample.dat");
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadMultiPartWithAttachmentNames()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--MIME_boundary_01234567--\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assertTrue (message.parts().size() == 2);
|
||||
assertTrue (message.parts()[1].name == "sample");
|
||||
assertTrue (message.parts()[1].pSource->filename() == "sample.dat");
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadMultiPartDefaultTransferEncoding()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--MIME_boundary_01234567--\r\n"
|
||||
);
|
||||
|
||||
StringPartHandler handler;
|
||||
MailMessage message;
|
||||
message.read(istr, handler);
|
||||
|
||||
assertTrue (handler.data().size() == 2);
|
||||
assertTrue (handler.data()[0] == "Hello World!\r\n");
|
||||
assertTrue (handler.type()[0] == "text/plain");
|
||||
assertTrue (handler.disp()[0] == "inline");
|
||||
|
||||
assertTrue (handler.data()[1] == "This is some binary data. Really.");
|
||||
assertTrue (handler.type()[1] == "application/octet-stream; name=sample");
|
||||
assertTrue (handler.disp()[1] == "attachment; filename=sample.dat");
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadWriteMultiPart()
|
||||
{
|
||||
std::string msgin(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_31E8A8D61DF53389\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_31E8A8D61DF53389\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_31E8A8D61DF53389\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-ID: abcd1234\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--MIME_boundary_31E8A8D61DF53389--\r\n"
|
||||
);
|
||||
|
||||
std::istringstream istr(msgin);
|
||||
std::ostringstream ostr;
|
||||
MailMessage message;
|
||||
|
||||
message.read(istr);
|
||||
message.write(ostr);
|
||||
|
||||
std::string msgout(ostr.str());
|
||||
assertTrue (msgout == msgin);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadWriteMultiPartStore()
|
||||
{
|
||||
std::string msgin(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_31E8A8D61DF53389\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_31E8A8D61DF53389\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_31E8A8D61DF53389\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-ID: abcd1234\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--MIME_boundary_31E8A8D61DF53389--\r\n"
|
||||
);
|
||||
|
||||
std::istringstream istr(msgin);
|
||||
std::ostringstream ostr;
|
||||
FilePartStoreFactory pfsf;
|
||||
MailMessage message(&pfsf);
|
||||
|
||||
message.read(istr);
|
||||
|
||||
MailMessage::PartVec::const_iterator it = message.parts().begin();
|
||||
MailMessage::PartVec::const_iterator end = message.parts().end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
FilePartStore* fps = dynamic_cast<FilePartStore*>(it->pSource);
|
||||
if (fps && fps->filename().size())
|
||||
{
|
||||
std::string filename = fps->filename();
|
||||
assertTrue (filename == "sample.dat");
|
||||
std::string path = fps->path();
|
||||
// for security reasons, the filesystem temporary
|
||||
// filename is not the same as attachment name
|
||||
std::size_t sz = (path.size() > filename.size()) ? filename.size() : path.size();
|
||||
assertTrue (0 != icompare(path, path.size() - sz, sz, path));
|
||||
|
||||
Poco::FileInputStream fis(path);
|
||||
assertTrue (fis.good());
|
||||
std::string read;
|
||||
std::string line;
|
||||
while (std::getline(fis, line)) read += line;
|
||||
|
||||
assertTrue (!read.empty());
|
||||
assertTrue (read == "This is some binary data. Really.");
|
||||
}
|
||||
}
|
||||
|
||||
message.write(ostr);
|
||||
std::string msgout(ostr.str());
|
||||
assertTrue (msgout == msgin);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testEncodeWord()
|
||||
{
|
||||
std::string plain("this is pure ASCII");
|
||||
std::string encoded = MailMessage::encodeWord(plain, "ISO-8859-1");
|
||||
assertTrue (encoded == plain);
|
||||
|
||||
plain = "This text contains German Umlauts: \304\326";
|
||||
encoded = MailMessage::encodeWord(plain, "ISO-8859-1");
|
||||
assertTrue (encoded == "=?ISO-8859-1?q?This_text_contains_German_Umlauts=3A_=C4=D6?=");
|
||||
|
||||
plain = "This text contains German Umlauts: \304\326. "
|
||||
"It is also a very long text. Longer than 75 "
|
||||
"characters. Long enough to become three lines "
|
||||
"after being word-encoded.";
|
||||
encoded = MailMessage::encodeWord(plain, "ISO-8859-1");
|
||||
assertTrue (encoded == "=?ISO-8859-1?q?This_text_contains_German_Umlauts=3A_=C4=D6=2E_It_?=\r\n"
|
||||
" =?ISO-8859-1?q?is_also_a_very_long_text=2E_Longer_than_75_characters=2E_?=\r\n"
|
||||
" =?ISO-8859-1?q?Long_enough_to_become_three_lines_after_being_word-encode?=\r\n"
|
||||
" =?ISO-8859-1?q?d=2E?=");
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MailMessageTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailMessageTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteQP);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWrite8Bit);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteBase64);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteManyRecipients);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadQP);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadDefaultTransferEncoding);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartDefaultTransferEncoding);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPartStore);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testEncodeWord);
|
||||
|
||||
return pSuite;
|
||||
}
|
51
vendor/POCO/Net/testsuite/src/MailMessageTest.h
vendored
Normal file
51
vendor/POCO/Net/testsuite/src/MailMessageTest.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// MailMessageTest.h
|
||||
//
|
||||
// Definition of the MailMessageTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MailMessageTest_INCLUDED
|
||||
#define MailMessageTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MailMessageTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MailMessageTest(const std::string& name);
|
||||
~MailMessageTest();
|
||||
|
||||
void testWriteQP();
|
||||
void testWrite8Bit();
|
||||
void testWriteBase64();
|
||||
void testWriteManyRecipients();
|
||||
void testWriteMultiPart();
|
||||
void testReadWriteMultiPart();
|
||||
void testReadWriteMultiPartStore();
|
||||
void testReadDefaultTransferEncoding();
|
||||
void testReadQP();
|
||||
void testRead8Bit();
|
||||
void testReadMultiPart();
|
||||
void testReadMultiPartWithAttachmentNames();
|
||||
void testReadMultiPartDefaultTransferEncoding();
|
||||
void testEncodeWord();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MailMessageTest_INCLUDED
|
121
vendor/POCO/Net/testsuite/src/MailStreamTest.cpp
vendored
Normal file
121
vendor/POCO/Net/testsuite/src/MailStreamTest.cpp
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
//
|
||||
// MailStreamTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MailStreamTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/MailStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MailInputStream;
|
||||
using Poco::Net::MailOutputStream;
|
||||
using Poco::StreamCopier;
|
||||
|
||||
|
||||
MailStreamTest::MailStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MailStreamTest::~MailStreamTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::testMailInputStream()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
".This line starts with a period.\r\n"
|
||||
"..and this one too\r\n"
|
||||
"..\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
|
||||
MailInputStream mis(istr);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(mis, ostr);
|
||||
std::string s(ostr.str());
|
||||
assertTrue (s ==
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
".This line starts with a period.\r\n"
|
||||
".and this one too\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::testMailOutputStream()
|
||||
{
|
||||
std::string msg(
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
".This line starts with a period.\r\n"
|
||||
"\r\n"
|
||||
".and this one too\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
|
||||
std::ostringstream ostr;
|
||||
MailOutputStream mos(ostr);
|
||||
mos << msg;
|
||||
mos.close();
|
||||
std::string s(ostr.str());
|
||||
assertTrue (s ==
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
"..This line starts with a period.\r\n"
|
||||
"\r\n"
|
||||
"..and this one too\r\n"
|
||||
"..\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MailStreamTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailStreamTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MailStreamTest, testMailInputStream);
|
||||
CppUnit_addTest(pSuite, MailStreamTest, testMailOutputStream);
|
||||
|
||||
return pSuite;
|
||||
}
|
39
vendor/POCO/Net/testsuite/src/MailStreamTest.h
vendored
Normal file
39
vendor/POCO/Net/testsuite/src/MailStreamTest.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// MailStreamTest.h
|
||||
//
|
||||
// Definition of the MailStreamTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MailStreamTest_INCLUDED
|
||||
#define MailStreamTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MailStreamTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MailStreamTest(const std::string& name);
|
||||
~MailStreamTest();
|
||||
|
||||
void testMailInputStream();
|
||||
void testMailOutputStream();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MailStreamTest_INCLUDED
|
28
vendor/POCO/Net/testsuite/src/MailTestSuite.cpp
vendored
Normal file
28
vendor/POCO/Net/testsuite/src/MailTestSuite.cpp
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// MailTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MailTestSuite.h"
|
||||
#include "MailMessageTest.h"
|
||||
#include "MailStreamTest.h"
|
||||
#include "SMTPClientSessionTest.h"
|
||||
#include "POP3ClientSessionTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* MailTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailTestSuite");
|
||||
|
||||
pSuite->addTest(MailMessageTest::suite());
|
||||
pSuite->addTest(MailStreamTest::suite());
|
||||
pSuite->addTest(SMTPClientSessionTest::suite());
|
||||
pSuite->addTest(POP3ClientSessionTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/MailTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/MailTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// MailTestSuite.h
|
||||
//
|
||||
// Definition of the MailTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MailTestSuite_INCLUDED
|
||||
#define MailTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class MailTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // MailTestSuite_INCLUDED
|
138
vendor/POCO/Net/testsuite/src/MediaTypeTest.cpp
vendored
Normal file
138
vendor/POCO/Net/testsuite/src/MediaTypeTest.cpp
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
//
|
||||
// MediaTypeTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MediaTypeTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/MediaType.h"
|
||||
|
||||
|
||||
using Poco::Net::MediaType;
|
||||
|
||||
|
||||
MediaTypeTest::MediaTypeTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MediaTypeTest::~MediaTypeTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testParse()
|
||||
{
|
||||
MediaType mt1("text/plain");
|
||||
assertTrue (mt1.getType() == "text");
|
||||
assertTrue (mt1.getSubType() == "plain");
|
||||
assertTrue (mt1.parameters().empty());
|
||||
|
||||
MediaType mt2("text/xml;charset=us-ascii");
|
||||
assertTrue (mt2.getType() == "text");
|
||||
assertTrue (mt2.getSubType() == "xml");
|
||||
assertTrue (mt2.parameters().size() == 1);
|
||||
assertTrue (mt2.getParameter("charset") == "us-ascii");
|
||||
|
||||
MediaType mt3("application/test; param1=value1; param2=\"value 2\"");
|
||||
assertTrue (mt3.getType() == "application");
|
||||
assertTrue (mt3.getSubType() == "test");
|
||||
assertTrue (mt3.parameters().size() == 2);
|
||||
assertTrue (mt3.getParameter("param1") == "value1");
|
||||
assertTrue (mt3.getParameter("PARAM2") == "value 2");
|
||||
|
||||
MediaType mt4("multipart/mixed; boundary=\"MIME_boundary_01234567\"");
|
||||
assertTrue (mt4.getType() == "multipart");
|
||||
assertTrue (mt4.getSubType() == "mixed");
|
||||
assertTrue (mt4.parameters().size() == 1);
|
||||
assertTrue (mt4.getParameter("boundary") == "MIME_boundary_01234567");
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testToString()
|
||||
{
|
||||
MediaType mt1("text", "plain");
|
||||
assertTrue (mt1.toString() == "text/plain");
|
||||
|
||||
mt1.setParameter("charset", "iso-8859-1");
|
||||
assertTrue (mt1.toString() == "text/plain; charset=iso-8859-1");
|
||||
|
||||
MediaType mt2("application", "test");
|
||||
mt2.setParameter("param1", "value1");
|
||||
mt2.setParameter("param2", "value 2");
|
||||
assertTrue (mt2.toString() == "application/test; param1=value1; param2=\"value 2\"");
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testMatch()
|
||||
{
|
||||
MediaType mt1("Text/Plain");
|
||||
MediaType mt2("text/plain");
|
||||
MediaType mt3("text/xml");
|
||||
assertTrue (mt1.matches(mt2));
|
||||
assertTrue (!mt1.matches(mt3));
|
||||
assertTrue (mt1.matches("text"));
|
||||
assertTrue (mt2.matches("text"));
|
||||
assertTrue (mt3.matches("text"));
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testMatchRange()
|
||||
{
|
||||
MediaType mt1("Text/Plain");
|
||||
MediaType mt2("text/plain");
|
||||
MediaType mt3("text/xml");
|
||||
MediaType mt4("image/jpg");
|
||||
MediaType mt5("text/*");
|
||||
MediaType mt6("*/*");
|
||||
assertTrue (mt1.matchesRange(mt5));
|
||||
assertTrue (mt2.matchesRange(mt5));
|
||||
assertTrue (mt3.matchesRange(mt5));
|
||||
assertTrue (!mt4.matchesRange(mt5));
|
||||
assertTrue (mt1.matchesRange(mt6));
|
||||
assertTrue (mt2.matchesRange(mt6));
|
||||
assertTrue (mt3.matchesRange(mt6));
|
||||
assertTrue (mt4.matchesRange(mt6));
|
||||
|
||||
assertTrue (mt5.matchesRange(mt1));
|
||||
assertTrue (mt5.matchesRange(mt2));
|
||||
assertTrue (mt5.matchesRange(mt3));
|
||||
assertTrue (!mt5.matchesRange(mt4));
|
||||
|
||||
assertTrue (mt1.matchesRange("text", "*"));
|
||||
assertTrue (mt2.matchesRange("text", "*"));
|
||||
assertTrue (mt3.matchesRange("text", "*"));
|
||||
assertTrue (!mt4.matchesRange("text", "*"));
|
||||
|
||||
assertTrue (mt1.matchesRange("*"));
|
||||
assertTrue (mt4.matchesRange("*"));
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MediaTypeTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MediaTypeTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testParse);
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testToString);
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testMatch);
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testMatchRange);
|
||||
|
||||
return pSuite;
|
||||
}
|
41
vendor/POCO/Net/testsuite/src/MediaTypeTest.h
vendored
Normal file
41
vendor/POCO/Net/testsuite/src/MediaTypeTest.h
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// MediaTypeTest.h
|
||||
//
|
||||
// Definition of the MediaTypeTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MediaTypeTest_INCLUDED
|
||||
#define MediaTypeTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MediaTypeTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MediaTypeTest(const std::string& name);
|
||||
~MediaTypeTest();
|
||||
|
||||
void testParse();
|
||||
void testToString();
|
||||
void testMatch();
|
||||
void testMatchRange();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MediaTypeTest_INCLUDED
|
413
vendor/POCO/Net/testsuite/src/MessageHeaderTest.cpp
vendored
Normal file
413
vendor/POCO/Net/testsuite/src/MessageHeaderTest.cpp
vendored
Normal file
@ -0,0 +1,413 @@
|
||||
//
|
||||
// MessageHeaderTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MessageHeaderTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/MessageHeader.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::NameValueCollection;
|
||||
using Poco::Net::MessageException;
|
||||
|
||||
|
||||
MessageHeaderTest::MessageHeaderTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MessageHeaderTest::~MessageHeaderTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testWrite()
|
||||
{
|
||||
MessageHeader mh;
|
||||
mh.set("name1", "value1");
|
||||
mh.set("name2", "value2");
|
||||
mh.set("name3", "value3");
|
||||
|
||||
std::ostringstream ostr;
|
||||
mh.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "name1: value1\r\nname2: value2\r\nname3: value3\r\n");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead1()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value2\r\nname3: value3\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 3);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value2");
|
||||
assertTrue (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead2()
|
||||
{
|
||||
std::string s("name1: value1\nname2: value2\nname3: value3\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 3);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value2");
|
||||
assertTrue (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead3()
|
||||
{
|
||||
std::string s("name1: value1\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 1);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead4()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value2\r\n\r\nsomedata");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 2);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value2");
|
||||
int ch = istr.get();
|
||||
assertTrue (ch == '\r');
|
||||
ch = istr.get();
|
||||
assertTrue (ch == '\n');
|
||||
ch = istr.get();
|
||||
assertTrue (ch == 's');
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead5()
|
||||
{
|
||||
std::string s("name1:\r\nname2: value2\r\nname3: value3 \r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 3);
|
||||
assertTrue (mh["name1"] == "");
|
||||
assertTrue (mh["name2"] == "value2");
|
||||
assertTrue (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding1()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\nname3: value3\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 3);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value21 value22");
|
||||
assertTrue (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding2()
|
||||
{
|
||||
std::string s("name1: value1\nname2: value21\n\tvalue22\nname3: value3\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 3);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value21\tvalue22");
|
||||
assertTrue (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding3()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 2);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value21 value22");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding4()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n value23");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 2);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value21 value22 value23");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding5()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n value23\r\nname3: value3");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assertTrue (mh.size() == 3);
|
||||
assertTrue (mh["name1"] == "value1");
|
||||
assertTrue (mh["name2"] == "value21 value22 value23");
|
||||
assertTrue (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadInvalid1()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n value23\r\n");
|
||||
s.append(300, 'x');
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
try
|
||||
{
|
||||
mh.read(istr);
|
||||
fail("malformed message - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadInvalid2()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: ");
|
||||
s.append(9000, 'x');
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
try
|
||||
{
|
||||
mh.read(istr);
|
||||
fail("malformed message - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testSplitElements()
|
||||
{
|
||||
std::string s;
|
||||
std::vector<std::string> v;
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.empty());
|
||||
|
||||
s = "foo";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 1);
|
||||
assertTrue (v[0] == "foo");
|
||||
|
||||
s = " foo ";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 1);
|
||||
assertTrue (v[0] == "foo");
|
||||
|
||||
s = "foo,bar";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 2);
|
||||
assertTrue (v[0] == "foo");
|
||||
assertTrue (v[1] == "bar");
|
||||
|
||||
s = "foo,,bar";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 2);
|
||||
assertTrue (v[0] == "foo");
|
||||
assertTrue (v[1] == "bar");
|
||||
|
||||
MessageHeader::splitElements(s, v, false);
|
||||
assertTrue (v.size() == 3);
|
||||
assertTrue (v[0] == "foo");
|
||||
assertTrue (v[1] == "");
|
||||
assertTrue (v[2] == "bar");
|
||||
|
||||
s = "foo;param=\"a,b\",bar;param=\"c,d\"";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 2);
|
||||
assertTrue (v[0] == "foo;param=\"a,b\"");
|
||||
assertTrue (v[1] == "bar;param=\"c,d\"");
|
||||
|
||||
s = "foo; param=\"a,b\", bar; param=\"c,d\"";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 2);
|
||||
assertTrue (v[0] == "foo; param=\"a,b\"");
|
||||
assertTrue (v[1] == "bar; param=\"c,d\"");
|
||||
|
||||
s = "foo, bar, f00, baz";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 4);
|
||||
assertTrue (v[0] == "foo");
|
||||
assertTrue (v[1] == "bar");
|
||||
assertTrue (v[2] == "f00");
|
||||
assertTrue (v[3] == "baz");
|
||||
|
||||
s = "a,b,c";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 3);
|
||||
assertTrue (v[0] == "a");
|
||||
assertTrue (v[1] == "b");
|
||||
assertTrue (v[2] == "c");
|
||||
|
||||
s = "a=\"value=\\\\\\\"foo, bar\\\\\\\"\",b=foo";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 2);
|
||||
assertTrue (v[0] == "a=\"value=\\\"foo, bar\\\"\"");
|
||||
assertTrue (v[1] == "b=foo");
|
||||
|
||||
s = "a=\\\",b=\\\"";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assertTrue (v.size() == 2);
|
||||
assertTrue (v[0] == "a=\"");
|
||||
assertTrue (v[1] == "b=\"");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testSplitParameters()
|
||||
{
|
||||
std::string s;
|
||||
std::string v;
|
||||
NameValueCollection p;
|
||||
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v.empty());
|
||||
assertTrue (p.empty());
|
||||
|
||||
s = "multipart/related";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "multipart/related");
|
||||
assertTrue (p.empty());
|
||||
|
||||
s = "multipart/related; boundary=MIME_boundary_01234567";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "multipart/related");
|
||||
assertTrue (p.size() == 1);
|
||||
assertTrue (p["boundary"] == "MIME_boundary_01234567");
|
||||
|
||||
s = "multipart/related; boundary=\"MIME_boundary_76543210\"";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "multipart/related");
|
||||
assertTrue (p.size() == 1);
|
||||
assertTrue (p["boundary"] == "MIME_boundary_76543210");
|
||||
|
||||
s = "text/plain; charset=us-ascii";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "text/plain");
|
||||
assertTrue (p.size() == 1);
|
||||
assertTrue (p["charset"] == "us-ascii");
|
||||
|
||||
s = "value; p1=foo; p2=bar";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "value");
|
||||
assertTrue (p.size() == 2);
|
||||
assertTrue (p["p1"] == "foo");
|
||||
assertTrue (p["p2"] == "bar");
|
||||
|
||||
s = "value; p1=\"foo; bar\"";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "value");
|
||||
assertTrue (p.size() == 1);
|
||||
assertTrue (p["p1"] == "foo; bar");
|
||||
|
||||
s = "value ; p1=foo ; p2=bar ";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assertTrue (v == "value");
|
||||
assertTrue (p.size() == 2);
|
||||
assertTrue (p["p1"] == "foo");
|
||||
assertTrue (p["p2"] == "bar");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testFieldLimit()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value2\r\nname3: value3\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.setFieldLimit(2);
|
||||
try
|
||||
{
|
||||
mh.read(istr);
|
||||
fail("Field limit exceeded - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testDecodeWord()
|
||||
{
|
||||
std::string coded("this is pure ASCII");
|
||||
std::string decoded = MessageHeader::decodeWord(coded, "ISO-8859-1");
|
||||
assertTrue (decoded == coded);
|
||||
|
||||
coded = "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)";
|
||||
decoded = MessageHeader::decodeWord(coded, "ISO-8859-1");
|
||||
assertTrue (decoded == "(a b)");
|
||||
|
||||
coded = "Hello =?UTF-8?B?RnJhbmNpcw==?=, good bye";
|
||||
decoded = MessageHeader::decodeWord(coded, "ISO-8859-1");
|
||||
assertTrue (decoded == "Hello Francis, good bye");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MessageHeaderTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MessageHeaderTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MessageHeaderTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testWrite);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead1);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead2);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead3);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead4);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead5);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding1);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding2);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding3);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding4);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding5);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadInvalid1);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadInvalid2);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testSplitElements);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testSplitParameters);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testFieldLimit);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testDecodeWord);
|
||||
|
||||
return pSuite;
|
||||
}
|
54
vendor/POCO/Net/testsuite/src/MessageHeaderTest.h
vendored
Normal file
54
vendor/POCO/Net/testsuite/src/MessageHeaderTest.h
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// MessageHeaderTest.h
|
||||
//
|
||||
// Definition of the MessageHeaderTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MessageHeaderTest_INCLUDED
|
||||
#define MessageHeaderTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MessageHeaderTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MessageHeaderTest(const std::string& name);
|
||||
~MessageHeaderTest();
|
||||
|
||||
void testWrite();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testRead4();
|
||||
void testRead5();
|
||||
void testReadFolding1();
|
||||
void testReadFolding2();
|
||||
void testReadFolding3();
|
||||
void testReadFolding4();
|
||||
void testReadFolding5();
|
||||
void testReadInvalid1();
|
||||
void testReadInvalid2();
|
||||
void testSplitElements();
|
||||
void testSplitParameters();
|
||||
void testFieldLimit();
|
||||
void testDecodeWord();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MessageHeaderTest_INCLUDED
|
32
vendor/POCO/Net/testsuite/src/MessagesTestSuite.cpp
vendored
Normal file
32
vendor/POCO/Net/testsuite/src/MessagesTestSuite.cpp
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// MessagesTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MessagesTestSuite.h"
|
||||
#include "NameValueCollectionTest.h"
|
||||
#include "MessageHeaderTest.h"
|
||||
#include "MediaTypeTest.h"
|
||||
#include "MultipartWriterTest.h"
|
||||
#include "MultipartReaderTest.h"
|
||||
#include "QuotedPrintableTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* MessagesTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MessagesTestSuite");
|
||||
|
||||
pSuite->addTest(NameValueCollectionTest::suite());
|
||||
pSuite->addTest(MessageHeaderTest::suite());
|
||||
pSuite->addTest(MediaTypeTest::suite());
|
||||
pSuite->addTest(MultipartWriterTest::suite());
|
||||
pSuite->addTest(MultipartReaderTest::suite());
|
||||
pSuite->addTest(QuotedPrintableTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/MessagesTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/MessagesTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// MessagesTestSuite.h
|
||||
//
|
||||
// Definition of the MessagesTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MessagesTestSuite_INCLUDED
|
||||
#define MessagesTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class MessagesTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // MessagesTestSuite_INCLUDED
|
107
vendor/POCO/Net/testsuite/src/MulticastEchoServer.cpp
vendored
Normal file
107
vendor/POCO/Net/testsuite/src/MulticastEchoServer.cpp
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
//
|
||||
// MulticastEchoServer.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MulticastEchoServer.h"
|
||||
|
||||
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#include "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::DatagramSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::NetworkInterface;
|
||||
|
||||
|
||||
MulticastEchoServer::MulticastEchoServer():
|
||||
_group("239.255.1.2", 12345),
|
||||
_if(findInterface()),
|
||||
_thread("MulticastEchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_socket.bind(SocketAddress(IPAddress(), _group.port()), true);
|
||||
_socket.joinGroup(_group.host(), _if);
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
MulticastEchoServer::~MulticastEchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
_socket.leaveGroup(_group.host(), _if);
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 MulticastEchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void MulticastEchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
SocketAddress sender;
|
||||
int n = _socket.receiveFrom(buffer, sizeof(buffer), sender);
|
||||
_socket.sendTo(buffer, n, sender);
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "MulticastEchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const SocketAddress& MulticastEchoServer::group() const
|
||||
{
|
||||
return _group;
|
||||
}
|
||||
|
||||
|
||||
const NetworkInterface& MulticastEchoServer::interfc() const
|
||||
{
|
||||
return _if;
|
||||
}
|
||||
|
||||
|
||||
Poco::Net::NetworkInterface MulticastEchoServer::findInterface()
|
||||
{
|
||||
NetworkInterface::Map m = NetworkInterface::map();
|
||||
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
|
||||
{
|
||||
if (it->second.supportsIPv4() &&
|
||||
it->second.firstAddress(IPAddress::IPv4).isUnicast() &&
|
||||
!it->second.isLoopback() &&
|
||||
!it->second.isPointToPoint())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
return NetworkInterface();
|
||||
}
|
||||
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
71
vendor/POCO/Net/testsuite/src/MulticastEchoServer.h
vendored
Normal file
71
vendor/POCO/Net/testsuite/src/MulticastEchoServer.h
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// MulticastEchoServer.h
|
||||
//
|
||||
// Definition of the MulticastEchoServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MulticastEchoServer_INCLUDED
|
||||
#define MulticastEchoServer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
|
||||
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#include "Poco/Net/MulticastSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetworkInterface.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
class MulticastEchoServer: public Poco::Runnable
|
||||
/// A simple sequential Multicast echo server.
|
||||
{
|
||||
public:
|
||||
MulticastEchoServer();
|
||||
/// Creates the MulticastEchoServer.
|
||||
|
||||
~MulticastEchoServer();
|
||||
/// Destroys the MulticastEchoServer.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const Poco::Net::SocketAddress& group() const;
|
||||
/// Returns the group address where the server listens.
|
||||
|
||||
const Poco::Net::NetworkInterface& interfc() const;
|
||||
/// Returns the network interface for multicasting.
|
||||
|
||||
protected:
|
||||
static Poco::Net::NetworkInterface findInterface();
|
||||
/// Finds an appropriate network interface for
|
||||
/// multicasting.
|
||||
|
||||
private:
|
||||
Poco::Net::MulticastSocket _socket;
|
||||
Poco::Net::SocketAddress _group;
|
||||
Poco::Net::NetworkInterface _if;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#endif // MulticastEchoServer_INCLUDED
|
92
vendor/POCO/Net/testsuite/src/MulticastSocketTest.cpp
vendored
Normal file
92
vendor/POCO/Net/testsuite/src/MulticastSocketTest.cpp
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// MulticastSocketTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MulticastSocketTest.h"
|
||||
|
||||
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "MulticastEchoServer.h"
|
||||
#include "Poco/Net/MulticastSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::MulticastSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::IOException;
|
||||
|
||||
|
||||
MulticastSocketTest::MulticastSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MulticastSocketTest::~MulticastSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocketTest::testMulticast()
|
||||
{
|
||||
try
|
||||
{
|
||||
MulticastEchoServer echoServer;
|
||||
MulticastSocket ms(SocketAddress::IPv4);
|
||||
ms.setReceiveTimeout(Poco::Timespan(5, 0));
|
||||
int n = ms.sendTo("hello", 5, echoServer.group());
|
||||
assertTrue (n == 5);
|
||||
char buffer[256];
|
||||
n = ms.receiveBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "hello");
|
||||
ms.close();
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MulticastSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MulticastSocketTest");
|
||||
#if (POCO_OS != POCO_OS_FREE_BSD) // TODO
|
||||
CppUnit_addTest(pSuite, MulticastSocketTest, testMulticast);
|
||||
#endif
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
46
vendor/POCO/Net/testsuite/src/MulticastSocketTest.h
vendored
Normal file
46
vendor/POCO/Net/testsuite/src/MulticastSocketTest.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// MulticastSocketTest.h
|
||||
//
|
||||
// Definition of the MulticastSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MulticastSocketTest_INCLUDED
|
||||
#define MulticastSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
|
||||
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MulticastSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MulticastSocketTest(const std::string& name);
|
||||
~MulticastSocketTest();
|
||||
|
||||
void testMulticast();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#endif // MulticastSocketTest_INCLUDED
|
378
vendor/POCO/Net/testsuite/src/MultipartReaderTest.cpp
vendored
Normal file
378
vendor/POCO/Net/testsuite/src/MultipartReaderTest.cpp
vendored
Normal file
@ -0,0 +1,378 @@
|
||||
//
|
||||
// MultipartReaderTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MultipartReaderTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/MultipartReader.h"
|
||||
#include "Poco/Net/MessageHeader.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MultipartReader;
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::MultipartException;
|
||||
|
||||
|
||||
MultipartReaderTest::MultipartReaderTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MultipartReaderTest::~MultipartReaderTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadOnePart()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.boundary() == "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is part 1");
|
||||
assertTrue (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadTwoParts()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is part 1");
|
||||
assertTrue (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assertTrue (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assertTrue (part == "this is part 2\r\n");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadEmptyLines()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is\r\npart 1\r\n\r\n--MIME_boundary_01234567\r\n\r\nthis\r\n\r\nis part 2\r\n\r\n\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is\r\npart 1\r\n");
|
||||
assertTrue (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assertTrue (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assertTrue (part == "this\r\n\r\nis part 2\r\n\r\n");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadLongPart()
|
||||
{
|
||||
std::string longPart(3000, 'X');
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\n");
|
||||
s.append(longPart);
|
||||
s.append("\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == longPart);
|
||||
assertTrue (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assertTrue (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assertTrue (part == "this is part 2");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testGuessBoundary()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr);
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (r.boundary() == "MIME_boundary_01234567");
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is part 1");
|
||||
assertTrue (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testPreamble()
|
||||
{
|
||||
std::string s("this is the\r\npreamble\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is part 1");
|
||||
assertTrue (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testBadBoundary()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_7654321");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testRobustness()
|
||||
{
|
||||
std::string s("--MIME_boundary_01234567\rname1: value1\r\n\nthis is part 1\n--MIME_boundary_01234567--");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is part 1");
|
||||
assertTrue (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testUnixLineEnds()
|
||||
{
|
||||
std::string s("\n--MIME_boundary_01234567\nname1: value1\n\nthis is part 1\n--MIME_boundary_01234567\n\nthis is part 2\n\n--MIME_boundary_01234567--\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assertTrue (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assertTrue (h.size() == 1);
|
||||
assertTrue (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assertTrue (part == "this is part 1");
|
||||
assertTrue (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assertTrue (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assertTrue (part == "this is part 2\n");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MultipartReaderTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MultipartReaderTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadOnePart);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadTwoParts);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadEmptyLines);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadLongPart);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testGuessBoundary);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testPreamble);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testBadBoundary);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testRobustness);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testUnixLineEnds);
|
||||
|
||||
return pSuite;
|
||||
}
|
46
vendor/POCO/Net/testsuite/src/MultipartReaderTest.h
vendored
Normal file
46
vendor/POCO/Net/testsuite/src/MultipartReaderTest.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// MultipartReaderTest.h
|
||||
//
|
||||
// Definition of the MultipartReaderTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MultipartReaderTest_INCLUDED
|
||||
#define MultipartReaderTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MultipartReaderTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MultipartReaderTest(const std::string& name);
|
||||
~MultipartReaderTest();
|
||||
|
||||
void testReadOnePart();
|
||||
void testReadTwoParts();
|
||||
void testReadEmptyLines();
|
||||
void testReadLongPart();
|
||||
void testGuessBoundary();
|
||||
void testPreamble();
|
||||
void testBadBoundary();
|
||||
void testRobustness();
|
||||
void testUnixLineEnds();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MultipartReaderTest_INCLUDED
|
94
vendor/POCO/Net/testsuite/src/MultipartWriterTest.cpp
vendored
Normal file
94
vendor/POCO/Net/testsuite/src/MultipartWriterTest.cpp
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// MultipartWriterTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "MultipartWriterTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/MultipartWriter.h"
|
||||
#include "Poco/Net/MessageHeader.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MultipartWriter;
|
||||
using Poco::Net::MessageHeader;
|
||||
|
||||
|
||||
MultipartWriterTest::MultipartWriterTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MultipartWriterTest::~MultipartWriterTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::testWriteOnePart()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
MultipartWriter w(ostr, "MIME_boundary_01234567");
|
||||
assertTrue (w.boundary() == "MIME_boundary_01234567");
|
||||
MessageHeader h;
|
||||
h.set("name1", "value1");
|
||||
w.nextPart(h);
|
||||
ostr << "this is part 1";
|
||||
w.close();
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::testWriteTwoParts()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
MultipartWriter w(ostr, "MIME_boundary_01234567");
|
||||
MessageHeader h;
|
||||
h.set("name1", "value1");
|
||||
w.nextPart(h);
|
||||
ostr << "this is part 1";
|
||||
h.clear();
|
||||
w.nextPart(h);
|
||||
ostr << "this is part 2";
|
||||
w.close();
|
||||
std::string s = ostr.str();
|
||||
assertTrue (s == "--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::testBoundary()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
MultipartWriter w(ostr);
|
||||
std::string boundary = w.boundary();
|
||||
assertTrue (boundary.substr(0, 14) == "MIME_boundary_");
|
||||
assertTrue (boundary.length() == 14 + 16);
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MultipartWriterTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MultipartWriterTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MultipartWriterTest, testWriteOnePart);
|
||||
CppUnit_addTest(pSuite, MultipartWriterTest, testWriteTwoParts);
|
||||
CppUnit_addTest(pSuite, MultipartWriterTest, testBoundary);
|
||||
|
||||
return pSuite;
|
||||
}
|
40
vendor/POCO/Net/testsuite/src/MultipartWriterTest.h
vendored
Normal file
40
vendor/POCO/Net/testsuite/src/MultipartWriterTest.h
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// MultipartWriterTest.h
|
||||
//
|
||||
// Definition of the MultipartWriterTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MultipartWriterTest_INCLUDED
|
||||
#define MultipartWriterTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MultipartWriterTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MultipartWriterTest(const std::string& name);
|
||||
~MultipartWriterTest();
|
||||
|
||||
void testWriteOnePart();
|
||||
void testWriteTwoParts();
|
||||
void testBoundary();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MultipartWriterTest_INCLUDED
|
279
vendor/POCO/Net/testsuite/src/NTLMCredentialsTest.cpp
vendored
Normal file
279
vendor/POCO/Net/testsuite/src/NTLMCredentialsTest.cpp
vendored
Normal file
@ -0,0 +1,279 @@
|
||||
//
|
||||
// NTLMCredentialsTest.cpp
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NTLMCredentialsTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/NTLMCredentials.h"
|
||||
#include "Poco/DigestEngine.h"
|
||||
|
||||
|
||||
using Poco::Net::NTLMCredentials;
|
||||
|
||||
|
||||
NTLMCredentialsTest::NTLMCredentialsTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NTLMCredentialsTest::~NTLMCredentialsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testNonce()
|
||||
{
|
||||
std::vector<unsigned char> nonce1 = NTLMCredentials::createNonce();
|
||||
assertTrue (nonce1.size() == 8);
|
||||
|
||||
std::vector<unsigned char> nonce2 = NTLMCredentials::createNonce();
|
||||
assertTrue (nonce2.size() == 8);
|
||||
|
||||
assertTrue (nonce1 != nonce2);
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testPasswordHash()
|
||||
{
|
||||
std::vector<unsigned char> passHash = NTLMCredentials::createPasswordHash("SecREt01");
|
||||
std::string passHashHex = Poco::DigestEngine::digestToHex(passHash);
|
||||
assertTrue (passHashHex == "cd06ca7c7e10c99b1d33b7485a2ed808");
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testNTLMv2Hash()
|
||||
{
|
||||
std::vector<unsigned char> ntlm2Hash = NTLMCredentials::createNTLMv2Hash("user", "DOMAIN", "SecREt01");
|
||||
std::string ntlm2HashHex = Poco::DigestEngine::digestToHex(ntlm2Hash);
|
||||
assertTrue (ntlm2HashHex == "04b8e0ba74289cc540826bab1dee63ae");
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testLMv2Response()
|
||||
{
|
||||
static const unsigned char CHALLENGE[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
|
||||
static const unsigned char NONCE[] = {0xff, 0xff, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44};
|
||||
|
||||
std::vector<unsigned char> challenge(CHALLENGE, CHALLENGE + 8);
|
||||
std::vector<unsigned char> nonce(NONCE, NONCE + 8);
|
||||
|
||||
std::vector<unsigned char> ntlm2Hash = NTLMCredentials::createNTLMv2Hash("user", "DOMAIN", "SecREt01");
|
||||
std::vector<unsigned char> lm2Response = NTLMCredentials::createLMv2Response(ntlm2Hash, challenge, nonce);
|
||||
|
||||
std::string lm2ResponseHex = Poco::DigestEngine::digestToHex(lm2Response);
|
||||
assertTrue (lm2ResponseHex == "d6e6152ea25d03b7c6ba6629c2d6aaf0ffffff0011223344");
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testNTLMv2Response()
|
||||
{
|
||||
static const unsigned char CHALLENGE[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
|
||||
static const unsigned char NONCE[] = {0xff, 0xff, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44};
|
||||
static const unsigned char TARGET_INFO[] = {
|
||||
0x02, 0x00, 0x0c, 0x00, 0x44, 0x00, 0x4f, 0x00,
|
||||
0x4d, 0x00, 0x41, 0x00, 0x49, 0x00, 0x4e, 0x00,
|
||||
0x01, 0x00, 0x0c, 0x00, 0x53, 0x00, 0x45, 0x00,
|
||||
0x52, 0x00, 0x56, 0x00, 0x45, 0x00, 0x52, 0x00,
|
||||
0x04, 0x00, 0x14, 0x00, 0x64, 0x00, 0x6f, 0x00,
|
||||
0x6d, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6e, 0x00,
|
||||
0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00,
|
||||
0x03, 0x00, 0x22, 0x00, 0x73, 0x00, 0x65, 0x00,
|
||||
0x72, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00,
|
||||
0x2e, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x6d, 0x00,
|
||||
0x61, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x2e, 0x00,
|
||||
0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
std::vector<unsigned char> challenge(CHALLENGE, CHALLENGE + 8);
|
||||
std::vector<unsigned char> nonce(NONCE, NONCE + 8);
|
||||
std::vector<unsigned char> targetInfo(TARGET_INFO, TARGET_INFO + sizeof(TARGET_INFO));
|
||||
|
||||
std::vector<unsigned char> ntlm2Hash = NTLMCredentials::createNTLMv2Hash("user", "DOMAIN", "SecREt01");
|
||||
Poco::UInt64 timestamp = Poco::UInt64(12700317600)*10000000;
|
||||
|
||||
std::vector<unsigned char> ntlm2Response = NTLMCredentials::createNTLMv2Response(
|
||||
ntlm2Hash,
|
||||
challenge,
|
||||
nonce,
|
||||
targetInfo,
|
||||
timestamp);
|
||||
|
||||
std::string ntlm2ResponseHex = Poco::DigestEngine::digestToHex(ntlm2Response);
|
||||
|
||||
assertTrue (ntlm2ResponseHex ==
|
||||
"cbabbca713eb795d04c97abc01ee4983"
|
||||
"01010000000000000090d336b734c301"
|
||||
"ffffff00112233440000000002000c00"
|
||||
"44004f004d00410049004e0001000c00"
|
||||
"53004500520056004500520004001400"
|
||||
"64006f006d00610069006e002e006300"
|
||||
"6f006d00030022007300650072007600"
|
||||
"650072002e0064006f006d0061006900"
|
||||
"6e002e0063006f006d00000000000000"
|
||||
"0000"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testFormatNegotiateMessage()
|
||||
{
|
||||
NTLMCredentials::NegotiateMessage msg1;
|
||||
msg1.flags = 0;
|
||||
|
||||
std::vector<unsigned char> msg1Buffer = NTLMCredentials::formatNegotiateMessage(msg1);
|
||||
std::string msg1BufferHex = Poco::DigestEngine::digestToHex(msg1Buffer);
|
||||
|
||||
assertTrue (msg1BufferHex == "4e544c4d53535000010000000582080000000000180000000000000018000000");
|
||||
|
||||
msg1.domain = "DOMAIN";
|
||||
msg1Buffer = NTLMCredentials::formatNegotiateMessage(msg1);
|
||||
msg1BufferHex = Poco::DigestEngine::digestToHex(msg1Buffer);
|
||||
|
||||
assertTrue (msg1BufferHex == "4e544c4d5353500001000000059208000c000c0018000000000000002400000044004f004d00410049004e00");
|
||||
|
||||
msg1.workstation = "WORKST";
|
||||
msg1Buffer = NTLMCredentials::formatNegotiateMessage(msg1);
|
||||
msg1BufferHex = Poco::DigestEngine::digestToHex(msg1Buffer);
|
||||
|
||||
assertTrue (msg1BufferHex == "4e544c4d535350000100000005b208000c000c00180000000c000c002400000044004f004d00410049004e0057004f0052004b0053005400");
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testParseChallengeMessage()
|
||||
{
|
||||
const unsigned char BUFFER[] = {
|
||||
0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00,
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
|
||||
};
|
||||
|
||||
NTLMCredentials::ChallengeMessage msg2;
|
||||
bool ok = NTLMCredentials::parseChallengeMessage(BUFFER, sizeof(BUFFER), msg2);
|
||||
|
||||
assertTrue (ok);
|
||||
assertTrue (msg2.flags == (NTLMCredentials::NTLM_FLAG_NEGOTIATE_OEM | NTLMCredentials::NTLM_FLAG_NEGOTIATE_NTLM));
|
||||
assertTrue (msg2.challenge.size() == 8);
|
||||
assertTrue (msg2.targetInfo.empty());
|
||||
|
||||
assertTrue (msg2.challenge[0] == 0x01);
|
||||
assertTrue (msg2.challenge[1] == 0x23);
|
||||
assertTrue (msg2.challenge[7] == 0xef);
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testParseChallengeMessageWithTargetInfo()
|
||||
{
|
||||
const unsigned char BUFFER[] = {
|
||||
0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00,
|
||||
0x30, 0x00, 0x00, 0x00, 0x01, 0x02, 0x81, 0x00,
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x62, 0x00, 0x62, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||
0x44, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x41, 0x00,
|
||||
0x49, 0x00, 0x4e, 0x00, 0x02, 0x00, 0x0c, 0x00,
|
||||
0x44, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x41, 0x00,
|
||||
0x49, 0x00, 0x4e, 0x00, 0x01, 0x00, 0x0c, 0x00,
|
||||
0x53, 0x00, 0x45, 0x00, 0x52, 0x00, 0x56, 0x00,
|
||||
0x45, 0x00, 0x52, 0x00, 0x04, 0x00, 0x14, 0x00,
|
||||
0x64, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x61, 0x00,
|
||||
0x69, 0x00, 0x6e, 0x00, 0x2e, 0x00, 0x63, 0x00,
|
||||
0x6f, 0x00, 0x6d, 0x00, 0x03, 0x00, 0x22, 0x00,
|
||||
0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x76, 0x00,
|
||||
0x65, 0x00, 0x72, 0x00, 0x2e, 0x00, 0x64, 0x00,
|
||||
0x6f, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x69, 0x00,
|
||||
0x6e, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00,
|
||||
0x6d, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
NTLMCredentials::ChallengeMessage msg2;
|
||||
bool ok = NTLMCredentials::parseChallengeMessage(BUFFER, sizeof(BUFFER), msg2);
|
||||
|
||||
assertTrue (ok);
|
||||
assertTrue (msg2.flags == (NTLMCredentials::NTLM_FLAG_NEGOTIATE_UNICODE | NTLMCredentials::NTLM_FLAG_NEGOTIATE_NTLM | NTLMCredentials::NTLM_FLAG_NEGOTIATE_TARGET | NTLMCredentials::NTLM_FLAG_TARGET_DOMAIN));
|
||||
assertTrue (msg2.challenge.size() == 8);
|
||||
assertTrue (msg2.target == "DOMAIN");
|
||||
|
||||
assertTrue (msg2.targetInfo.size() == 98);
|
||||
|
||||
assertTrue (msg2.challenge[0] == 0x01);
|
||||
assertTrue (msg2.challenge[1] == 0x23);
|
||||
assertTrue (msg2.challenge[7] == 0xef);
|
||||
|
||||
assertTrue (msg2.targetInfo[0] == 0x02);
|
||||
assertTrue (msg2.targetInfo[1] == 0x00);
|
||||
assertTrue (msg2.targetInfo[97] == 0x00);
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::testFormatAuthenticateMessage()
|
||||
{
|
||||
const unsigned char LM[] = {
|
||||
0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97,
|
||||
0x82, 0xa6, 0x67, 0xaf, 0x6d, 0x42, 0x7c, 0x6d,
|
||||
0xe6, 0x7c, 0x20, 0xc2, 0xd3, 0xe7, 0x7c, 0x56
|
||||
};
|
||||
const unsigned char NTLM[] = {
|
||||
0x25, 0xa9, 0x8c, 0x1c, 0x31, 0xe8, 0x18, 0x47,
|
||||
0x46, 0x6b, 0x29, 0xb2, 0xdf, 0x46, 0x80, 0xf3,
|
||||
0x99, 0x58, 0xfb, 0x8c, 0x21, 0x3a, 0x9c, 0xc6
|
||||
};
|
||||
|
||||
NTLMCredentials::AuthenticateMessage msg3;
|
||||
msg3.flags = NTLMCredentials::NTLM_FLAG_NEGOTIATE_UNICODE | NTLMCredentials::NTLM_FLAG_NEGOTIATE_NTLM;
|
||||
msg3.target = "DOMAIN";
|
||||
msg3.username = "user";
|
||||
msg3.workstation = "WORKSTATION";
|
||||
msg3.lmResponse.assign(LM, LM + sizeof(LM));
|
||||
msg3.ntlmResponse.assign(NTLM, NTLM + sizeof(NTLM));
|
||||
|
||||
std::vector<unsigned char> msg3Buffer = NTLMCredentials::formatAuthenticateMessage(msg3);
|
||||
std::string msg3BufferHex = Poco::DigestEngine::digestToHex(msg3Buffer);
|
||||
|
||||
assertTrue (msg3BufferHex ==
|
||||
"4e544c4d5353500003000000180018004000000018001800"
|
||||
"580000000c000c0070000000080008007c00000016001600"
|
||||
"84000000000000009a00000001020000c337cd5cbd44fc97"
|
||||
"82a667af6d427c6de67c20c2d3e77c5625a98c1c31e81847"
|
||||
"466b29b2df4680f39958fb8c213a9cc644004f004d004100"
|
||||
"49004e00750073006500720057004f0052004b0053005400"
|
||||
"4100540049004f004e00"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NTLMCredentialsTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* NTLMCredentialsTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NTLMCredentialsTest");
|
||||
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testNonce);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testPasswordHash);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testNTLMv2Hash);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testLMv2Response);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testNTLMv2Response);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testFormatNegotiateMessage);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testParseChallengeMessage);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testParseChallengeMessageWithTargetInfo);
|
||||
CppUnit_addTest(pSuite, NTLMCredentialsTest, testFormatAuthenticateMessage);
|
||||
|
||||
return pSuite;
|
||||
}
|
46
vendor/POCO/Net/testsuite/src/NTLMCredentialsTest.h
vendored
Normal file
46
vendor/POCO/Net/testsuite/src/NTLMCredentialsTest.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// NTLMCredentialsTest.h
|
||||
//
|
||||
// Definition of the NTLMCredentialsTest class.
|
||||
//
|
||||
// Copyright (c) 2019, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NTLMCredentialsTest_INCLUDED
|
||||
#define NTLMCredentialsTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class NTLMCredentialsTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NTLMCredentialsTest(const std::string& name);
|
||||
~NTLMCredentialsTest();
|
||||
|
||||
void testNonce();
|
||||
void testPasswordHash();
|
||||
void testNTLMv2Hash();
|
||||
void testLMv2Response();
|
||||
void testNTLMv2Response();
|
||||
void testFormatNegotiateMessage();
|
||||
void testParseChallengeMessage();
|
||||
void testParseChallengeMessageWithTargetInfo();
|
||||
void testFormatAuthenticateMessage();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // NTLMCredentialsTest_INCLUDED
|
92
vendor/POCO/Net/testsuite/src/NTPClientTest.cpp
vendored
Normal file
92
vendor/POCO/Net/testsuite/src/NTPClientTest.cpp
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// NTPClientTest.cpp
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NTPClientTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/NTPClient.h"
|
||||
#include "Poco/Net/NTPEventArgs.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Net/ICMPClient.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::NTPClient;
|
||||
using Poco::Net::NTPEventArgs;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::ICMPClient;
|
||||
using Poco::Net::HostNotFoundException;
|
||||
using Poco::Delegate;
|
||||
using Poco::AutoPtr;
|
||||
|
||||
|
||||
NTPClientTest::NTPClientTest(const std::string& name):
|
||||
CppUnit::TestCase(name),
|
||||
_ntpClient(IPAddress::IPv4)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NTPClientTest::~NTPClientTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NTPClientTest::testTimeSync()
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
if (ICMPClient::pingIPv4("pool.ntp.org") <= 0)
|
||||
{
|
||||
std::cerr << "pool.ntp.org not accessibe, test skipped" << std::endl;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
assertTrue (_ntpClient.request("pool.ntp.org") > 0);
|
||||
}
|
||||
|
||||
|
||||
void NTPClientTest::setUp()
|
||||
{
|
||||
_ntpClient.response += Delegate<NTPClientTest, NTPEventArgs>(this, &NTPClientTest::onResponse);
|
||||
}
|
||||
|
||||
|
||||
void NTPClientTest::tearDown()
|
||||
{
|
||||
_ntpClient.response -= Delegate<NTPClientTest, NTPEventArgs>(this, &NTPClientTest::onResponse);
|
||||
}
|
||||
|
||||
|
||||
void NTPClientTest::onResponse(const void* pSender, NTPEventArgs& args)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << std::endl << "Received from " << args.hostName() << " [" << args.hostAddress() << "] with "
|
||||
<< Poco::DateTimeFormatter::format(args.packet().referenceTime(), Poco::DateTimeFormat::ISO8601_FORMAT) << " reference typestamp"
|
||||
<< std::endl;
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* NTPClientTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NTPClientTest");
|
||||
|
||||
CppUnit_addTest(pSuite, NTPClientTest, testTimeSync);
|
||||
|
||||
return pSuite;
|
||||
}
|
42
vendor/POCO/Net/testsuite/src/NTPClientTest.h
vendored
Normal file
42
vendor/POCO/Net/testsuite/src/NTPClientTest.h
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// NTPClientTest.h
|
||||
//
|
||||
// Definition of the NTPClientTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NTPClientTest_INCLUDED
|
||||
#define NTPClientTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/Net/NTPClient.h"
|
||||
#include "Poco/Net/NTPEventArgs.h"
|
||||
|
||||
|
||||
class NTPClientTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NTPClientTest(const std::string& name);
|
||||
~NTPClientTest();
|
||||
|
||||
void testTimeSync();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
void onResponse(const void* pSender, Poco::Net::NTPEventArgs& args);
|
||||
private:
|
||||
Poco::Net::NTPClient _ntpClient;
|
||||
};
|
||||
|
||||
|
||||
#endif // NTPClientTest_INCLUDED
|
22
vendor/POCO/Net/testsuite/src/NTPClientTestSuite.cpp
vendored
Normal file
22
vendor/POCO/Net/testsuite/src/NTPClientTestSuite.cpp
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// NTPClientTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NTPClientTestSuite.h"
|
||||
#include "NTPClientTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* NTPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NTPClientTestSuite");
|
||||
|
||||
pSuite->addTest(NTPClientTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/NTPClientTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/NTPClientTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// NTPClientTestSuite.h
|
||||
//
|
||||
// Definition of the NTPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NTPClientTestSuite_INCLUDED
|
||||
#define NTPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class NTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NTPClientTestSuite_INCLUDED
|
126
vendor/POCO/Net/testsuite/src/NameValueCollectionTest.cpp
vendored
Normal file
126
vendor/POCO/Net/testsuite/src/NameValueCollectionTest.cpp
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
//
|
||||
// NameValueCollectionTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NameValueCollectionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::Net::NameValueCollection;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
NameValueCollectionTest::NameValueCollectionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NameValueCollectionTest::~NameValueCollectionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollectionTest::testNameValueCollection()
|
||||
{
|
||||
NameValueCollection nvc;
|
||||
|
||||
assertTrue (nvc.empty());
|
||||
assertTrue (nvc.size() == 0);
|
||||
|
||||
nvc.set("name", "value");
|
||||
assertTrue (!nvc.empty());
|
||||
assertTrue (nvc["name"] == "value");
|
||||
assertTrue (nvc["Name"] == "value");
|
||||
|
||||
nvc.set("name2", "value2");
|
||||
assertTrue (nvc.get("name2") == "value2");
|
||||
assertTrue (nvc.get("NAME2") == "value2");
|
||||
|
||||
assertTrue (nvc.size() == 2);
|
||||
|
||||
try
|
||||
{
|
||||
std::string value = nvc.get("name3");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
std::string value = nvc["name3"];
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
}
|
||||
|
||||
assertTrue (nvc.get("name", "default") == "value");
|
||||
assertTrue (nvc.get("name3", "default") == "default");
|
||||
|
||||
assertTrue (nvc.has("name"));
|
||||
assertTrue (nvc.has("name2"));
|
||||
assertTrue (!nvc.has("name3"));
|
||||
|
||||
nvc.add("name3", "value3");
|
||||
assertTrue (nvc.get("name3") == "value3");
|
||||
|
||||
nvc.add("name3", "value31");
|
||||
|
||||
NameValueCollection::ConstIterator it = nvc.find("Name3");
|
||||
assertTrue (it != nvc.end());
|
||||
std::string v1 = it->second;
|
||||
assertTrue (it->first == "name3");
|
||||
++it;
|
||||
assertTrue (it != nvc.end());
|
||||
std::string v2 = it->second;
|
||||
assertTrue (it->first == "name3");
|
||||
|
||||
assertTrue ((v1 == "value3" && v2 == "value31") || (v1 == "value31" && v2 == "value3"));
|
||||
|
||||
nvc.erase("name3");
|
||||
assertTrue (!nvc.has("name3"));
|
||||
assertTrue (nvc.find("name3") == nvc.end());
|
||||
|
||||
it = nvc.begin();
|
||||
assertTrue (it != nvc.end());
|
||||
++it;
|
||||
assertTrue (it != nvc.end());
|
||||
++it;
|
||||
assertTrue (it == nvc.end());
|
||||
|
||||
nvc.clear();
|
||||
assertTrue (nvc.empty());
|
||||
|
||||
assertTrue (nvc.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollectionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollectionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* NameValueCollectionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NameValueCollectionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, NameValueCollectionTest, testNameValueCollection);
|
||||
|
||||
return pSuite;
|
||||
}
|
38
vendor/POCO/Net/testsuite/src/NameValueCollectionTest.h
vendored
Normal file
38
vendor/POCO/Net/testsuite/src/NameValueCollectionTest.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// NameValueCollectionTest.h
|
||||
//
|
||||
// Definition of the NameValueCollectionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NameValueCollectionTest_INCLUDED
|
||||
#define NameValueCollectionTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class NameValueCollectionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NameValueCollectionTest(const std::string& name);
|
||||
~NameValueCollectionTest();
|
||||
|
||||
void testNameValueCollection();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // NameValueCollectionTest_INCLUDED
|
29
vendor/POCO/Net/testsuite/src/NetCoreTestSuite.cpp
vendored
Normal file
29
vendor/POCO/Net/testsuite/src/NetCoreTestSuite.cpp
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// NetCoreTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NetCoreTestSuite.h"
|
||||
#include "IPAddressTest.h"
|
||||
#include "SocketAddressTest.h"
|
||||
#include "DNSTest.h"
|
||||
#include "NetworkInterfaceTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* NetCoreTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NetCoreTestSuite");
|
||||
|
||||
pSuite->addTest(IPAddressTest::suite());
|
||||
pSuite->addTest(SocketAddressTest::suite());
|
||||
pSuite->addTest(DNSTest::suite());
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
pSuite->addTest(NetworkInterfaceTest::suite());
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/NetCoreTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/NetCoreTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// NetCoreTestSuite.h
|
||||
//
|
||||
// Definition of the NetCoreTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NetCoreTestSuite_INCLUDED
|
||||
#define NetCoreTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class NetCoreTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NetCoreTestSuite_INCLUDED
|
54
vendor/POCO/Net/testsuite/src/NetTestSuite.cpp
vendored
Normal file
54
vendor/POCO/Net/testsuite/src/NetTestSuite.cpp
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// NetTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NetTestSuite.h"
|
||||
#include "NetCoreTestSuite.h"
|
||||
#include "SocketsTestSuite.h"
|
||||
#include "MessagesTestSuite.h"
|
||||
#include "HTTPTestSuite.h"
|
||||
#include "HTTPClientTestSuite.h"
|
||||
#include "TCPServerTestSuite.h"
|
||||
#include "UDPServerTestSuite.h"
|
||||
#include "HTTPServerTestSuite.h"
|
||||
#include "HTMLTestSuite.h"
|
||||
#include "ReactorTestSuite.h"
|
||||
#include "FTPClientTestSuite.h"
|
||||
#include "MailTestSuite.h"
|
||||
#include "ICMPClientTestSuite.h"
|
||||
#include "NTPClientTestSuite.h"
|
||||
#include "WebSocketTestSuite.h"
|
||||
#include "OAuthTestSuite.h"
|
||||
#include "SyslogTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* NetTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NetTestSuite");
|
||||
|
||||
pSuite->addTest(NetCoreTestSuite::suite());
|
||||
pSuite->addTest(SocketsTestSuite::suite());
|
||||
pSuite->addTest(MessagesTestSuite::suite());
|
||||
pSuite->addTest(HTTPTestSuite::suite());
|
||||
pSuite->addTest(HTTPClientTestSuite::suite());
|
||||
pSuite->addTest(TCPServerTestSuite::suite());
|
||||
pSuite->addTest(UDPServerTestSuite::suite());
|
||||
pSuite->addTest(HTTPServerTestSuite::suite());
|
||||
pSuite->addTest(HTMLTestSuite::suite());
|
||||
pSuite->addTest(ReactorTestSuite::suite());
|
||||
pSuite->addTest(FTPClientTestSuite::suite());
|
||||
pSuite->addTest(MailTestSuite::suite());
|
||||
pSuite->addTest(ICMPClientTestSuite::suite());
|
||||
pSuite->addTest(NTPClientTestSuite::suite());
|
||||
pSuite->addTest(WebSocketTestSuite::suite());
|
||||
pSuite->addTest(OAuthTestSuite::suite());
|
||||
pSuite->addTest(SyslogTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/NetTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/NetTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// NetTestSuite.h
|
||||
//
|
||||
// Definition of the NetTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NetTestSuite_INCLUDED
|
||||
#define NetTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class NetTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NetTestSuite_INCLUDED
|
337
vendor/POCO/Net/testsuite/src/NetworkInterfaceTest.cpp
vendored
Normal file
337
vendor/POCO/Net/testsuite/src/NetworkInterfaceTest.cpp
vendored
Normal file
@ -0,0 +1,337 @@
|
||||
//
|
||||
// NetworkInterfaceTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "NetworkInterfaceTest.h"
|
||||
|
||||
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/NetworkInterface.h"
|
||||
#include "Poco/Net/IPAddress.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
using Poco::Net::NetworkInterface;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
NetworkInterfaceTest::NetworkInterfaceTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NetworkInterfaceTest::~NetworkInterfaceTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testMap()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map m = NetworkInterface::map(false, false);
|
||||
assertTrue (!m.empty());
|
||||
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
|
||||
{
|
||||
std::cout << std::endl << "=============" << std::endl;
|
||||
|
||||
std::cout << "Index: " << it->second.index() << std::endl;
|
||||
std::cout << "Name: " << it->second.name() << std::endl;
|
||||
std::cout << "DisplayName: " << it->second.displayName() << std::endl;
|
||||
std::cout << "Status: " << (it->second.isUp() ? "Up" : "Down") << std::endl;
|
||||
|
||||
NetworkInterface::MACAddress mac(it->second.macAddress());
|
||||
if (!mac.empty() && (it->second.type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
|
||||
std::cout << "MAC Address: (" << it->second.type() << ") " << mac << std::endl;
|
||||
|
||||
typedef NetworkInterface::AddressList List;
|
||||
const List& ipList = it->second.addressList();
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter)
|
||||
{
|
||||
std::cout << std::endl << "----------" << std::endl;
|
||||
std::cout << "Address " << counter << std::endl;
|
||||
std::cout << "----------" << std::endl;
|
||||
std::cout << "Address: " << ipIt->get<NetworkInterface::IP_ADDRESS>() << std::endl;
|
||||
IPAddress addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
|
||||
if (!addr.isWildcard()) std::cout << "Subnet: " << addr << " (/" << addr.prefixLength() << ")" << std::endl;
|
||||
addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
|
||||
if (!addr.isWildcard()) std::cout << "Broadcast: " << addr << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "=============" << std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testList()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::List list = NetworkInterface::list(false, false);
|
||||
assertTrue (!list.empty());
|
||||
for (NetworkInterface::List::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
std::cout << std::endl << "==============" << std::endl;
|
||||
|
||||
std::cout << "Index: " << it->index() << std::endl;
|
||||
std::cout << "Name: " << it->name() << std::endl;
|
||||
std::cout << "DisplayName: " << it->displayName() << std::endl;
|
||||
std::cout << "Status: " << (it->isUp() ? "Up" : "Down") << std::endl;
|
||||
|
||||
NetworkInterface::MACAddress mac(it->macAddress());
|
||||
if (!mac.empty() && (it->type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
|
||||
std::cout << "MAC Address: (" << it->type() << ") " << mac << std::endl;
|
||||
|
||||
typedef NetworkInterface::AddressList AddrList;
|
||||
const AddrList& ipList = it->addressList();
|
||||
AddrList::const_iterator ipIt = ipList.begin();
|
||||
AddrList::const_iterator ipEnd = ipList.end();
|
||||
for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter)
|
||||
{
|
||||
std::cout << "IP Address: " << ipIt->get<NetworkInterface::IP_ADDRESS>() << std::endl;
|
||||
IPAddress addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
|
||||
if (!addr.isWildcard()) std::cout << "Subnet: " << ipIt->get<NetworkInterface::SUBNET_MASK>() << " (/" << ipIt->get<NetworkInterface::SUBNET_MASK>().prefixLength() << ")" << std::endl;
|
||||
addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
|
||||
if (!addr.isWildcard()) std::cout << "Broadcast: " << ipIt->get<NetworkInterface::BROADCAST_ADDRESS>() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "==============" << std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testForName()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map map = NetworkInterface::map();
|
||||
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
NetworkInterface ifc = NetworkInterface::forName(it->second.name());
|
||||
assertTrue (ifc.name() == it->second.name());
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testForAddress()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map map = NetworkInterface::map();
|
||||
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
// not all interfaces have IP configured
|
||||
if (it->second.addressList().empty()) continue;
|
||||
|
||||
if (it->second.supportsIPv4())
|
||||
{
|
||||
NetworkInterface ifc = NetworkInterface::forAddress(it->second.firstAddress(IPAddress::IPv4));
|
||||
assertTrue (ifc.firstAddress(IPAddress::IPv4) == it->second.firstAddress(IPAddress::IPv4));
|
||||
|
||||
IPAddress addr(IPAddress::IPv4);
|
||||
assertTrue (addr.isWildcard());
|
||||
it->second.firstAddress(addr, IPAddress::IPv4);
|
||||
assertTrue (!addr.isWildcard());
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
it->second.firstAddress(IPAddress::IPv4);
|
||||
fail ("must throw");
|
||||
}
|
||||
catch (NotFoundException&) { }
|
||||
|
||||
IPAddress addr(IPAddress::IPv4);
|
||||
assertTrue (addr.isWildcard());
|
||||
it->second.firstAddress(addr, IPAddress::IPv4);
|
||||
assertTrue (addr.isWildcard());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testForIndex()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map map = NetworkInterface::map();
|
||||
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
NetworkInterface ifc = NetworkInterface::forIndex(it->second.index());
|
||||
assertTrue (ifc.index() == it->second.index());
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testMapIpOnly()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map m = NetworkInterface::map(true, false);
|
||||
assertTrue (!m.empty());
|
||||
|
||||
std::cout << std::endl;
|
||||
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
|
||||
{
|
||||
assertTrue (it->second.supportsIPv4() || it->second.supportsIPv6());
|
||||
std::cout << "Interface: (" << it->second.index() << ")" << std::endl;
|
||||
std::cout << "Address: " << it->second.address() << std::endl;
|
||||
NetworkInterface::MACAddress mac(it->second.macAddress());
|
||||
if (!mac.empty() && (it->second.type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
|
||||
std::cout << "MAC Address:" << mac << std::endl;
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testMapUpOnly()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map m = NetworkInterface::map(false, true);
|
||||
assertTrue (!m.empty());
|
||||
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
|
||||
{
|
||||
assertTrue (it->second.isUp());
|
||||
}
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testListMapConformance()
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkInterface::Map m = NetworkInterface::map(false, false);
|
||||
assertTrue (!m.empty());
|
||||
NetworkInterface::List l = NetworkInterface::list(false, false);
|
||||
assertTrue (!l.empty());
|
||||
|
||||
int counter = 0;
|
||||
NetworkInterface::Map::const_iterator mapIt = m.begin();
|
||||
NetworkInterface::List::const_iterator listIt = l.begin();
|
||||
for (; mapIt != m.end(); ++mapIt)
|
||||
{
|
||||
NetworkInterface::MACAddress mac(mapIt->second.macAddress());
|
||||
|
||||
typedef NetworkInterface::AddressList List;
|
||||
const List& ipList = mapIt->second.addressList();
|
||||
if (ipList.size() > 0)
|
||||
{
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for(; ipIt != ipEnd; ++ipIt, ++counter, ++listIt)
|
||||
{
|
||||
if(listIt == l.end()) fail("wrong number of list items");
|
||||
NetworkInterface::MACAddress lmac = listIt->macAddress();
|
||||
assertTrue (lmac == mac);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++listIt;
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue (counter == l.size());
|
||||
}
|
||||
catch (Poco::NotImplementedException e)
|
||||
{
|
||||
#if POCO_OS != POCO_OS_ANDROID
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* NetworkInterfaceTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NetworkInterfaceTest");
|
||||
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testList);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testMap);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testForName);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testForAddress);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testForIndex);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testMapIpOnly);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testMapUpOnly);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testListMapConformance);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
53
vendor/POCO/Net/testsuite/src/NetworkInterfaceTest.h
vendored
Normal file
53
vendor/POCO/Net/testsuite/src/NetworkInterfaceTest.h
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// NetworkInterfaceTest.h
|
||||
//
|
||||
// Definition of the NetworkInterfaceTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef NetworkInterfaceTest_INCLUDED
|
||||
#define NetworkInterfaceTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
|
||||
|
||||
#ifdef POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class NetworkInterfaceTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NetworkInterfaceTest(const std::string& name);
|
||||
~NetworkInterfaceTest();
|
||||
|
||||
void testMap();
|
||||
void testList();
|
||||
void testForName();
|
||||
void testForAddress();
|
||||
void testForIndex();
|
||||
void testMapIpOnly();
|
||||
void testMapUpOnly();
|
||||
void testListMapConformance();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // POCO_NET_HAS_INTERFACE
|
||||
|
||||
|
||||
#endif // NetworkInterfaceTest_INCLUDED
|
264
vendor/POCO/Net/testsuite/src/OAuth10CredentialsTest.cpp
vendored
Normal file
264
vendor/POCO/Net/testsuite/src/OAuth10CredentialsTest.cpp
vendored
Normal file
@ -0,0 +1,264 @@
|
||||
//
|
||||
// OAuth10CredentialsTest.cpp
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "OAuth10CredentialsTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/OAuth10Credentials.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
#include "Poco/URI.h"
|
||||
|
||||
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::OAuth10Credentials;
|
||||
using Poco::Net::NotAuthenticatedException;
|
||||
using Poco::Net::HTMLForm;
|
||||
using Poco::URI;
|
||||
|
||||
|
||||
OAuth10CredentialsTest::OAuth10CredentialsTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OAuth10CredentialsTest::~OAuth10CredentialsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::testCallback()
|
||||
{
|
||||
// Note: Request taken from <https://dev.twitter.com/web/sign-in/implementing>
|
||||
//
|
||||
// POST /oauth/request_token HTTP/1.1
|
||||
// Host: api.twitter.com
|
||||
// Authorization:
|
||||
// OAuth oauth_callback="http%3A%2F%2Flocalhost%2Fsign-in-with-twitter%2F",
|
||||
// oauth_consumer_key="cChZNFj6T5R0TigYB9yd1w",
|
||||
// oauth_nonce="ea9ec8429b68d6b77cd5600adbbb0456",
|
||||
// oauth_signature="F1Li3tvehgcraF8DMJ7OyxO4w9Y%3D",
|
||||
// oauth_signature_method="HMAC-SHA1",
|
||||
// oauth_timestamp="1318467427",
|
||||
// oauth_version="1.0"
|
||||
|
||||
|
||||
URI uri("https://api.twitter.com/oauth/request_token");
|
||||
OAuth10Credentials creds("cChZNFj6T5R0TigYB9yd1w", "L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg");
|
||||
creds.setCallback("http://localhost/sign-in-with-twitter/");
|
||||
creds.nonceAndTimestampForTesting("ea9ec8429b68d6b77cd5600adbbb0456", "1318467427");
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPathEtc());
|
||||
|
||||
creds.authenticate(request, uri);
|
||||
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "OAuth"
|
||||
" oauth_consumer_key=\"cChZNFj6T5R0TigYB9yd1w\","
|
||||
" oauth_nonce=\"ea9ec8429b68d6b77cd5600adbbb0456\","
|
||||
" oauth_signature=\"F1Li3tvehgcraF8DMJ7OyxO4w9Y%3D\","
|
||||
" oauth_signature_method=\"HMAC-SHA1\","
|
||||
" oauth_timestamp=\"1318467427\","
|
||||
" oauth_callback=\"http%3A%2F%2Flocalhost%2Fsign-in-with-twitter%2F\","
|
||||
" oauth_version=\"1.0\"");
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::testParams()
|
||||
{
|
||||
// Note: Request taken from <https://dev.twitter.com/oauth/overview/authorizing-requests>
|
||||
// and <https://dev.twitter.com/oauth/overview/creating-signatures>.
|
||||
//
|
||||
// POST /1/statuses/update.json?include_entities=true HTTP/1.1
|
||||
// Content-Type: application/x-www-form-urlencoded
|
||||
// Authorization:
|
||||
// OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",
|
||||
// oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
|
||||
// oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
|
||||
// oauth_signature_method="HMAC-SHA1",
|
||||
// oauth_timestamp="1318622958",
|
||||
// oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
|
||||
// oauth_version="1.0"
|
||||
// Content-Length: 76
|
||||
// Host: api.twitter.com
|
||||
//
|
||||
// status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21
|
||||
|
||||
URI uri("https://api.twitter.com/1/statuses/update.json?include_entities=true");
|
||||
OAuth10Credentials creds(
|
||||
"xvz1evFS4wEEPTGEFPHBog",
|
||||
"kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw",
|
||||
"370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
|
||||
"LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE"
|
||||
);
|
||||
creds.nonceAndTimestampForTesting("kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", "1318622958");
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPathEtc());
|
||||
|
||||
HTMLForm params;
|
||||
params.set("include_entities", "true");
|
||||
params.set("status", "Hello Ladies + Gentlemen, a signed OAuth request!");
|
||||
|
||||
creds.authenticate(request, uri, params);
|
||||
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "OAuth"
|
||||
" oauth_consumer_key=\"xvz1evFS4wEEPTGEFPHBog\","
|
||||
" oauth_nonce=\"kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg\","
|
||||
" oauth_signature=\"tnnArxj06cWHq44gCs1OSKk%2FjLY%3D\","
|
||||
" oauth_signature_method=\"HMAC-SHA1\","
|
||||
" oauth_timestamp=\"1318622958\","
|
||||
" oauth_token=\"370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb\","
|
||||
" oauth_version=\"1.0\"");
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::testRealm()
|
||||
{
|
||||
// Note: Request taken from <https://dev.twitter.com/oauth/overview/authorizing-requests>
|
||||
// and <https://dev.twitter.com/oauth/overview/creating-signatures>.
|
||||
//
|
||||
// POST /1/statuses/update.json?include_entities=true HTTP/1.1
|
||||
// Content-Type: application/x-www-form-urlencoded
|
||||
// Authorization:
|
||||
// OAuth realm="Twitter API"
|
||||
// oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",
|
||||
// oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
|
||||
// oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
|
||||
// oauth_signature_method="HMAC-SHA1",
|
||||
// oauth_timestamp="1318622958",
|
||||
// oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
|
||||
// oauth_version="1.0"
|
||||
// Content-Length: 76
|
||||
// Host: api.twitter.com
|
||||
//
|
||||
// status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21
|
||||
|
||||
URI uri("https://api.twitter.com/1/statuses/update.json?include_entities=true");
|
||||
OAuth10Credentials creds(
|
||||
"xvz1evFS4wEEPTGEFPHBog",
|
||||
"kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw",
|
||||
"370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
|
||||
"LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE"
|
||||
);
|
||||
creds.setRealm("Twitter API");
|
||||
creds.nonceAndTimestampForTesting("kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", "1318622958");
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPathEtc());
|
||||
|
||||
HTMLForm params;
|
||||
params.set("include_entities", "true");
|
||||
params.set("status", "Hello Ladies + Gentlemen, a signed OAuth request!");
|
||||
|
||||
creds.authenticate(request, uri, params);
|
||||
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "OAuth"
|
||||
" realm=\"Twitter API\","
|
||||
" oauth_consumer_key=\"xvz1evFS4wEEPTGEFPHBog\","
|
||||
" oauth_nonce=\"kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg\","
|
||||
" oauth_signature=\"tnnArxj06cWHq44gCs1OSKk%2FjLY%3D\","
|
||||
" oauth_signature_method=\"HMAC-SHA1\","
|
||||
" oauth_timestamp=\"1318622958\","
|
||||
" oauth_token=\"370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb\","
|
||||
" oauth_version=\"1.0\"");
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::testPlaintext()
|
||||
{
|
||||
URI uri("https://api.twitter.com/oauth/request_token");
|
||||
OAuth10Credentials creds("consumerKey", "consumerSecret");
|
||||
creds.setCallback("http://localhost/sign-in-with-twitter/");
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPathEtc());
|
||||
|
||||
creds.authenticate(request, uri, OAuth10Credentials::SIGN_PLAINTEXT);
|
||||
|
||||
std::string auth = request.get("Authorization");
|
||||
|
||||
assertTrue (auth == "OAuth"
|
||||
" oauth_consumer_key=\"consumerKey\","
|
||||
" oauth_signature=\"consumerSecret%26\","
|
||||
" oauth_signature_method=\"PLAINTEXT\","
|
||||
" oauth_callback=\"http%3A%2F%2Flocalhost%2Fsign-in-with-twitter%2F\","
|
||||
" oauth_version=\"1.0\"");
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::testVerify()
|
||||
{
|
||||
URI uri("https://api.twitter.com/1/statuses/update.json?include_entities=true");
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPathEtc());
|
||||
request.set("Authorization", "OAuth"
|
||||
" oauth_consumer_key=\"xvz1evFS4wEEPTGEFPHBog\","
|
||||
" oauth_nonce=\"kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg\","
|
||||
" oauth_signature=\"tnnArxj06cWHq44gCs1OSKk%2FjLY%3D\","
|
||||
" oauth_signature_method=\"HMAC-SHA1\","
|
||||
" oauth_timestamp=\"1318622958\","
|
||||
" oauth_token=\"370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb\","
|
||||
" oauth_version=\"1.0\"");
|
||||
|
||||
OAuth10Credentials creds(request);
|
||||
assertTrue (creds.getConsumerKey() == "xvz1evFS4wEEPTGEFPHBog");
|
||||
assertTrue (creds.getToken() == "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb");
|
||||
creds.setConsumerSecret("kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw");
|
||||
creds.setTokenSecret("LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE");
|
||||
|
||||
HTMLForm params;
|
||||
params.read(uri.getRawQuery());
|
||||
params.read("status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21");
|
||||
|
||||
assertTrue (creds.verify(request, uri, params));
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::testVerifyPlaintext()
|
||||
{
|
||||
URI uri("https://api.twitter.com/oauth/request_token");
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPathEtc());
|
||||
request.set("Authorization", "OAuth"
|
||||
" oauth_consumer_key=\"consumerKey\","
|
||||
" oauth_signature=\"consumerSecret%26\","
|
||||
" oauth_signature_method=\"PLAINTEXT\","
|
||||
" oauth_callback=\"http%3A%2F%2Flocalhost%2Fsign-in-with-twitter%2F\","
|
||||
" oauth_version=\"1.0\"");
|
||||
|
||||
OAuth10Credentials creds(request);
|
||||
assertTrue (creds.getConsumerKey() == "consumerKey");
|
||||
creds.setConsumerSecret("consumerSecret");
|
||||
|
||||
assertTrue (creds.verify(request, uri));
|
||||
assertTrue (creds.getCallback() == "http://localhost/sign-in-with-twitter/");
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void OAuth10CredentialsTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* OAuth10CredentialsTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OAuth10CredentialsTest");
|
||||
|
||||
CppUnit_addTest(pSuite, OAuth10CredentialsTest, testCallback);
|
||||
CppUnit_addTest(pSuite, OAuth10CredentialsTest, testParams);
|
||||
CppUnit_addTest(pSuite, OAuth10CredentialsTest, testRealm);
|
||||
CppUnit_addTest(pSuite, OAuth10CredentialsTest, testPlaintext);
|
||||
CppUnit_addTest(pSuite, OAuth10CredentialsTest, testVerify);
|
||||
CppUnit_addTest(pSuite, OAuth10CredentialsTest, testVerifyPlaintext);
|
||||
|
||||
return pSuite;
|
||||
}
|
43
vendor/POCO/Net/testsuite/src/OAuth10CredentialsTest.h
vendored
Normal file
43
vendor/POCO/Net/testsuite/src/OAuth10CredentialsTest.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// OAuth10CredentialsTest.h
|
||||
//
|
||||
// Definition of the OAuth10CredentialsTest class.
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef OAuth10CredentialsTest_INCLUDED
|
||||
#define OAuth10CredentialsTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class OAuth10CredentialsTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
OAuth10CredentialsTest(const std::string& name);
|
||||
~OAuth10CredentialsTest();
|
||||
|
||||
void testCallback();
|
||||
void testParams();
|
||||
void testRealm();
|
||||
void testPlaintext();
|
||||
void testVerify();
|
||||
void testVerifyPlaintext();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // OAuth10CredentialsTest_INCLUDED
|
107
vendor/POCO/Net/testsuite/src/OAuth20CredentialsTest.cpp
vendored
Normal file
107
vendor/POCO/Net/testsuite/src/OAuth20CredentialsTest.cpp
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
//
|
||||
// OAuth20CredentialsTest.cpp
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "OAuth20CredentialsTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/OAuth20Credentials.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::OAuth20Credentials;
|
||||
using Poco::Net::NotAuthenticatedException;
|
||||
|
||||
|
||||
OAuth20CredentialsTest::OAuth20CredentialsTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OAuth20CredentialsTest::~OAuth20CredentialsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::testAuthorize()
|
||||
{
|
||||
OAuth20Credentials creds("s3cr3tt0k3n");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
creds.authenticate(request);
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "Bearer s3cr3tt0k3n");
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::testAuthorizeCustomScheme()
|
||||
{
|
||||
OAuth20Credentials creds("s3cr3tt0k3n", "token");
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
creds.authenticate(request);
|
||||
std::string auth = request.get("Authorization");
|
||||
assertTrue (auth == "token s3cr3tt0k3n");
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::testExtract()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
request.set("Authorization", "Bearer s3cr3tt0k3n");
|
||||
OAuth20Credentials creds(request);
|
||||
assertTrue (creds.getBearerToken() == "s3cr3tt0k3n");
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::testExtractCustomScheme()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
request.set("Authorization", "token s3cr3tt0k3n");
|
||||
OAuth20Credentials creds(request, "token");
|
||||
assertTrue (creds.getBearerToken() == "s3cr3tt0k3n");
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::testExtractNoCreds()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
|
||||
try
|
||||
{
|
||||
OAuth20Credentials creds(request);
|
||||
fail("no credentials - must throw");
|
||||
}
|
||||
catch (NotAuthenticatedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void OAuth20CredentialsTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* OAuth20CredentialsTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OAuth20CredentialsTest");
|
||||
|
||||
CppUnit_addTest(pSuite, OAuth20CredentialsTest, testAuthorize);
|
||||
CppUnit_addTest(pSuite, OAuth20CredentialsTest, testAuthorizeCustomScheme);
|
||||
CppUnit_addTest(pSuite, OAuth20CredentialsTest, testExtract);
|
||||
CppUnit_addTest(pSuite, OAuth20CredentialsTest, testExtractCustomScheme);
|
||||
CppUnit_addTest(pSuite, OAuth20CredentialsTest, testExtractNoCreds);
|
||||
|
||||
return pSuite;
|
||||
}
|
42
vendor/POCO/Net/testsuite/src/OAuth20CredentialsTest.h
vendored
Normal file
42
vendor/POCO/Net/testsuite/src/OAuth20CredentialsTest.h
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// OAuth20CredentialsTest.h
|
||||
//
|
||||
// Definition of the OAuth20CredentialsTest class.
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef OAuth20CredentialsTest_INCLUDED
|
||||
#define OAuth20CredentialsTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class OAuth20CredentialsTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
OAuth20CredentialsTest(const std::string& name);
|
||||
~OAuth20CredentialsTest();
|
||||
|
||||
void testAuthorize();
|
||||
void testAuthorizeCustomScheme();
|
||||
void testExtract();
|
||||
void testExtractCustomScheme();
|
||||
void testExtractNoCreds();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // OAuth20CredentialsTest_INCLUDED
|
24
vendor/POCO/Net/testsuite/src/OAuthTestSuite.cpp
vendored
Normal file
24
vendor/POCO/Net/testsuite/src/OAuthTestSuite.cpp
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// OAuthTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "OAuthTestSuite.h"
|
||||
#include "OAuth10CredentialsTest.h"
|
||||
#include "OAuth20CredentialsTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* OAuthTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OAuthTestSuite");
|
||||
|
||||
pSuite->addTest(OAuth10CredentialsTest::suite());
|
||||
pSuite->addTest(OAuth20CredentialsTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
27
vendor/POCO/Net/testsuite/src/OAuthTestSuite.h
vendored
Normal file
27
vendor/POCO/Net/testsuite/src/OAuthTestSuite.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// OAuthTestSuite.h
|
||||
//
|
||||
// Definition of the OAuthTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef OAuthTestSuite_INCLUDED
|
||||
#define OAuthTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class OAuthTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // OAuthTestSuite_INCLUDED
|
296
vendor/POCO/Net/testsuite/src/POP3ClientSessionTest.cpp
vendored
Normal file
296
vendor/POCO/Net/testsuite/src/POP3ClientSessionTest.cpp
vendored
Normal file
@ -0,0 +1,296 @@
|
||||
//
|
||||
// POP3ClientSessionTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "POP3ClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Poco/Net/POP3ClientSession.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::POP3ClientSession;
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::MailMessage;
|
||||
using Poco::Net::POP3Exception;
|
||||
|
||||
|
||||
POP3ClientSessionTest::POP3ClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
POP3ClientSessionTest::~POP3ClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testLogin()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "USER user");
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "PASS secret");
|
||||
session.close();
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "QUIT");
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testLoginFail()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("-ERR PASS");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
try
|
||||
{
|
||||
session.login("user", "secret");
|
||||
fail("login failed - must throw");
|
||||
}
|
||||
catch (POP3Exception&)
|
||||
{
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testMessageCount()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse("+OK 42 12345");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
int n = session.messageCount();
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "STAT");
|
||||
assertTrue (n == 42);
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testList()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes da list\r\n"
|
||||
"1 1234\r\n"
|
||||
"2 5678\r\n"
|
||||
"3 987\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
std::vector<POP3ClientSession::MessageInfo> infos;
|
||||
session.listMessages(infos);
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "LIST");
|
||||
assertTrue (infos.size() == 3);
|
||||
assertTrue (infos[0].id == 1);
|
||||
assertTrue (infos[0].size == 1234);
|
||||
assertTrue (infos[1].id == 2);
|
||||
assertTrue (infos[1].size == 5678);
|
||||
assertTrue (infos[2].id == 3);
|
||||
assertTrue (infos[2].size == 987);
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testRetrieveMessage()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"....\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
MailMessage message;
|
||||
session.retrieveMessage(1, message);
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "RETR 1");
|
||||
|
||||
assertTrue (message.getContent() ==
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"...\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
);
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testRetrieveHeader()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"."
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
MessageHeader header;
|
||||
session.retrieveHeader(1, header);
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "TOP 1 0");
|
||||
assertTrue (header.get("From") == "john.doe@no.where");
|
||||
assertTrue (header.get("To") == "jane.doe@no.where");
|
||||
assertTrue (header.get("Subject") == "test");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testRetrieveMessages()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"."
|
||||
);
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"....\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
"."
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
MessageHeader header;
|
||||
session.retrieveHeader(1, header);
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "TOP 1 0");
|
||||
assertTrue (header.get("From") == "john.doe@no.where");
|
||||
assertTrue (header.get("To") == "jane.doe@no.where");
|
||||
assertTrue (header.get("Subject") == "test");
|
||||
|
||||
MailMessage message;
|
||||
session.retrieveMessage(2, message);
|
||||
cmd = server.popCommand();
|
||||
assertTrue (cmd == "RETR 2");
|
||||
|
||||
assertTrue (message.getContent() ==
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"...\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
);
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testDeleteMessage()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse("+OK DELETED");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("127.0.0.1", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
session.deleteMessage(42);
|
||||
std::string cmd = server.popCommand();
|
||||
assertTrue (cmd == "DELE 42");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* POP3ClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("POP3ClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testLogin);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testLoginFail);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testMessageCount);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testList);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testRetrieveMessage);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testRetrieveHeader);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testRetrieveMessages);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testDeleteMessage);
|
||||
|
||||
return pSuite;
|
||||
}
|
45
vendor/POCO/Net/testsuite/src/POP3ClientSessionTest.h
vendored
Normal file
45
vendor/POCO/Net/testsuite/src/POP3ClientSessionTest.h
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// POP3ClientSessionTest.h
|
||||
//
|
||||
// Definition of the POP3ClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef POP3ClientSessionTest_INCLUDED
|
||||
#define POP3ClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class POP3ClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
POP3ClientSessionTest(const std::string& name);
|
||||
~POP3ClientSessionTest();
|
||||
|
||||
void testLogin();
|
||||
void testLoginFail();
|
||||
void testMessageCount();
|
||||
void testList();
|
||||
void testRetrieveMessage();
|
||||
void testRetrieveHeader();
|
||||
void testRetrieveMessages();
|
||||
void testDeleteMessage();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // POP3ClientSessionTest_INCLUDED
|
145
vendor/POCO/Net/testsuite/src/PollSetTest.cpp
vendored
Normal file
145
vendor/POCO/Net/testsuite/src/PollSetTest.cpp
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
//
|
||||
// PollSetTest.cpp
|
||||
//
|
||||
// Copyright (c) 2016, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "PollSetTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "EchoServer.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Net/PollSet.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::ConnectionRefusedException;
|
||||
using Poco::Net::PollSet;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
|
||||
|
||||
PollSetTest::PollSetTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PollSetTest::~PollSetTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void PollSetTest::testPoll()
|
||||
{
|
||||
EchoServer echoServer1;
|
||||
EchoServer echoServer2;
|
||||
StreamSocket ss1;
|
||||
StreamSocket ss2;
|
||||
|
||||
ss1.connect(SocketAddress("127.0.0.1", echoServer1.port()));
|
||||
ss2.connect(SocketAddress("127.0.0.1", echoServer2.port()));
|
||||
|
||||
PollSet ps;
|
||||
assertTrue(ps.empty());
|
||||
ps.add(ss1, PollSet::POLL_READ);
|
||||
assertTrue(!ps.empty());
|
||||
assertTrue(ps.has(ss1));
|
||||
assertTrue(!ps.has(ss2));
|
||||
|
||||
// nothing readable
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
Timespan timeout(1000000);
|
||||
assertTrue (ps.poll(timeout).empty());
|
||||
assertTrue (sw.elapsed() >= 900000);
|
||||
sw.restart();
|
||||
|
||||
ps.add(ss2, PollSet::POLL_READ);
|
||||
assertTrue(!ps.empty());
|
||||
assertTrue(ps.has(ss1));
|
||||
assertTrue(ps.has(ss2));
|
||||
|
||||
// ss1 must be writable, if polled for
|
||||
ps.update(ss1, PollSet::POLL_READ | PollSet::POLL_WRITE);
|
||||
PollSet::SocketModeMap sm = ps.poll(timeout);
|
||||
assertTrue (sm.find(ss1) != sm.end());
|
||||
assertTrue (sm.find(ss2) == sm.end());
|
||||
assertTrue (sm.find(ss1)->second == PollSet::POLL_WRITE);
|
||||
assertTrue (sw.elapsed() < 100000);
|
||||
|
||||
ps.update(ss1, PollSet::POLL_READ);
|
||||
|
||||
ss1.sendBytes("hello", 5);
|
||||
char buffer[256];
|
||||
sw.restart();
|
||||
sm = ps.poll(timeout);
|
||||
assertTrue (sm.find(ss1) != sm.end());
|
||||
assertTrue (sm.find(ss2) == sm.end());
|
||||
assertTrue (sm.find(ss1)->second == PollSet::POLL_READ);
|
||||
assertTrue (sw.elapsed() < 100000);
|
||||
|
||||
int n = ss1.receiveBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "hello");
|
||||
|
||||
|
||||
ss2.sendBytes("HELLO", 5);
|
||||
sw.restart();
|
||||
sm = ps.poll(timeout);
|
||||
assertTrue (sm.find(ss1) == sm.end());
|
||||
assertTrue (sm.find(ss2) != sm.end());
|
||||
assertTrue (sm.find(ss2)->second == PollSet::POLL_READ);
|
||||
assertTrue (sw.elapsed() < 100000);
|
||||
|
||||
n = ss2.receiveBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "HELLO");
|
||||
|
||||
ps.remove(ss2);
|
||||
assertTrue(!ps.empty());
|
||||
assertTrue(ps.has(ss1));
|
||||
assertTrue(!ps.has(ss2));
|
||||
|
||||
ss2.sendBytes("HELLO", 5);
|
||||
sw.restart();
|
||||
sm = ps.poll(timeout);
|
||||
assertTrue (sm.empty());
|
||||
|
||||
n = ss2.receiveBytes(buffer, sizeof(buffer));
|
||||
assertTrue (n == 5);
|
||||
assertTrue (std::string(buffer, n) == "HELLO");
|
||||
|
||||
ss1.close();
|
||||
ss2.close();
|
||||
}
|
||||
|
||||
|
||||
void PollSetTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void PollSetTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* PollSetTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PollSetTest");
|
||||
|
||||
CppUnit_addTest(pSuite, PollSetTest, testPoll);
|
||||
|
||||
return pSuite;
|
||||
}
|
36
vendor/POCO/Net/testsuite/src/PollSetTest.h
vendored
Normal file
36
vendor/POCO/Net/testsuite/src/PollSetTest.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// PollSetTest.h
|
||||
//
|
||||
// Definition of the PollSetTest class.
|
||||
//
|
||||
// Copyright (c) 2016, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef PollSetTest_INCLUDED
|
||||
#define PollSetTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class PollSetTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
PollSetTest(const std::string& name);
|
||||
~PollSetTest();
|
||||
|
||||
void testPoll();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // PollSetTest_INCLUDED
|
100
vendor/POCO/Net/testsuite/src/QuotedPrintableTest.cpp
vendored
Normal file
100
vendor/POCO/Net/testsuite/src/QuotedPrintableTest.cpp
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
//
|
||||
// QuotedPrintableTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "QuotedPrintableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/QuotedPrintableEncoder.h"
|
||||
#include "Poco/Net/QuotedPrintableDecoder.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::QuotedPrintableEncoder;
|
||||
using Poco::Net::QuotedPrintableDecoder;
|
||||
|
||||
|
||||
QuotedPrintableTest::QuotedPrintableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QuotedPrintableTest::~QuotedPrintableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::testEncode()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
QuotedPrintableEncoder encoder(ostr);
|
||||
|
||||
encoder <<
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor. \r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin sodales molestie arcu.\r\n"
|
||||
"\t\bSed suscipit, mi in facilisis feugiat, \t \r\n"
|
||||
"\200\201\r\n";
|
||||
encoder.close();
|
||||
std::string txt = ostr.str();
|
||||
assertTrue (txt == "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor.=20\r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin s=\r\n"
|
||||
"odales molestie arcu.\r\n"
|
||||
"\t=08Sed suscipit, mi in facilisis feugiat, \t =20\r\n"
|
||||
"=80=81\r\n");
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::testDecode()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor.=20\r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin s=\r\n"
|
||||
"odales molestie arcu.\r\n"
|
||||
"\t=08Sed suscipit, mi in facilisis feugiat, \t =20\r\n"
|
||||
"=80=81\r\n"
|
||||
);
|
||||
QuotedPrintableDecoder decoder(istr);
|
||||
std::string str;
|
||||
int c = decoder.get();
|
||||
while (c != -1)
|
||||
{
|
||||
str += (char) c;
|
||||
c = decoder.get();
|
||||
}
|
||||
assertTrue (str == "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor. \r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin sodales molestie arcu.\r\n"
|
||||
"\t\bSed suscipit, mi in facilisis feugiat, \t \r\n"
|
||||
"\200\201\r\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* QuotedPrintableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("QuotedPrintableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, QuotedPrintableTest, testEncode);
|
||||
CppUnit_addTest(pSuite, QuotedPrintableTest, testDecode);
|
||||
|
||||
return pSuite;
|
||||
}
|
39
vendor/POCO/Net/testsuite/src/QuotedPrintableTest.h
vendored
Normal file
39
vendor/POCO/Net/testsuite/src/QuotedPrintableTest.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// QuotedPrintableTest.h
|
||||
//
|
||||
// Definition of the QuotedPrintableTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef QuotedPrintableTest_INCLUDED
|
||||
#define QuotedPrintableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class QuotedPrintableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
QuotedPrintableTest(const std::string& name);
|
||||
~QuotedPrintableTest();
|
||||
|
||||
void testEncode();
|
||||
void testDecode();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // QuotedPrintableTest_INCLUDED
|
105
vendor/POCO/Net/testsuite/src/RawSocketTest.cpp
vendored
Normal file
105
vendor/POCO/Net/testsuite/src/RawSocketTest.cpp
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
//
|
||||
// RawSocketTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "RawSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/RawSocket.h"
|
||||
#include "Poco/Net/RawSocketImpl.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::RawSocket;
|
||||
using Poco::Net::RawSocketImpl;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::IOException;
|
||||
|
||||
|
||||
RawSocketTest::RawSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RawSocketTest::~RawSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::testEchoIPv4()
|
||||
{
|
||||
SocketAddress sa("127.0.0.1", 0);
|
||||
RawSocket rs(IPAddress::IPv4);
|
||||
rs.connect(sa);
|
||||
|
||||
int n = rs.sendBytes("hello", 5);
|
||||
assertTrue (5 == n);
|
||||
|
||||
char buffer[256] = "";
|
||||
unsigned char* ptr = (unsigned char*) buffer;
|
||||
|
||||
n = rs.receiveBytes(buffer, sizeof(buffer));
|
||||
int shift = ((buffer[0] & 0x0F) * 4);
|
||||
ptr += shift;
|
||||
|
||||
assertTrue (5 == (n - shift));
|
||||
assertTrue ("hello" == std::string((char*)ptr, 5));
|
||||
|
||||
rs.close();
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::testSendToReceiveFromIPv4()
|
||||
{
|
||||
RawSocket rs(IPAddress::IPv4);
|
||||
|
||||
int n = rs.sendTo("hello", 5, SocketAddress("127.0.0.1", 0));
|
||||
assertTrue (n == 5);
|
||||
|
||||
char buffer[256] = "";
|
||||
unsigned char* ptr = (unsigned char*) buffer;
|
||||
SocketAddress sa;
|
||||
n = rs.receiveFrom(buffer, sizeof(buffer), sa);
|
||||
int shift = ((buffer[0] & 0x0F) * 4);
|
||||
ptr += shift;
|
||||
|
||||
assertTrue ((n - shift) == 5);
|
||||
assertTrue ("hello" == std::string((char*)ptr, 5));
|
||||
rs.close();
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* RawSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RawSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, RawSocketTest, testEchoIPv4);
|
||||
CppUnit_addTest(pSuite, RawSocketTest, testSendToReceiveFromIPv4);
|
||||
|
||||
return pSuite;
|
||||
}
|
39
vendor/POCO/Net/testsuite/src/RawSocketTest.h
vendored
Normal file
39
vendor/POCO/Net/testsuite/src/RawSocketTest.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// RawSocketTest.h
|
||||
//
|
||||
// Definition of the RawSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef RawSocketTest_INCLUDED
|
||||
#define RawSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class RawSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
RawSocketTest(const std::string& name);
|
||||
~RawSocketTest();
|
||||
|
||||
void testEchoIPv4();
|
||||
void testSendToReceiveFromIPv4();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // RawSocketTest_INCLUDED
|
22
vendor/POCO/Net/testsuite/src/ReactorTestSuite.cpp
vendored
Normal file
22
vendor/POCO/Net/testsuite/src/ReactorTestSuite.cpp
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// ReactorTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "ReactorTestSuite.h"
|
||||
#include "SocketReactorTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* ReactorTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ReactorTestSuite");
|
||||
|
||||
pSuite->addTest(SocketReactorTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user