wsd: test: proper parsing of http header in UnitHttp
This removes the literal string comparison of the received http header with proper parsing and comparison. Change-Id: I383794aa1dc791632ec9d5ed2191880a57d457ee Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
6ed5dc9a64
commit
bd056aef91
2 changed files with 13 additions and 12 deletions
|
@ -22,6 +22,7 @@
|
|||
#include <Log.hpp>
|
||||
#include <Util.hpp>
|
||||
#include <Unit.hpp>
|
||||
#include <lokassert.hpp>
|
||||
|
||||
class UnitHTTP : public UnitWSD
|
||||
{
|
||||
|
@ -176,18 +177,19 @@ public:
|
|||
LOG_TST("Receiving...");
|
||||
char buffer[4096] = { 0, };
|
||||
int got = socket->receiveBytes(buffer, 4096);
|
||||
static const std::string start =
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Content-Disposition: attachment; filename=\"test.txt\"\r\n";
|
||||
|
||||
if (strncmp(buffer, start.c_str(), start.size()))
|
||||
{
|
||||
LOG_TST("missing pre-amble " << got << " [" << buffer << "] vs. expected [" << start
|
||||
<< ']');
|
||||
LOK_ASSERT(Util::startsWith(std::string(buffer), start));
|
||||
exitTest(TestResult::Failed);
|
||||
return;
|
||||
}
|
||||
http::Response httpResponse;
|
||||
LOK_ASSERT_MESSAGE("Expected to receive valid data",
|
||||
httpResponse.readData(buffer, got) > 0);
|
||||
LOK_ASSERT(!httpResponse.statusLine().httpVersion().empty());
|
||||
LOK_ASSERT(!httpResponse.statusLine().reasonPhrase().empty());
|
||||
LOK_ASSERT_EQUAL(http::StatusCode::OK, httpResponse.statusLine().statusCode());
|
||||
LOK_ASSERT(httpResponse.statusLine().statusCategory() ==
|
||||
http::StatusLine::StatusCodeClass::Successful);
|
||||
LOK_ASSERT_EQUAL(std::string("HTTP/1.0"), httpResponse.statusLine().httpVersion());
|
||||
LOK_ASSERT_EQUAL(std::string("OK"), httpResponse.statusLine().reasonPhrase());
|
||||
LOK_ASSERT_EQUAL(std::string("attachment; filename=\"test.txt\""),
|
||||
httpResponse.header().get("Content-Disposition"));
|
||||
|
||||
// TODO: check content-length etc.
|
||||
|
||||
|
|
|
@ -1813,7 +1813,6 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
|
|||
|
||||
const std::string fileName = Poco::Path(resultURL.getPath()).getFileName();
|
||||
Poco::Net::HTTPResponse response;
|
||||
// We have a fragile test that expects Content-Disposition first.
|
||||
if (!fileName.empty())
|
||||
response.set("Content-Disposition", "attachment; filename=\"" + fileName + '"');
|
||||
response.setContentType("application/octet-stream");
|
||||
|
|
Loading…
Reference in a new issue