Skip to content

Commit

Permalink
[xds_client_fuzzer] ignore connection failures with OK status (grpc#3…
Browse files Browse the repository at this point in the history
…8619)

Closes grpc#38619

COPYBARA_INTEGRATE_REVIEW=grpc#38619 from markdroth:xds_client_fuzzer_fix 54c4f70
PiperOrigin-RevId: 721104015
  • Loading branch information
markdroth authored and copybara-github committed Jan 29, 2025
1 parent f512dcb commit 9a9e90a
Showing 1 changed file with 132 additions and 111 deletions.
243 changes: 132 additions & 111 deletions test/core/xds/xds_client_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class Fuzzer {

void TriggerConnectionFailure(const std::string& authority,
absl::Status status) {
if (status.ok()) return;
LOG(INFO) << "### TriggerConnectionFailure(" << authority
<< "): " << status;
const auto* xds_server = GetServer(authority);
Expand Down Expand Up @@ -347,85 +348,6 @@ class Fuzzer {
std::map<std::string, std::set<EndpointWatcher*>> endpoint_watchers_;
};

static const char* kBasicCluster = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions {
start_watch {
resource_type { cluster {} }
resource_name: "cluster1"
}
}
actions {
read_message_from_client {
stream_id { ads {} }
ok: true
}
}
actions {
send_message_to_client {
stream_id { ads {} }
response {
version_info: "1"
nonce: "A"
type_url: "type.googleapis.com/envoy.config.cluster.v3.Cluster"
resources {
[type.googleapis.com/envoy.config.cluster.v3.Cluster] {
name: "cluster1"
type: EDS
eds_cluster_config {
eds_config { ads {} }
service_name: "endpoint1"
}
}
}
}
}
}
)pb";

static const char* kBasicEndpoint = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions {
start_watch {
resource_type { endpoint {} }
resource_name: "endpoint1"
}
}
actions {
read_message_from_client {
stream_id { ads {} }
ok: true
}
}
actions {
send_message_to_client {
stream_id { ads {} }
response {
version_info: "1"
nonce: "A"
type_url: "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment"
resources {
[type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment] {
cluster_name: "endpoint1"
endpoints {
locality { region: "region1" zone: "zone1" sub_zone: "sub_zone1" }
load_balancing_weight { value: 1 }
lb_endpoints {
load_balancing_weight { value: 1 }
endpoint {
address {
socket_address { address: "127.0.0.1" port_value: 443 }
}
}
}
}
}
}
}
}
}
)pb";

static const char* kBasicListener = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions {
Expand Down Expand Up @@ -513,57 +435,85 @@ static const char* kBasicRouteConfig = R"pb(
}
)pb";

static const char* kBasicXdsServersEmpty = R"pb(
bootstrap: "{\"xds_servers\": []}"
static const char* kBasicCluster = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions {
start_watch {
resource_type { listener {} }
resource_name: "\003"
resource_type { cluster {} }
resource_name: "cluster1"
}
}
actions {
read_message_from_client {
stream_id { ads {} }
ok: true
}
}
)pb";

static const char* kResourceWrapperEmpty = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions { start_watch { resource_type { cluster {} } } }
actions {
send_message_to_client {
stream_id { ads {} }
response {
version_info: "envoy.config.cluster.v3.Cluster"
resources { type_url: "envoy.service.discovery.v3.Resource" }
canary: true
type_url: "envoy.config.cluster.v3.Cluster"
nonce: "envoy.config.cluster.v3.Cluster"
version_info: "1"
nonce: "A"
type_url: "type.googleapis.com/envoy.config.cluster.v3.Cluster"
resources {
[type.googleapis.com/envoy.config.cluster.v3.Cluster] {
name: "cluster1"
type: EDS
eds_cluster_config {
eds_config { ads {} }
service_name: "endpoint1"
}
}
}
}
}
}
)pb";

