Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/build_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if [ "$1" != "-nofetch" ]; then
fi

# This is the hash on https://github.com/envoyproxy/envoy-filter-example.git we pin to.
(cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 4b6c55b726eda8a1f99e6f4ca1a87f6ce670604f)
(cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 92307d723a1ead25c39f025a734fa091443efdbc)
cp -f "${ENVOY_SRCDIR}"/ci/WORKSPACE.filter.example "${ENVOY_FILTER_EXAMPLE_SRCDIR}"/WORKSPACE
fi

Expand Down
6 changes: 6 additions & 0 deletions include/envoy/buffer/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ class Instance {
*/
virtual ssize_t search(const void* data, uint64_t size, size_t start) const PURE;

/**
* Constructs a flattened string from a buffer.
* @return the flattened string.
*/
virtual std::string toString() const PURE;

/**
* Write the buffer out to a file descriptor.
* @param fd supplies the descriptor to write to.
Expand Down
7 changes: 1 addition & 6 deletions source/common/buffer/buffer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ class OwnedImpl : public LibEventInstance {
ssize_t search(const void* data, uint64_t size, size_t start) const override;
int write(int fd) override;
void postProcess() override {}

/**
* Construct a flattened string from a buffer.
* @return the flattened string.
*/
std::string toString() const;
std::string toString() const override;

Event::Libevent::BufferPtr& buffer() override { return buffer_; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BufferWrapper : public Buffer::Instance {
uint64_t reserve(uint64_t, Buffer::RawSlice*, uint64_t) override { NOT_IMPLEMENTED; }
ssize_t search(const void*, uint64_t, size_t) const override { NOT_IMPLEMENTED; }
int write(int) override { NOT_IMPLEMENTED; }
std::string toString() const override { NOT_IMPLEMENTED; }

private:
Buffer::Instance& underlying_;
Expand Down
14 changes: 7 additions & 7 deletions test/common/decompressor/zlib_decompressor_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ZlibDecompressorImplTest : public testing::Test {
std::string original_text{};
for (uint64_t i = 0; i < 30; ++i) {
TestUtility::feedBufferWithRandomCharacters(buffer, default_input_size * i, i);
original_text.append(TestUtility::bufferToString(buffer));
original_text.append(buffer.toString());
compressor.compress(buffer, Compressor::State::Flush);
accumulation_buffer.add(buffer);
drainBuffer(buffer);
Expand All @@ -45,7 +45,7 @@ class ZlibDecompressorImplTest : public testing::Test {
decompressor.init(window_bits);

decompressor.decompress(accumulation_buffer, buffer);
std::string decompressed_text{TestUtility::bufferToString(buffer)};
std::string decompressed_text{buffer.toString()};

ASSERT_EQ(compressor.checksum(), decompressor.checksum());
ASSERT_EQ(original_text.length(), decompressed_text.length());
Expand Down Expand Up @@ -122,7 +122,7 @@ TEST_F(ZlibDecompressorImplTest, CompressAndDecompress) {
std::string original_text{};
for (uint64_t i = 0; i < 20; ++i) {
TestUtility::feedBufferWithRandomCharacters(buffer, default_input_size * i, i);
original_text.append(TestUtility::bufferToString(buffer));
original_text.append(buffer.toString());
compressor.compress(buffer, Compressor::State::Flush);
accumulation_buffer.add(buffer);
drainBuffer(buffer);
Expand All @@ -142,7 +142,7 @@ TEST_F(ZlibDecompressorImplTest, CompressAndDecompress) {
decompressor.init(gzip_window_bits);

decompressor.decompress(accumulation_buffer, buffer);
std::string decompressed_text{TestUtility::bufferToString(buffer)};
std::string decompressed_text{buffer.toString()};

ASSERT_EQ(compressor.checksum(), decompressor.checksum());
ASSERT_EQ(original_text.length(), decompressed_text.length());
Expand All @@ -162,7 +162,7 @@ TEST_F(ZlibDecompressorImplTest, DecompressWithSmallOutputBuffer) {
std::string original_text{};
for (uint64_t i = 0; i < 20; ++i) {
TestUtility::feedBufferWithRandomCharacters(buffer, default_input_size * i, i);
original_text.append(TestUtility::bufferToString(buffer));
original_text.append(buffer.toString());
compressor.compress(buffer, Compressor::State::Flush);
accumulation_buffer.add(buffer);
drainBuffer(buffer);
Expand All @@ -182,7 +182,7 @@ TEST_F(ZlibDecompressorImplTest, DecompressWithSmallOutputBuffer) {
decompressor.init(gzip_window_bits);

decompressor.decompress(accumulation_buffer, buffer);
std::string decompressed_text{TestUtility::bufferToString(buffer)};
std::string decompressed_text{buffer.toString()};

ASSERT_EQ(compressor.checksum(), decompressor.checksum());
ASSERT_EQ(original_text.length(), decompressed_text.length());
Expand Down Expand Up @@ -244,7 +244,7 @@ TEST_F(ZlibDecompressorImplTest, CompressDecompressOfMultipleSlices) {
ASSERT_EQ(0, buffer.length());

decompressor.decompress(accumulation_buffer, buffer);
std::string decompressed_text{TestUtility::bufferToString(buffer)};
std::string decompressed_text{buffer.toString()};

ASSERT_EQ(compressor.checksum(), decompressor.checksum());
ASSERT_EQ(original_text.length(), decompressed_text.length());
Expand Down
20 changes: 7 additions & 13 deletions test/common/http/codec_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ TEST_P(CodecNetworkTest, SendData) {
Buffer::OwnedImpl data(full_data);
upstream_connection_->write(data, false);
EXPECT_CALL(*codec_, dispatch(_)).WillOnce(Invoke([&](Buffer::Instance& data) -> void {
EXPECT_EQ(full_data, TestUtility::bufferToString(data));
EXPECT_EQ(full_data, data.toString());
dispatcher_->exit();
}));
dispatcher_->run(Event::Dispatcher::RunType::Block);
Expand All @@ -375,12 +375,9 @@ TEST_P(CodecNetworkTest, SendHeadersAndClose) {
upstream_connection_->close(Network::ConnectionCloseType::FlushWrite);
EXPECT_CALL(*codec_, dispatch(_))
.Times(2)
.WillOnce(Invoke([&](Buffer::Instance& data) -> void {
EXPECT_EQ(full_data, TestUtility::bufferToString(data));
}))
.WillOnce(Invoke([&](Buffer::Instance& data) -> void {
EXPECT_EQ("", TestUtility::bufferToString(data));
}));
.WillOnce(
Invoke([&](Buffer::Instance& data) -> void { EXPECT_EQ(full_data, data.toString()); }))
.WillOnce(Invoke([&](Buffer::Instance& data) -> void { EXPECT_EQ("", data.toString()); }));
// Because the headers are not complete, the disconnect will reset the stream.
// Note even if the final \r\n were appended to the header data, enough of the
// codec state is mocked out that the data would not be framed and the stream
Expand Down Expand Up @@ -411,12 +408,9 @@ TEST_P(CodecNetworkTest, SendHeadersAndCloseUnderReadDisable) {

EXPECT_CALL(*codec_, dispatch(_))
.Times(2)
.WillOnce(Invoke([&](Buffer::Instance& data) -> void {
EXPECT_EQ(full_data, TestUtility::bufferToString(data));
}))
.WillOnce(Invoke([&](Buffer::Instance& data) -> void {
EXPECT_EQ("", TestUtility::bufferToString(data));
}));
.WillOnce(
Invoke([&](Buffer::Instance& data) -> void { EXPECT_EQ(full_data, data.toString()); }))
.WillOnce(Invoke([&](Buffer::Instance& data) -> void { EXPECT_EQ("", data.toString()); }));
EXPECT_CALL(inner_encoder_.stream_, resetStream(_)).WillOnce(InvokeWithoutArgs([&]() -> void {
for (auto callbacks : inner_encoder_.stream_.callbacks_) {
callbacks->onResetStream(StreamResetReason::RemoteReset);
Expand Down
6 changes: 2 additions & 4 deletions test/common/http/conn_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1972,8 +1972,7 @@ TEST_F(HttpConnectionManagerImplTest, FilterAddBodyDuringDecodeData) {
EXPECT_CALL(*decoder_filters_[0], decodeData(_, true))
.WillOnce(Invoke([&](Buffer::Instance& data, bool) -> FilterDataStatus {
decoder_filters_[0]->callbacks_->addDecodedData(data, true);
EXPECT_EQ(TestUtility::bufferToString(*decoder_filters_[0]->callbacks_->decodingBuffer()),
"helloworld");
EXPECT_EQ(decoder_filters_[0]->callbacks_->decodingBuffer()->toString(), "helloworld");
return FilterDataStatus::Continue;
}));
EXPECT_CALL(*decoder_filters_[1], decodeHeaders(_, false))
Expand All @@ -1992,8 +1991,7 @@ TEST_F(HttpConnectionManagerImplTest, FilterAddBodyDuringDecodeData) {
EXPECT_CALL(*encoder_filters_[0], encodeData(_, true))
.WillOnce(Invoke([&](Buffer::Instance& data, bool) -> FilterDataStatus {
encoder_filters_[0]->callbacks_->addEncodedData(data, true);
EXPECT_EQ(TestUtility::bufferToString(*encoder_filters_[0]->callbacks_->encodingBuffer()),
"goodbye");
EXPECT_EQ(encoder_filters_[0]->callbacks_->encodingBuffer()->toString(), "goodbye");
return FilterDataStatus::Continue;
}));
EXPECT_CALL(*encoder_filters_[1], encodeHeaders(_, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class GrpcJsonTranscoderIntegrationTest
for (size_t i = 0; i < grpc_request_messages.size(); ++i) {
RequestType actual_message;
if (frames[i].length_ > 0) {
EXPECT_TRUE(
actual_message.ParseFromString(TestUtility::bufferToString(*frames[i].data_)));
EXPECT_TRUE(actual_message.ParseFromString(frames[i].data_->toString()));
}
RequestType expected_message;
EXPECT_TRUE(TextFormat::ParseFromString(grpc_request_messages[i], &expected_message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryPost) {
expected_request.mutable_shelf()->set_theme("Children");

bookstore::CreateShelfRequest request;
request.ParseFromString(TestUtility::bufferToString(*frames[0].data_));
request.ParseFromString(frames[0].data_->toString());

EXPECT_EQ(expected_request.ByteSize(), frames[0].length_);
EXPECT_TRUE(MessageDifferencer::Equals(expected_request, request));
Expand All @@ -327,7 +327,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryPost) {
EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer,
filter_.encodeData(*response_data, false));

std::string response_json = TestUtility::bufferToString(*response_data);
std::string response_json = response_data->toString();

EXPECT_EQ("{\"id\":\"20\",\"theme\":\"Children\"}", response_json);

Expand Down Expand Up @@ -366,7 +366,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryPostWithPackageServiceMetho
expected_request.mutable_shelf()->set_theme("Children");

bookstore::CreateShelfRequest request;
request.ParseFromString(TestUtility::bufferToString(*frames[0].data_));
request.ParseFromString(frames[0].data_->toString());

EXPECT_EQ(expected_request.ByteSize(), frames[0].length_);
EXPECT_TRUE(MessageDifferencer::Equals(expected_request, request));
Expand All @@ -391,7 +391,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryPostWithPackageServiceMetho
EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer,
filter_.encodeData(*response_data, false));

std::string response_json = TestUtility::bufferToString(*response_data);
std::string response_json = response_data->toString();

EXPECT_EQ("{\"id\":\"20\",\"theme\":\"Children\"}", response_json);

Expand Down Expand Up @@ -427,7 +427,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, ForwardUnaryPostGrpc) {
expected_request.mutable_shelf()->set_theme("Children");

bookstore::CreateShelfRequest forwarded_request;
forwarded_request.ParseFromString(TestUtility::bufferToString(*frames[0].data_));
forwarded_request.ParseFromString(frames[0].data_->toString());

EXPECT_EQ(expected_request.ByteSize(), frames[0].length_);
EXPECT_TRUE(MessageDifferencer::Equals(expected_request, forwarded_request));
Expand Down Expand Up @@ -458,7 +458,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, ForwardUnaryPostGrpc) {
EXPECT_EQ(1, frames.size());

bookstore::Shelf forwarded_response;
forwarded_response.ParseFromString(TestUtility::bufferToString(*frames[0].data_));
forwarded_response.ParseFromString(frames[0].data_->toString());

EXPECT_EQ(expected_response.ByteSize(), frames[0].length_);
EXPECT_TRUE(MessageDifferencer::Equals(expected_response, forwarded_response));
Expand Down Expand Up @@ -594,7 +594,7 @@ TEST_P(GrpcJsonTranscoderFilterPrintTest, PrintOptions) {
EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer,
filter_->encodeData(*response_data, false));

std::string response_json = TestUtility::bufferToString(*response_data);
std::string response_json = response_data->toString();
EXPECT_EQ(GetParam().expected_response_, response_json);
}

Expand Down
20 changes: 8 additions & 12 deletions test/extensions/filters/http/grpc_web/grpc_web_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ class GrpcWebFilterTest : public testing::TestWithParam<std::tuple<std::string,
EXPECT_EQ(static_cast<uint64_t>(expected_code), code);
}));
EXPECT_CALL(decoder_callbacks_, encodeData(_, _))
.WillOnce(Invoke([=](Buffer::Instance& data, bool) {
EXPECT_EQ(expected_message, TestUtility::bufferToString(data));
}));
.WillOnce(Invoke(
[=](Buffer::Instance& data, bool) { EXPECT_EQ(expected_message, data.toString()); }));
}

void expectRequiredGrpcUpstreamHeaders(const Http::HeaderMap& request_headers) {
Expand Down Expand Up @@ -247,7 +246,7 @@ TEST_P(GrpcWebFilterTest, Unary) {
EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(request_buffer, true));
decoded_buffer.move(request_buffer);
}
EXPECT_EQ(std::string(MESSAGE, MESSAGE_SIZE), TestUtility::bufferToString(decoded_buffer));
EXPECT_EQ(std::string(MESSAGE, MESSAGE_SIZE), decoded_buffer.toString());
} else if (isTextRequest()) {
Buffer::OwnedImpl request_buffer;
Buffer::OwnedImpl decoded_buffer;
Expand All @@ -266,8 +265,7 @@ TEST_P(GrpcWebFilterTest, Unary) {
}
decoded_buffer.move(request_buffer);
}
EXPECT_EQ(std::string(TEXT_MESSAGE, TEXT_MESSAGE_SIZE),
TestUtility::bufferToString(decoded_buffer));
EXPECT_EQ(std::string(TEXT_MESSAGE, TEXT_MESSAGE_SIZE), decoded_buffer.toString());
} else {
FAIL() << "Unsupported gRPC-Web request content-type: " << request_content_type();
}
Expand Down Expand Up @@ -304,7 +302,7 @@ TEST_P(GrpcWebFilterTest, Unary) {
EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(response_buffer, false));
encoded_buffer.move(response_buffer);
}
EXPECT_EQ(std::string(MESSAGE, MESSAGE_SIZE), TestUtility::bufferToString(encoded_buffer));
EXPECT_EQ(std::string(MESSAGE, MESSAGE_SIZE), encoded_buffer.toString());
} else if (accept_text_response()) {
Buffer::OwnedImpl response_buffer;
Buffer::OwnedImpl encoded_buffer;
Expand All @@ -318,8 +316,7 @@ TEST_P(GrpcWebFilterTest, Unary) {
}
encoded_buffer.move(response_buffer);
}
EXPECT_EQ(std::string(B64_MESSAGE, B64_MESSAGE_SIZE),
TestUtility::bufferToString(encoded_buffer));
EXPECT_EQ(std::string(B64_MESSAGE, B64_MESSAGE_SIZE), encoded_buffer.toString());
} else {
FAIL() << "Unsupported gRPC-Web response content-type: "
<< response_headers.ContentType()->value().c_str();
Expand All @@ -334,10 +331,9 @@ TEST_P(GrpcWebFilterTest, Unary) {
response_trailers.addCopy(Http::Headers::get().GrpcMessage, "ok");
EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers));
if (accept_binary_response()) {
EXPECT_EQ(std::string(TRAILERS, TRAILERS_SIZE), TestUtility::bufferToString(trailers_buffer));
EXPECT_EQ(std::string(TRAILERS, TRAILERS_SIZE), trailers_buffer.toString());
} else if (accept_text_response()) {
EXPECT_EQ(std::string(TRAILERS, TRAILERS_SIZE),
Base64::decode(TestUtility::bufferToString(trailers_buffer)));
EXPECT_EQ(std::string(TRAILERS, TRAILERS_SIZE), Base64::decode(trailers_buffer.toString()));
} else {
FAIL() << "Unsupported gRPC-Web response content-type: "
<< response_headers.ContentType()->value().c_str();
Expand Down
4 changes: 2 additions & 2 deletions test/extensions/filters/http/gzip/gzip_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class GzipFilterTest : public testing::Test {

void verifyCompressedData() {
decompressor_.decompress(data_, decompressed_data_);
const std::string uncompressed_str{TestUtility::bufferToString(decompressed_data_)};
const std::string uncompressed_str{decompressed_data_.toString()};
ASSERT_EQ(expected_str_.length(), uncompressed_str.length());
EXPECT_EQ(expected_str_, uncompressed_str);
EXPECT_EQ(expected_str_.length(), stats_.counter("test.gzip.total_uncompressed_bytes").value());
Expand All @@ -77,7 +77,7 @@ class GzipFilterTest : public testing::Test {

void feedBuffer(uint64_t size) {
TestUtility::feedBufferWithRandomCharacters(data_, size);
expected_str_ += TestUtility::bufferToString(data_);
expected_str_ += data_.toString();
}

void drainBuffer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ TEST_P(SquashFilterIntegrationTest, TestHappyPath) {
EXPECT_STREQ("/api/v2/debugattachment/", create_stream->headers().Path()->value().c_str());
// Make sure the env var was replaced
ProtobufWkt::Struct actualbody;
MessageUtil::loadFromJson(TestUtility::bufferToString(create_stream->body()), actualbody);
MessageUtil::loadFromJson(create_stream->body().toString(), actualbody);

ProtobufWkt::Struct expectedbody;
MessageUtil::loadFromJson("{\"spec\": { \"attachment\" : { \"env\": \"" ENV_VAR_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ProxyProtocolTest : public testing::TestWithParam<Network::Address::IpVers
EXPECT_CALL(*read_filter_, onNewConnection());
EXPECT_CALL(*read_filter_, onData(_, _))
.WillOnce(Invoke([&](Buffer::Instance& buffer, bool) -> Network::FilterStatus {
EXPECT_EQ(TestUtility::bufferToString(buffer), expected);
EXPECT_EQ(buffer.toString(), expected);
buffer.drain(expected.length());
dispatcher_.exit();
return Network::FilterStatus::Continue;
Expand Down Expand Up @@ -391,7 +391,7 @@ class WildcardProxyProtocolTest : public testing::TestWithParam<Network::Address
EXPECT_CALL(*read_filter_, onNewConnection());
EXPECT_CALL(*read_filter_, onData(_, _))
.WillOnce(Invoke([&](Buffer::Instance& buffer, bool) -> Network::FilterStatus {
EXPECT_EQ(TestUtility::bufferToString(buffer), expected);
EXPECT_EQ(buffer.toString(), expected);
buffer.drain(expected.length());
dispatcher_.exit();
return Network::FilterStatus::Continue;
Expand Down
Loading