@@ -635,10 +635,8 @@ TEST_F(ExtAuthzGrpcClientTest, AuthorizationOkUpstreamHeaderMutations) {
635635 span_);
636636}
637637
638- // TODO(https://github.com/envoyproxy/envoy/issues/45003)
639- // This test ensures the default (buggy) behavior remains unchanged since
640- // existing Envoy deployments may be relying on the default (buggy) behavior
641- TEST_F (ExtAuthzGrpcClientTest, AuthorizationOkWithKeepEmptyValueIgnored) {
638+ // This test ensures keep_empty_value is respected in ext_authz responses.
639+ TEST_F (ExtAuthzGrpcClientTest, AuthorizationOkWithKeepEmptyValueRespected) {
642640 initialize ();
643641
644642 envoy::service::auth::v3::CheckResponse check_response;
@@ -654,12 +652,10 @@ TEST_F(ExtAuthzGrpcClientTest, AuthorizationOkWithKeepEmptyValueIgnored) {
654652)EOF" ,
655653 check_response);
656654
657- // If keep_empty_value were respected, the header "x-keep-empty" should be DROPPED
658- // because its value is empty. However, the current implementation ignores this
659- // flag and blindly adds the empty header to the headers_to_set vector.
655+ // keep_empty_value is false and value is empty, so the header should be dropped.
660656 auto expected_authz_response = Response{
661657 .status = CheckStatus::OK ,
662- .headers_to_set = UnsafeHeaderVector{{ " x-keep-empty " , " " } },
658+ .headers_to_set = UnsafeHeaderVector{},
663659 .status_code = Http::Code::OK ,
664660 .grpc_status = Grpc::Status::WellKnownGrpcStatus::Ok,
665661 };
@@ -672,8 +668,47 @@ TEST_F(ExtAuthzGrpcClientTest, AuthorizationOkWithKeepEmptyValueIgnored) {
672668 client_->onCreateInitialMetadata (headers);
673669
674670 EXPECT_CALL (span_, setTag (Eq (" ext_authz_status" ), Eq (" ext_authz_ok" )));
675- EXPECT_CALL (request_callbacks_, onComplete_ (WhenDynamicCastTo<ResponsePtr&>(
676- AuthzOkResponse (expected_authz_response))));
671+ EXPECT_CALL (request_callbacks_, onComplete_ (testing::_))
672+ .WillOnce (testing::Invoke ([&expected_authz_response](ResponsePtr& response) {
673+ EXPECT_TRUE (TestCommon::compareHeaderVector (response->headers_to_set ,
674+ expected_authz_response.headers_to_set ));
675+ }));
676+ client_->onSuccess (std::make_unique<envoy::service::auth::v3::CheckResponse>(check_response),
677+ span_);
678+ }
679+
680+ TEST_F (ExtAuthzGrpcClientTest, AuthorizationOkWithKeepEmptyValueTrue) {
681+ initialize ();
682+ envoy::service::auth::v3::CheckResponse check_response;
683+ TestUtility::loadFromYaml (R"EOF(
684+ status:
685+ code: 0
686+ ok_response:
687+ headers:
688+ - header:
689+ key: x-keep-empty
690+ value: ""
691+ keep_empty_value: true
692+ )EOF" ,
693+ check_response);
694+ // keep_empty_value is true and value is empty, so the header should be kept.
695+ auto expected_authz_response = Response{
696+ .status = CheckStatus::OK ,
697+ .headers_to_set = UnsafeHeaderVector{{" x-keep-empty" , " " }},
698+ .status_code = Http::Code::OK ,
699+ .grpc_status = Grpc::Status::WellKnownGrpcStatus::Ok,
700+ };
701+ envoy::service::auth::v3::CheckRequest request;
702+ expectCallSend (request);
703+ client_->check (request_callbacks_, request, Tracing::NullSpan::instance (), stream_info_);
704+ Http::TestRequestHeaderMapImpl headers;
705+ client_->onCreateInitialMetadata (headers);
706+ EXPECT_CALL (span_, setTag (Eq (" ext_authz_status" ), Eq (" ext_authz_ok" )));
707+ EXPECT_CALL (request_callbacks_, onComplete_ (testing::_))
708+ .WillOnce (testing::Invoke ([&expected_authz_response](ResponsePtr& response) {
709+ EXPECT_TRUE (TestCommon::compareHeaderVector (response->headers_to_set ,
710+ expected_authz_response.headers_to_set ));
711+ }));
677712 client_->onSuccess (std::make_unique<envoy::service::auth::v3::CheckResponse>(check_response),
678713 span_);
679714}
0 commit comments