test/extensions/filters/http/ext_proc/filter_test.cc
// Using the default configuration, test the filter with a processor that
// replies to the request_headers message with an empty response
Using the default configuration, test the filter with a processor that
replies to the request_headers message with an empty response
Using the default configuration test the filter with a processor that replies to the request_headers message with an empty response
TEST_F(HttpFilterTest, SimplestPost) {
  initialize(R"EOF(
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
  failure_mode_allow: true
  )EOF");
  EXPECT_TRUE(config_->failureModeAllow());
  HttpTestUtility::addDefaultHeaders(request_headers_, "POST");
  request_headers_.addCopy(LowerCaseString("content-type"), "text/plain");
  request_headers_.addCopy(LowerCaseString("content-length"), 10);
  request_headers_.addCopy(LowerCaseString("x-some-other-header"), "yes");
  EXPECT_EQ(FilterHeadersStatus::StopAllIterationAndWatermark,
            filter_->decodeHeaders(request_headers_, false));
  EXPECT_FALSE(last_request_.async_mode());
  EXPECT_FALSE(stream_close_sent_);
  ASSERT_TRUE(last_request_.has_request_headers());
  const auto request_headers = last_request_.request_headers();
  EXPECT_FALSE(request_headers.end_of_stream());
  Http::TestRequestHeaderMapImpl expected{{":path", "/"},
                                          {":method", "POST"},
                                          {":scheme", "http"},
                                          {"host", "host"},
                                          {"content-type", "text/plain"},
                                          {"content-length", "10"},
                                          {"x-some-other-header", "yes"}};
  EXPECT_TRUE(
      ExtProcTestUtility::headerProtosEqualIgnoreOrder(expected, request_headers.headers()));
  EXPECT_CALL(decoder_callbacks_, continueDecoding());
  std::unique_ptr<ProcessingResponse> resp1 = std::make_unique<ProcessingResponse>();
  resp1->mutable_request_headers();
  stream_callbacks_->onReceiveMessage(std::move(resp1));
  data_.add("foo");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encode100ContinueHeaders(response_headers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, true));
  data_.add("bar");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, false));
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_));
  filter_->onDestroy();
  EXPECT_TRUE(stream_close_sent_);
  EXPECT_EQ(1, config_->stats().streams_started_.value());
  EXPECT_EQ(1, config_->stats().stream_msgs_sent_.value());
  EXPECT_EQ(1, config_->stats().stream_msgs_received_.value());
  EXPECT_EQ(1, config_->stats().streams_closed_.value());
}
TEST_F ( HttpFilterTest , SimplestPost ) { initialize ( R" EOF ( 
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
  failure_mode_allow: true
   ) EOF " ) ; EXPECT_TRUE ( config_ -> failureModeAllow ( ) ) ; HttpTestUtility :: addDefaultHeaders ( request_headers_ , " " ) ; request_headers_ . addCopy ( LowerCaseString ( " " ) , " " ) ; request_headers_ . addCopy ( LowerCaseString ( " " ) , 10 ) ; request_headers_ . addCopy ( LowerCaseString ( " " ) , " " ) ; EXPECT_EQ ( FilterHeadersStatus :: StopAllIterationAndWatermark , filter_ -> decodeHeaders ( request_headers_ , false ) ) ; EXPECT_FALSE ( last_request_ . async_mode ( ) ) ; EXPECT_FALSE ( stream_close_sent_ ) ; ASSERT_TRUE ( last_request_ . has_request_headers ( ) ) ; const auto request_headers = last_request_ . request_headers ( ) ; EXPECT_FALSE ( request_headers . end_of_stream ( ) ) ; Http :: TestRequestHeaderMapImpl expected { { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } } ; EXPECT_TRUE ( ExtProcTestUtility :: headerProtosEqualIgnoreOrder ( expected , request_headers . headers ( ) ) ) ; EXPECT_CALL ( decoder_callbacks_ , continueDecoding ( ) ) ; std :: unique_ptr < ProcessingResponse > resp1 = std :: make_unique < ProcessingResponse > ( ) ; resp1 -> mutable_request_headers ( ) ; stream_callbacks_ -> onReceiveMessage ( std :: move ( resp1 ) ) ; data_ . add ( " " ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> decodeData ( data_ , true ) ) ; EXPECT_EQ ( FilterTrailersStatus :: Continue , filter_ -> decodeTrailers ( request_trailers_ ) ) ; EXPECT_EQ ( FilterHeadersStatus :: Continue , filter_ -> encode100ContinueHeaders ( response_headers_ ) ) ; EXPECT_EQ ( FilterHeadersStatus :: Continue , filter_ -> encodeHeaders ( response_headers_ , true ) ) ; data_ . add ( " " ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> encodeData ( data_ , false ) ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> encodeData ( data_ , true ) ) ; EXPECT_EQ ( FilterTrailersStatus :: Continue , filter_ -> encodeTrailers ( response_trailers_ ) ) ; filter_ -> onDestroy ( ) ; EXPECT_TRUE ( stream_close_sent_ ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . streams_started_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . stream_msgs_sent_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . stream_msgs_received_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . streams_closed_ . value ( ) ) ; }
Using the default configuration, test the filter with a processor that
replies to the request_headers message with an empty response
Using the default configuration test the filter with a processor that replies to the request_headers message with an empty response
// Create synthetic HTTP request // Verify that call was received by mock gRPC server // Send back a response