Beispiel #1
0
TEST(HTTPRequest, testInvalid3)
{
	std::string s("GET / HTTP/1.10");
	std::istringstream istr(s);
	HTTPRequest request;
    EXPECT_THROW(request.read(istr), MessageException);
}
Beispiel #2
0
TEST(HTTPRequest, testInvalid1)
{
	std::string s(256, 'x');
	std::istringstream istr(s);
	HTTPRequest request;
    EXPECT_THROW(request.read(istr), MessageException);
}
Beispiel #3
0
TEST(HTTPRequest, testInvalid2)
{
	std::string s("GET ");
	s.append(8000, 'x');
	s.append("HTTP/1.0");
	std::istringstream istr(s);
	HTTPRequest request;
    EXPECT_THROW(request.read(istr), MessageException);
}
void HTTPRequestTest::testRead1()
{
	std::string s("GET / HTTP/1.0\r\n\r\n");
	std::istringstream istr(s);
	HTTPRequest request;
	request.read(istr);
	assert (request.getMethod() == HTTPRequest::HTTP_GET);
	assert (request.getURI() == "/");
	assert (request.getVersion() == HTTPMessage::HTTP_1_0);
	assert (request.empty());
	assert (istr.get() == -1);
}
Beispiel #5
0
TEST(HTTPRequest, testRead1)
{
	std::string s("GET / HTTP/1.0\r\n\r\n");
	std::istringstream istr(s);
	HTTPRequest request;
	request.read(istr);
	EXPECT_TRUE (request.getMethod() == HTTPRequest::HTTP_GET);
	EXPECT_TRUE (request.getURI() == "/");
	EXPECT_TRUE (request.getVersion() == HTTPMessage::HTTP_1_0);
	EXPECT_TRUE (request.empty());
	EXPECT_TRUE (istr.get() == -1);
}
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::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);
	assert (request.getMethod() == HTTPRequest::HTTP_HEAD);
	assert (request.getURI() == "/index.html");
	assert (request.getVersion() == HTTPMessage::HTTP_1_1);
	assert (request.size() == 3);
	assert (request["Connection"] == "Keep-Alive");
	assert (request["Host"] == "localhost");
	assert (request["User-Agent"] == "Poco");
	assert (istr.get() == -1);
}
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::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);
	assert (request.getMethod() == HTTPRequest::HTTP_POST);
	assert (request.getURI() == "/test.cgi");
	assert (request.getVersion() == HTTPMessage::HTTP_1_1);
	assert (request.size() == 5);
	assert (request["Connection"] == "Close");
	assert (request["Host"] == "localhost:8000");
	assert (request["User-Agent"] == "Poco");
	assert (request.getContentType() == "text/plain");
	assert (request.getContentLength() == 100);
	assert (istr.get() == -1);
}
Beispiel #10
0
SiriTokenProvider::Ptr SiriTokenProvider::FromAceHeader( const string& header )
{
    SiriTokenProvider::Ptr p=new SiriTokenProvider();
    p->m_http_string=header;
    if(p->m_http_string.find("Assistant(iPhone/iPhone4,1;")!=-1)
    {
        stringstream ss(p->m_http_string);
        HTTPRequest req;
        req.read(ss);
        if(req.has("X-Ace-Host"))
        {
            p->m_Ticket.x_ace_host=req["X-Ace-Host"];
        }
        if(req.has("User-Agent"))
        {
            p->m_Ticket.user_agent=req["User-Agent"];
        }
        p->iPhone4s=true;
        p->m_Ticket.iPhone4s=true;
        if(!p->CheckHeader())
        {
            delete p;
            return NULL;
        }
    }
    else
    {
        p->m_http_string=iPhone4s_header_tmpl;
        p->iPhone4s=false;
        p->m_Ticket.iPhone4s=false;
        if(!p->CheckHeader())
        {
            delete p;
            return NULL;
        }

        stringstream ss(p->m_http_string);
        HTTPRequest req;
        req.read(ss);

        string strAceHost;
        size_t offset=p->m_http_string.find("X-Ace-Host");
        if(offset!=-1)
        {
            size_t n1=p->m_http_string.find(":",offset);
            if(n1==(offset+strlen("X-Ace-Host")))
            {
                size_t n2=p->m_http_string.find("\r\n",n1);
                if(n2>n1)
                {
                    string ace_host=p->m_http_string.substr(n1+1,n2-n1);
                    p->m_Ticket.x_ace_host=ace_host;
                    strAceHost=ace_host;
                }
            }
        }
        if(req.has("X-Ace-Host"))
        {
            strAceHost==req.get("X-Ace-Host");
            if(!strAceHost.empty())
                p->m_Ticket.x_ace_host=strAceHost;
        }

        p->m_Ticket.x_ace_host_tmpl=p->m_Ticket.x_ace_host;

        if(!SiriTokenProvider::GetNextTicket(&p->m_Ticket))
        {
            delete p;
            return NULL;
        }

        p->m_http_string=Poco::replace(p->m_http_string,strAceHost,p->m_Ticket.x_ace_host);
        p->m_http_string=Poco::replace(p->m_http_string,"siri.cd-team.org","guzzoni.apple.com");

    }

    return p;
}