@@ -4968,8 +4968,8 @@ TEST_P(Http1ServerConnectionImplTest, ValueStartsWithCR) {
4968
4968
const absl::string_view value = " \r value starts with carriage return" ;
4969
4969
4970
4970
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
4971
- const absl::string_view expected_value = " value starts with carriage return " ;
4972
- testRequestWithValueExpectSuccess ( value, expected_value );
4971
+ testRequestWithValueExpectFailure ( value, " http1.invalid_characters " ,
4972
+ " header value contains invalid chars " );
4973
4973
} else {
4974
4974
#ifdef ENVOY_ENABLE_UHV
4975
4975
testRequestWithValueExpectFailure (value, " http1.codec_error" , " HPE_INVALID_HEADER_TOKEN" );
@@ -4983,8 +4983,8 @@ TEST_P(Http1ServerConnectionImplTest, ValueWithCRInTheMiddle) {
4983
4983
const absl::string_view value = " value has \r carriage return in the middle" ;
4984
4984
4985
4985
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
4986
- const absl::string_view expected_value = " value has carriage return in the middle " ;
4987
- testRequestWithValueExpectSuccess ( value, expected_value );
4986
+ testRequestWithValueExpectFailure ( value, " http1.invalid_characters " ,
4987
+ " header value contains invalid chars " );
4988
4988
} else {
4989
4989
testRequestWithValueExpectFailure (value, " http1.codec_error" , " HPE_LF_EXPECTED" );
4990
4990
}
@@ -4994,8 +4994,8 @@ TEST_P(Http1ServerConnectionImplTest, ValueEndsWithCR) {
4994
4994
const absl::string_view value = " value ends in carriage return \r " ;
4995
4995
4996
4996
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
4997
- const absl::string_view expected_value = " value ends in carriage return " ;
4998
- testRequestWithValueExpectSuccess ( value, expected_value );
4997
+ testRequestWithValueExpectFailure ( value, " http1.invalid_characters " ,
4998
+ " header value contains invalid chars " );
4999
4999
} else {
5000
5000
testRequestWithValueExpectFailure (value, " http1.codec_error" , " HPE_LF_EXPECTED" );
5001
5001
}
@@ -5093,8 +5093,7 @@ TEST_P(Http1ClientConnectionImplTest, ValueStartsWithCR) {
5093
5093
const absl::string_view value = " \r value starts with carriage return" ;
5094
5094
5095
5095
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5096
- const absl::string_view expected_value = " value starts with carriage return" ;
5097
- testRequestWithValueExpectSuccess (value, expected_value);
5096
+ testRequestWithValueExpectFailure (value, " header value contains invalid chars" );
5098
5097
} else {
5099
5098
#ifdef ENVOY_ENABLE_UHV
5100
5099
testRequestWithValueExpectFailure (value, " HPE_INVALID_HEADER_TOKEN" );
@@ -5108,8 +5107,7 @@ TEST_P(Http1ClientConnectionImplTest, ValueWithCRInTheMiddle) {
5108
5107
const absl::string_view value = " value has \r carriage return in the middle" ;
5109
5108
5110
5109
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5111
- const absl::string_view expected_value = " value has carriage return in the middle" ;
5112
- testRequestWithValueExpectSuccess (value, expected_value);
5110
+ testRequestWithValueExpectFailure (value, " header value contains invalid chars" );
5113
5111
} else {
5114
5112
testRequestWithValueExpectFailure (value, " HPE_LF_EXPECTED" );
5115
5113
}
@@ -5119,8 +5117,7 @@ TEST_P(Http1ClientConnectionImplTest, ValueEndsWithCR) {
5119
5117
const absl::string_view value = " value ends in carriage return \r " ;
5120
5118
5121
5119
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5122
- const absl::string_view expected_value = " value ends in carriage return" ;
5123
- testRequestWithValueExpectSuccess (value, expected_value);
5120
+ testRequestWithValueExpectFailure (value, " header value contains invalid chars" );
5124
5121
} else {
5125
5122
testRequestWithValueExpectFailure (value, " HPE_LF_EXPECTED" );
5126
5123
}
@@ -5154,24 +5151,20 @@ TEST_P(Http1ServerConnectionImplTest, FirstLineInvalidCR) {
5154
5151
MockRequestDecoder decoder;
5155
5152
EXPECT_CALL (callbacks_, newStream (_, _)).WillOnce (ReturnRef (decoder));
5156
5153
5157
- TestRequestHeaderMapImpl expected_headers{
5158
- {" :path" , " /" },
5159
- {" :method" , " GET" },
5160
- };
5161
5154
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5162
- EXPECT_CALL (decoder, decodeHeaders_ (HeaderMapEqual (&expected_headers), true ));
5155
+ EXPECT_CALL (decoder, sendLocalReply (Http::Code::BadRequest, " Bad Request" , _, _,
5156
+ " http1.invalid_characters" ));
5163
5157
} else {
5164
5158
EXPECT_CALL (decoder,
5165
5159
sendLocalReply (Http::Code::BadRequest, " Bad Request" , _, _, " http1.codec_error" ));
5166
5160
}
5167
5161
5168
5162
Buffer::OwnedImpl buffer (" GET /\r HTTP/1.1\r\n\r\n " );
5169
5163
auto status = codec_->dispatch (buffer);
5164
+ EXPECT_TRUE (isCodecProtocolError (status));
5170
5165
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5171
- EXPECT_TRUE (status.ok ());
5172
- EXPECT_EQ (0u , buffer.length ());
5166
+ EXPECT_EQ (status.message (), " http/1.1 protocol error: header value contains invalid chars" );
5173
5167
} else {
5174
- EXPECT_TRUE (isCodecProtocolError (status));
5175
5168
EXPECT_EQ (status.message (), " http/1.1 protocol error: HPE_LF_EXPECTED" );
5176
5169
}
5177
5170
}
@@ -5190,24 +5183,13 @@ TEST_P(Http1ClientConnectionImplTest, FirstLineInvalidCR) {
5190
5183
};
5191
5184
EXPECT_TRUE (request_encoder.encodeHeaders (headers, true ).ok ());
5192
5185
5193
- TestResponseHeaderMapImpl expected_headers{
5194
- {" :status" , " 200" },
5195
- {" content-length" , " 5" },
5196
- };
5197
- if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5198
- EXPECT_CALL (response_decoder, decodeHeaders_ (HeaderMapEqual (&expected_headers), false ));
5199
- EXPECT_CALL (response_decoder, decodeData (BufferStringEqual (" hello" ), false ));
5200
- EXPECT_CALL (response_decoder, decodeData (BufferStringEqual (" " ), true ));
5201
- }
5202
-
5203
5186
Buffer::OwnedImpl buffer (" HTTP/1.1 200\r OK\r\n content-length: 5\r\n\r\n "
5204
5187
" hello" );
5205
5188
auto status = codec_->dispatch (buffer);
5189
+ EXPECT_TRUE (isCodecProtocolError (status));
5206
5190
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5207
- EXPECT_TRUE (status.ok ());
5208
- EXPECT_EQ (0u , buffer.length ());
5191
+ EXPECT_EQ (status.message (), " http/1.1 protocol error: header value contains invalid chars" );
5209
5192
} else {
5210
- EXPECT_TRUE (isCodecProtocolError (status));
5211
5193
#ifdef ENVOY_ENABLE_UHV
5212
5194
EXPECT_EQ (status.message (), " http/1.1 protocol error: HPE_INVALID_HEADER_TOKEN" );
5213
5195
#else
@@ -5225,16 +5207,21 @@ TEST_P(Http1ServerConnectionImplTest, HeaderNameInvalidCR) {
5225
5207
5226
5208
MockRequestDecoder decoder;
5227
5209
EXPECT_CALL (callbacks_, newStream (_, _)).WillOnce (ReturnRef (decoder));
5228
- EXPECT_CALL (decoder,
5229
- sendLocalReply (Http::Code::BadRequest, " Bad Request" , _, _, " http1.codec_error" ));
5210
+ if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5211
+ EXPECT_CALL (decoder, sendLocalReply (Http::Code::BadRequest, " Bad Request" , _, _,
5212
+ " http1.invalid_characters" ));
5213
+ } else {
5214
+ EXPECT_CALL (decoder,
5215
+ sendLocalReply (Http::Code::BadRequest, " Bad Request" , _, _, " http1.codec_error" ));
5216
+ }
5230
5217
5231
5218
// SPELLCHECKER(off)
5232
5219
Buffer::OwnedImpl buffer (" GET / HTTP/1.1\r\n fo\r o: bar\r\n\r\n " );
5233
5220
// SPELLCHECKER(on)
5234
5221
auto status = codec_->dispatch (buffer);
5235
5222
EXPECT_TRUE (isCodecProtocolError (status));
5236
5223
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5237
- EXPECT_EQ (status.message (), " http/1.1 protocol error: INVALID_HEADER_NAME_CHARACTER " );
5224
+ EXPECT_EQ (status.message (), " http/1.1 protocol error: header value contains invalid chars " );
5238
5225
} else {
5239
5226
EXPECT_EQ (status.message (), " http/1.1 protocol error: HPE_INVALID_HEADER_TOKEN" );
5240
5227
}
@@ -5260,7 +5247,7 @@ TEST_P(Http1ClientConnectionImplTest, HeaderNameInvalidCR) {
5260
5247
auto status = codec_->dispatch (buffer);
5261
5248
EXPECT_TRUE (isCodecProtocolError (status));
5262
5249
if (parser_impl_ == Http1ParserImpl::BalsaParser) {
5263
- EXPECT_EQ (status.message (), " http/1.1 protocol error: INVALID_HEADER_NAME_CHARACTER " );
5250
+ EXPECT_EQ (status.message (), " http/1.1 protocol error: header value contains invalid chars " );
5264
5251
} else {
5265
5252
EXPECT_EQ (status.message (), " http/1.1 protocol error: HPE_INVALID_HEADER_TOKEN" );
5266
5253
}
0 commit comments