static const char* kRlsMissingTypedExtensionConfig = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:-257\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions { start_watch { resource_type { route_config {} } } }
static const char* kBasicEndpoint = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions {
start_watch {
resource_type { endpoint {} }
resource_name: "endpoint1"
}
}
actions {
read_message_from_client {
stream_id { ads {} }
ok: true
}
}
actions {
send_message_to_client {
stream_id { ads {} }
response {
version_info: "grpc.lookup.v1.RouteLookup"
version_info: "1"
nonce: "A"
type_url: "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment"
resources {
type_url: "envoy.config.route.v3.RouteConfiguration"
value: "\010\001b\000"
[type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment] {
cluster_name: "endpoint1"
endpoints {
locality { region: "region1" zone: "zone1" sub_zone: "sub_zone1" }
load_balancing_weight { value: 1 }
lb_endpoints {
load_balancing_weight { value: 1 }
endpoint {
address {
socket_address { address: "127.0.0.1" port_value: 443 }
}
}
}
}
}
}
type_url: "envoy.config.route.v3.RouteConfiguration"
nonce: "/@\001\000\\\000\000x141183468234106731687303715884105729"
}
}
}
)pb";

static const char* kSendMessageToClientBeforeStreamCreated = R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions { send_message_to_client { stream_id { ads {} } } }
)pb";

auto ParseTestProto(const std::string& proto) {
xds_client_fuzzer::Msg msg;
CHECK(google::protobuf::TextFormat::ParseFromString(proto, &msg));
Expand All @@ -579,10 +529,81 @@ void Fuzz(const xds_client_fuzzer::Msg& message) {
FUZZ_TEST(XdsClientFuzzer, Fuzz)
.WithDomains(::fuzztest::Arbitrary<xds_client_fuzzer::Msg>().WithSeeds(
{ParseTestProto(kBasicCluster), ParseTestProto(kBasicEndpoint),
ParseTestProto(kBasicListener), ParseTestProto(kBasicRouteConfig),
ParseTestProto(kBasicXdsServersEmpty),
ParseTestProto(kResourceWrapperEmpty),
ParseTestProto(kRlsMissingTypedExtensionConfig),
ParseTestProto(kSendMessageToClientBeforeStreamCreated)}));
ParseTestProto(kBasicListener), ParseTestProto(kBasicRouteConfig)}));

TEST(XdsClientFuzzer, XdsServersEmpty) {
Fuzz(ParseTestProto(R"pb(
bootstrap: "{\"xds_servers\": []}"
actions {
start_watch {
resource_type { listener {} }
resource_name: "\003"
}
}
)pb"));
}

TEST(XdsClientFuzzer, ResourceWrapperEmpty) {
Fuzz(ParseTestProto(R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions { start_watch { resource_type { cluster {} } } }
actions {
send_message_to_client {
stream_id { ads {} }
response {
version_info: "envoy.config.cluster.v3.Cluster"
resources { type_url: "envoy.service.discovery.v3.Resource" }
canary: true
type_url: "envoy.config.cluster.v3.Cluster"
nonce: "envoy.config.cluster.v3.Cluster"
}
}
}
)pb"));
}

TEST(XdsClientFuzzer, RlsMissingTypedExtensionConfig) {
Fuzz(ParseTestProto(R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:-257\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions { start_watch { resource_type { route_config {} } } }
actions {
send_message_to_client {
stream_id { ads {} }
response {
version_info: "grpc.lookup.v1.RouteLookup"
resources {
type_url: "envoy.config.route.v3.RouteConfiguration"
value: "\010\001b\000"
}
type_url: "envoy.config.route.v3.RouteConfiguration"
nonce: "/@\001\000\\\000\000x141183468234106731687303715884105729"
}
}
}
)pb"));
}

TEST(XdsClientFuzzer, SendMessageToClientBeforeStreamCreated) {
Fuzz(ParseTestProto(R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com:443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions { send_message_to_client { stream_id { ads {} } } }
)pb"));
}

TEST(XdsClientFuzzer, IgnoresConnectionFailuresWithOkStatus) {
Fuzz(ParseTestProto(R"pb(
bootstrap: "{\"xds_servers\": [{\"server_uri\":\"xds.example.com\320\272443\", \"channel_creds\":[{\"type\": \"fake\"}]}]}"
actions {
start_watch {
resource_type { cluster {} }
resource_name: "*"
}
}
actions {}
actions { trigger_connection_failure {} }
actions {}
fuzzing_event_engine_actions { connections { write_size: 2147483647 } }
)pb"));
}

} // namespace grpc_core

0 comments on commit 9a9e90a

Please sign in to comment.