Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/test/config/utility.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <chrono>
4
#include <functional>
5
#include <string>
6
#include <vector>
7
8
#include "envoy/api/api.h"
9
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
10
#include "envoy/config/cluster/v3/cluster.pb.h"
11
#include "envoy/config/core/v3/base.pb.h"
12
#include "envoy/config/core/v3/proxy_protocol.pb.h"
13
#include "envoy/config/endpoint/v3/endpoint.pb.h"
14
#include "envoy/config/listener/v3/listener_components.pb.h"
15
#include "envoy/config/route/v3/route_components.pb.h"
16
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
17
#include "envoy/extensions/filters/udp/udp_proxy/v3/udp_proxy.pb.h"
18
#include "envoy/extensions/transport_sockets/tls/v3/cert.pb.h"
19
#include "envoy/extensions/transport_sockets/tls/v3/common.pb.h"
20
#include "envoy/extensions/upstreams/http/v3/http_protocol_options.pb.h"
21
#include "envoy/http/codes.h"
22
23
#include "source/common/config/api_version.h"
24
#include "source/common/network/address_impl.h"
25
#include "source/common/protobuf/protobuf.h"
26
#include "source/common/protobuf/utility.h"
27
28
#include "test/integration/server_stats.h"
29
30
#include "absl/types/optional.h"
31
32
namespace Envoy {
33
34
class ConfigHelper {
35
public:
36
  using HttpConnectionManager =
37
      envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager;
38
  using UdpProxyConfig = envoy::extensions::filters::udp::udp_proxy::v3::UdpProxyConfig;
39
40
  struct ServerSslOptions {
41
0
    ServerSslOptions& setAllowExpiredCertificate(bool allow) {
42
0
      allow_expired_certificate_ = allow;
43
0
      return *this;
44
0
    }
45
46
0
    ServerSslOptions& setRsaCert(bool rsa_cert) {
47
0
      rsa_cert_ = rsa_cert;
48
0
      return *this;
49
0
    }
50
51
0
    ServerSslOptions& setRsaCertOcspStaple(bool rsa_cert_ocsp_staple) {
52
0
      rsa_cert_ocsp_staple_ = rsa_cert_ocsp_staple;
53
0
      return *this;
54
0
    }
55
56
0
    ServerSslOptions& setEcdsaCert(bool ecdsa_cert) {
57
0
      ecdsa_cert_ = ecdsa_cert;
58
0
      return *this;
59
0
    }
60
61
0
    ServerSslOptions& setEcdsaCertOcspStaple(bool ecdsa_cert_ocsp_staple) {
62
0
      ecdsa_cert_ocsp_staple_ = ecdsa_cert_ocsp_staple;
63
0
      return *this;
64
0
    }
65
66
0
    ServerSslOptions& setOcspStapleRequired(bool ocsp_staple_required) {
67
0
      ocsp_staple_required_ = ocsp_staple_required;
68
0
      return *this;
69
0
    }
70
71
0
    ServerSslOptions& setTlsV13(bool tlsv1_3) {
72
0
      tlsv1_3_ = tlsv1_3;
73
0
      return *this;
74
0
    }
75
76
0
    ServerSslOptions& setPreferClientCiphers(bool prefer_client_ciphers) {
77
0
      prefer_client_ciphers_ = prefer_client_ciphers;
78
0
      return *this;
79
0
    }
80
81
0
    ServerSslOptions& setCiphers(const std::vector<std::string>& ciphers) {
82
0
      ciphers_ = ciphers;
83
0
      return *this;
84
0
    }
85
86
0
    ServerSslOptions& setCurves(const std::vector<std::string>& curves) {
87
0
      curves_ = curves;
88
0
      return *this;
89
0
    }
90
91
0
    ServerSslOptions& setExpectClientEcdsaCert(bool expect_client_ecdsa_cert) {
92
0
      expect_client_ecdsa_cert_ = expect_client_ecdsa_cert;
93
0
      return *this;
94
0
    }
95
96
    ServerSslOptions& setCustomValidatorConfig(
97
0
        envoy::config::core::v3::TypedExtensionConfig* custom_validator_config) {
98
0
      custom_validator_config_ = custom_validator_config;
99
0
      return *this;
100
0
    }
101
102
    ServerSslOptions&
103
    setSanMatchers(std::vector<envoy::extensions::transport_sockets::tls::v3::SubjectAltNameMatcher>
104
0
                       san_matchers) {
105
0
      san_matchers_ = san_matchers;
106
0
      return *this;
107
0
    }
108
109
0
    ServerSslOptions& setClientWithIntermediateCert(bool client_intermediate_cert) {
110
0
      client_with_intermediate_cert_ = client_intermediate_cert;
111
0
      return *this;
112
0
    }
113
114
0
    ServerSslOptions& setVerifyDepth(absl::optional<uint32_t> depth) {
115
0
      max_verify_depth_ = depth;
116
0
      return *this;
117
0
    }
118
119
    ServerSslOptions& setTlsKeyLogFilter(bool local, bool remote, bool local_negative,
120
                                         bool remote_negative, std::string log_path,
121
0
                                         bool multiple_ips, Network::Address::IpVersion version) {
122
0
      keylog_local_filter_ = local;
123
0
      keylog_remote_filter_ = remote;
124
0
      keylog_local_negative_ = local_negative;
125
0
      keylog_remote_negative_ = remote_negative;
126
0
      keylog_path_ = log_path;
127
0
      keylog_multiple_ips_ = multiple_ips;
128
0
      ip_version_ = version;
129
0
      return *this;
130
0
    }
131
132
0
    ServerSslOptions& setTrustRootOnly(bool trust_root_only) {
133
0
      trust_root_only_ = trust_root_only;
134
0
      return *this;
135
0
    }
136
137
0
    ServerSslOptions& setTlsCertSelector(std::string yaml) {
138
0
      tls_cert_selector_yaml_ = yaml;
139
0
      return *this;
140
0
    }
141
142
    bool allow_expired_certificate_{};
143
    envoy::config::core::v3::TypedExtensionConfig* custom_validator_config_{nullptr};
144
    bool rsa_cert_{true};
145
    bool rsa_cert_ocsp_staple_{true};
146
    bool ecdsa_cert_{false};
147
    bool ecdsa_cert_ocsp_staple_{false};
148
    bool prefer_client_ciphers_{false};
149
    bool ocsp_staple_required_{false};
150
    bool tlsv1_3_{false};
151
    std::vector<std::string> curves_;
152
    std::vector<std::string> ciphers_;
153
    bool expect_client_ecdsa_cert_{false};
154
    bool keylog_local_filter_{false};
155
    bool keylog_remote_filter_{false};
156
    bool keylog_local_negative_{false};
157
    bool keylog_remote_negative_{false};
158
    bool keylog_multiple_ips_{false};
159
    std::string keylog_path_;
160
    Network::Address::IpVersion ip_version_{Network::Address::IpVersion::v4};
161
    std::vector<envoy::extensions::transport_sockets::tls::v3::SubjectAltNameMatcher>
162
        san_matchers_{};
163
    std::string tls_cert_selector_yaml_{""};
164
    bool client_with_intermediate_cert_{false};
165
    bool trust_root_only_{false};
166
    absl::optional<uint32_t> max_verify_depth_{absl::nullopt};
167
  };
168
169
  // Sets up config with the provided bootstrap.
170
  ConfigHelper(const Network::Address::IpVersion version,
171
               const envoy::config::bootstrap::v3::Bootstrap& bootstrap);
172
173
  // Set up basic config, using the specified IpVersion for all connections: listeners, upstream,
174
  // and admin connections.
175
  //
176
  // By default, this runs with an L7 proxy config, but config can be set to TCP_PROXY_CONFIG
177
  // to test L4 proxying.
178
  ConfigHelper(const Network::Address::IpVersion version, Api::Api&,
179
               const std::string& config = httpProxyConfig(false, false));
180
181
  static void
182
  initializeTls(const ServerSslOptions& options,
183
                envoy::extensions::transport_sockets::tls::v3::CommonTlsContext& common_context,
184
                bool http3);
185
186
  static void initializeTlsKeyLog(
187
      envoy::extensions::transport_sockets::tls::v3::CommonTlsContext& common_tls_context,
188
      const ServerSslOptions& options);
189
  using ConfigModifierFunction = std::function<void(envoy::config::bootstrap::v3::Bootstrap&)>;
190
  using HttpModifierFunction = std::function<void(HttpConnectionManager&)>;
191
  using UdpProxyModifierFunction = std::function<void(UdpProxyConfig&)>;
192
193
  // A basic configuration (admin port, cluster_0, no listeners) with no network filters.
194
  static std::string baseConfigNoListeners();
195
196
  // A basic configuration (admin port, cluster_0, one listener) with no network filters.
197
  static std::string baseConfig(bool multiple_addresses = false);
198
199
  // A basic configuration (admin port, cluster_0, one udp listener) with no network filters.
200
  static std::string baseUdpListenerConfig(std::string listen_address = "0.0.0.0",
201
                                           bool multiple_addresses = false);
202
203
  // A string for a tls inspector listener filter which can be used with addListenerFilter()
204
  static std::string tlsInspectorFilter(bool enable_ja3_fingerprinting = false);
205
206
  // A string for the test inspector filter.
207
  static std::string testInspectorFilter();
208
209
  // A basic configuration for L4 proxying.
210
  static std::string tcpProxyConfig();
211
  // A basic configuration for L7 proxying.
212
  static std::string httpProxyConfig(bool downstream_use_quic = false,
213
                                     bool multiple_addresses = false);
214
  // A basic configuration for L7 proxying with QUIC transport.
215
  static std::string quicHttpProxyConfig(bool multiple_addresses = false);
216
  // A string for a basic buffer filter, which can be used with prependFilter()
217
  static std::string defaultBufferFilter();
218
  // A string for a small buffer filter, which can be used with prependFilter()
219
  static std::string smallBufferFilter();
220
  // A string for a health check filter which can be used with prependFilter()
221
  static std::string defaultHealthCheckFilter();
222
  // A string for a squash filter which can be used with prependFilter()
223
  static std::string defaultSquashFilter();
224
  // A string for startTls transport socket config.
225
  static std::string startTlsConfig();
226
  // A cluster that uses the startTls transport socket.
227
  static envoy::config::cluster::v3::Cluster buildStartTlsCluster(const std::string& address,
228
                                                                  int port);
229
230
  // Configuration for L7 proxying, with clusters cluster_1 and cluster_2 meant to be added via CDS.
231
  // api_type should be REST, GRPC, or DELTA_GRPC.
232
  static std::string discoveredClustersBootstrap(const std::string& api_type);
233
  // Configuration for L7 proxying, with clusters cluster_1 and cluster_2 meant to be added via CDS.
234
  // but there are no listeners.
235
  static std::string clustersNoListenerBootstrap(const std::string& api_type);
236
  static std::string adsBootstrap(const std::string& api_type);
237
  // Builds a standard Cluster config fragment, with a single endpoint (at address:port).
238
  static envoy::config::cluster::v3::Cluster
239
  buildStaticCluster(const std::string& name, int port, const std::string& address,
240
                     const envoy::config::cluster::v3::Cluster::LbPolicy lb_policy =
241
                         envoy::config::cluster::v3::Cluster::ROUND_ROBIN);
242
243
  static envoy::config::cluster::v3::Cluster buildH1ClusterWithHighCircuitBreakersLimits(
244
      const std::string& name, int port, const std::string& address,
245
      const envoy::config::cluster::v3::Cluster::LbPolicy lb_policy);
246
247
  // ADS configurations
248
  static envoy::config::cluster::v3::Cluster
249
  buildCluster(const std::string& name,
250
               const envoy::config::cluster::v3::Cluster::LbPolicy lb_policy =
251
                   envoy::config::cluster::v3::Cluster::ROUND_ROBIN);
252
253
  static envoy::config::cluster::v3::Cluster
254
  buildTlsCluster(const std::string& name,
255
                  const envoy::config::cluster::v3::Cluster::LbPolicy lb_policy =
256
                      envoy::config::cluster::v3::Cluster::ROUND_ROBIN);
257
258
  static envoy::config::endpoint::v3::ClusterLoadAssignment
259
  buildClusterLoadAssignment(const std::string& name, const std::string& ip_version, uint32_t port);
260
261
  static envoy::config::endpoint::v3::ClusterLoadAssignment
262
  buildClusterLoadAssignmentWithLeds(const std::string& name,
263
                                     const std::string& leds_collection_name);
264
265
  static envoy::config::endpoint::v3::LbEndpoint buildLbEndpoint(const std::string& address,
266
                                                                 uint32_t port);
267
268
  static envoy::config::listener::v3::Listener
269
  buildBaseListener(const std::string& name, const std::string& address,
270
                    const std::string& filter_chains = "");
271
272
  static envoy::config::listener::v3::Listener buildListener(const std::string& name,
273
                                                             const std::string& route_config,
274
                                                             const std::string& address,
275
                                                             const std::string& stat_prefix);
276
277
  static envoy::config::route::v3::RouteConfiguration buildRouteConfig(const std::string& name,
278
                                                                       const std::string& cluster);
279
280
  // Builds a standard Endpoint suitable for population by finalize().
281
  static envoy::config::endpoint::v3::Endpoint buildEndpoint(const std::string& address);
282
283
  // Run the final config modifiers, and then set the upstream ports based on upstream connections.
284
  // This is the last operation run on |bootstrap_| before it is handed to Envoy.
285
  // Ports are assigned by looping through clusters, hosts, and addresses in the
286
  // order they are stored in |bootstrap_|
287
  void finalize(const std::vector<uint32_t>& ports);
288
289
  // Called by finalize to set up the ports.
290
  void setPorts(const std::vector<uint32_t>& ports, bool override_port_zero = false);
291
292
  // Set source_address in the bootstrap bind config.
293
  void setSourceAddress(const std::string& address_string);
294
295
  // Overwrite the first host and route for the primary listener.
296
  void setDefaultHostAndRoute(const std::string& host, const std::string& route);
297
298
  // Sets byte limits on upstream and downstream connections.
299
  void setBufferLimits(uint32_t upstream_buffer_limit, uint32_t downstream_buffer_limit);
300
301
  // Sets a small kernel buffer for the listener send buffer
302
  void setListenerSendBufLimits(uint32_t limit);
303
304
  // Set the idle timeout on downstream connections through the HttpConnectionManager.
305
  void setDownstreamHttpIdleTimeout(std::chrono::milliseconds idle_timeout);
306
307
  // Set the max connection duration for downstream connections through the HttpConnectionManager.
308
  void setDownstreamMaxConnectionDuration(std::chrono::milliseconds max_connection_duration);
309
310
  // Set the max stream duration for downstream connections through the HttpConnectionManager.
311
  void setDownstreamMaxStreamDuration(std::chrono::milliseconds max_stream_duration);
312
313
  // Set the connect timeout on upstream connections.
314
  void setConnectTimeout(std::chrono::milliseconds timeout);
315
316
  // Disable delay close. This is especially useful for tests doing raw TCP for
317
  // HTTP/1.1 which functionally frame by connection close.
318
  void disableDelayClose();
319
320
  // Set the max_requests_per_connection for downstream through the HttpConnectionManager.
321
  void setDownstreamMaxRequestsPerConnection(uint64_t max_requests_per_connection);
322
323
  envoy::config::route::v3::VirtualHost createVirtualHost(const char* host, const char* route = "/",
324
                                                          const char* cluster = "cluster_0");
325
326
  void addVirtualHost(const envoy::config::route::v3::VirtualHost& vhost);
327
328
  // Add an HTTP filter prior to existing filters.
329
  // By default, this prepends a downstream HTTP filter, but if downstream is set to
330
  // false it will prepend an upstream HTTP filter.
331
  void prependFilter(const std::string& filter_yaml, bool downstream = true);
332
333
  // Add an HTTP filter prior to existing filters.
334
  // TODO(rgs1): remove once envoy-filter-example has been updated.
335
  void addFilter(const std::string& filter_yaml);
336
337
  // Add a network filter prior to existing filters.
338
  void addNetworkFilter(const std::string& filter_yaml);
339
340
  // Add a listener filter prior to existing filters.
341
  void addListenerFilter(const std::string& filter_yaml);
342
343
  // Add a new bootstrap extension.
344
  void addBootstrapExtension(const std::string& config);
345
346
  // Sets the client codec to the specified type.
347
  void setClientCodec(envoy::extensions::filters::network::http_connection_manager::v3::
348
                          HttpConnectionManager::CodecType type);
349
350
  // Add TLS configuration for either SSL or QUIC transport socket according to listener config.
351
  void configDownstreamTransportSocketWithTls(
352
      envoy::config::bootstrap::v3::Bootstrap& bootstrap,
353
      std::function<void(envoy::extensions::transport_sockets::tls::v3::CommonTlsContext&)>
354
          configure_tls_context,
355
      bool enable_quic_early_data = true);
356
357
  // Add the default SSL configuration.
358
  void addSslConfig(const ServerSslOptions& options);
359
0
  void addSslConfig() { addSslConfig({}); }
360
361
  // Add the default SSL configuration for QUIC downstream.
362
  void addQuicDownstreamTransportSocketConfig(bool enable_early_data,
363
                                              std::vector<absl::string_view> custom_alpns);
364
365
  // Set the HTTP access log for the first HCM (if present) to a given file. The default is
366
  // the platform's null device.
367
  bool setAccessLog(const std::string& filename, absl::string_view format = "",
368
                    std::vector<envoy::config::core::v3::TypedExtensionConfig> formatters = {});
369
370
  // Set the listener access log for the first listener to a given file.
371
  bool setListenerAccessLog(const std::string& filename, absl::string_view format = "");
372
373
  // Renames the first listener to the name specified.
374
  void renameListener(const std::string& name);
375
376
  // Allows callers to do their own modification to |bootstrap_| which will be
377
  // applied just before ports are modified in finalize().
378
  void addConfigModifier(ConfigModifierFunction function);
379
380
  // Allows callers to easily modify the HttpConnectionManager configuration.
381
  // Modifiers will be applied just before ports are modified in finalize
382
  void addConfigModifier(HttpModifierFunction function);
383
384
  // Allows callers to easily modify the UDP Proxy configuration.
385
  // Modifiers will be applied just before ports are modified in finalize
386
  void addConfigModifier(UdpProxyModifierFunction function);
387
388
  // Allows callers to easily modify the filter named 'name' from the first filter chain from the
389
  // first listener. Modifiers will be applied just before ports are modified in finalize
390
  template <class FilterType>
391
  void addFilterConfigModifier(const std::string& name,
392
                               std::function<void(Protobuf::Message& filter)> function) {
393
    addConfigModifier([name, function, this](envoy::config::bootstrap::v3::Bootstrap&) -> void {
394
      FilterType filter_config;
395
      loadFilter<FilterType>(name, filter_config);
396
      function(filter_config);
397
      storeFilter<FilterType>(name, filter_config);
398
    });
399
  }
400
401
  // Apply any outstanding config modifiers, stick all the listeners in a discovery response message
402
  // and write it to the lds file.
403
  void setLds(absl::string_view version_info);
404
405
  // Set limits on pending downstream outbound frames.
406
  void setDownstreamOutboundFramesLimits(uint32_t max_all_frames, uint32_t max_control_frames);
407
408
  // Set limits on pending upstream outbound frames.
409
  void setUpstreamOutboundFramesLimits(uint32_t max_all_frames, uint32_t max_control_frames);
410
411
  // Return the bootstrap configuration for hand-off to Envoy.
412
13.7k
  const envoy::config::bootstrap::v3::Bootstrap& bootstrap() { return bootstrap_; }
413
414
  // Allow a finalized configuration to be edited for generating xDS responses
415
  void applyConfigModifiers();
416
417
  // Configure Envoy to do TLS to upstream.
418
  void configureUpstreamTls(
419
      bool use_alpn = false, bool http3 = false,
420
      absl::optional<envoy::config::core::v3::AlternateProtocolsCacheOptions>
421
          alternate_protocol_cache_config = {},
422
      std::function<void(envoy::extensions::transport_sockets::tls::v3::CommonTlsContext&)>
423
          configure_tls_context = nullptr);
424
425
  // Skip validation that ensures that all upstream ports are referenced by the
426
  // configuration generated in ConfigHelper::finalize.
427
0
  void skipPortUsageValidation() { skip_port_usage_validation_ = true; }
428
429
  // Add this key value pair to the static runtime.
430
  void addRuntimeOverride(absl::string_view key, absl::string_view value);
431
432
  // Add typed_filter_metadata to the first listener.
433
  void addListenerTypedMetadata(absl::string_view key, ProtobufWkt::Any& packed_value);
434
435
  // Add filter_metadata to a cluster with the given name
436
  void addClusterFilterMetadata(absl::string_view metadata_yaml,
437
                                absl::string_view cluster_name = "cluster_0");
438
439
  // Given an HCM with the default config, set the matcher to be a connect matcher and enable
440
  // CONNECT requests.
441
  static void setConnectConfig(HttpConnectionManager& hcm, bool terminate_connect, bool allow_post,
442
                               bool http3 = false,
443
                               absl::optional<envoy::config::core::v3::ProxyProtocolConfig::Version>
444
                                   proxy_protocol_version = absl::nullopt);
445
  // Given an HCM with the default config, set the matcher to be a connect matcher and enable
446
  // CONNECT-UDP requests.
447
  static void setConnectUdpConfig(HttpConnectionManager& hcm, bool terminate_connect,
448
                                  bool http3 = false);
449
450
  void setLocalReply(
451
      const envoy::extensions::filters::network::http_connection_manager::v3::LocalReplyConfig&
452
          config);
453
454
  // Adjust the upstream route with larger timeout if running tsan. This is the duration between
455
  // whole request being processed and whole response received.
456
  static void adjustUpstreamTimeoutForTsan(
457
      envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager& hcm);
458
459
  using HttpProtocolOptions = envoy::extensions::upstreams::http::v3::HttpProtocolOptions;
460
  static void setProtocolOptions(envoy::config::cluster::v3::Cluster& cluster,
461
                                 HttpProtocolOptions& protocol_options);
462
  static void setHttp2(envoy::config::cluster::v3::Cluster& cluster);
463
464
  // Populate and return a Http3ProtocolOptions instance based on http2_options.
465
  static envoy::config::core::v3::Http3ProtocolOptions
466
  http2ToHttp3ProtocolOptions(const envoy::config::core::v3::Http2ProtocolOptions& http2_options,
467
                              size_t http3_max_stream_receive_window);
468
  // Load the first HCM struct from the first listener into a parsed proto.
469
  bool loadHttpConnectionManager(HttpConnectionManager& hcm);
470
  // Take the contents of the provided HCM proto and stuff them into the first HCM
471
  // struct of the first listener.
472
  void storeHttpConnectionManager(const HttpConnectionManager& hcm);
473
  // Load the first UDP Proxy from the first listener into a parsed proto.
474
  bool loadUdpProxyFilter(UdpProxyConfig& udp_proxy);
475
  // Take the contents of the provided UDP Proxy and stuff them into the first HCM
476
  // struct of the first listener.
477
  void storeUdpProxyFilter(const UdpProxyConfig& udp_proxy);
478
479
private:
480
  // Load the first FilterType struct from the first listener into a parsed proto.
481
5.04k
  template <class FilterType> bool loadFilter(const std::string& name, FilterType& filter) {
482
5.04k
    RELEASE_ASSERT(!finalized_, "");
483
5.04k
    auto* filter_config = getFilterFromListener(name);
484
5.04k
    if (filter_config) {
485
5.02k
      auto* config = filter_config->mutable_typed_config();
486
5.02k
      filter = MessageUtil::anyConvert<FilterType>(*config);
487
5.02k
      return true;
488
5.02k
    }
489
14
    return false;
490
5.04k
  }
491
  // Take the contents of the provided FilterType proto and stuff them into the first FilterType
492
  // struct of the first listener.
493
5.02k
  template <class FilterType> void storeFilter(const std::string& name, const FilterType& filter) {
494
5.02k
    RELEASE_ASSERT(!finalized_, "");
495
5.02k
    auto* filter_config_any = getFilterFromListener(name)->mutable_typed_config();
496
497
5.02k
    filter_config_any->PackFrom(filter);
498
5.02k
  }
499
500
  // Load the first FilterType struct from the first listener filters into a parsed proto.
501
0
  template <class FilterType> bool loadListenerFilter(const std::string& name, FilterType& filter) {
502
0
    RELEASE_ASSERT(!finalized_, "");
503
0
    auto* filter_config = getListenerFilterFromListener(name);
504
0
    if (filter_config) {
505
0
      auto* config = filter_config->mutable_typed_config();
506
0
      filter = MessageUtil::anyConvert<FilterType>(*config);
507
0
      return true;
508
0
    }
509
0
    return false;
510
0
  }
511
512
  // Take the contents of the provided FilterType proto and stuff them into the first FilterType
513
  // struct of the first listener.
514
  template <class FilterType>
515
0
  void storeListenerFilter(const std::string& name, const FilterType& filter) {
516
0
    RELEASE_ASSERT(!finalized_, "");
517
0
    auto* filter_config_any = getListenerFilterFromListener(name)->mutable_typed_config();
518
519
0
    filter_config_any->PackFrom(filter);
520
0
  }
521
522
  // Finds the filter named 'name' from the first filter chain from the first listener.
523
  envoy::config::listener::v3::Filter* getFilterFromListener(const std::string& name);
524
525
  // Finds the filter named 'name' from the first listener filter from the first listener.
526
  envoy::config::listener::v3::ListenerFilter*
527
  getListenerFilterFromListener(const std::string& name);
528
529
  // The bootstrap proto Envoy will start up with.
530
  envoy::config::bootstrap::v3::Bootstrap bootstrap_;
531
532
  // The config modifiers added via addConfigModifier() which will be applied in finalize()
533
  std::vector<ConfigModifierFunction> config_modifiers_;
534
535
  // Track if the connect timeout has been set (to avoid clobbering a custom setting with the
536
  // default).
537
  bool connect_timeout_set_{false};
538
539
  // Option to disable port usage validation for cases where the number of
540
  // upstream ports created is expected to be larger than the number of
541
  // upstreams in the config.
542
  bool skip_port_usage_validation_{false};
543
544
  // A sanity check guard to make sure config is not modified after handing it to Envoy.
545
  bool finalized_{false};
546
};
547
548
class CdsHelper {
549
public:
550
  CdsHelper();
551
552
  // Set CDS contents on filesystem.
553
  void setCds(const std::vector<envoy::config::cluster::v3::Cluster>& cluster);
554
0
  const std::string& cdsPath() const { return cds_path_; }
555
556
private:
557
  const std::string cds_path_;
558
  uint32_t cds_version_{};
559
};
560
561
// Common code for tests that deliver EDS update via the filesystem.
562
class EdsHelper {
563
public:
564
  EdsHelper();
565
566
  // Set EDS contents on filesystem and wait for Envoy to pick this up.
567
  void setEds(const std::vector<envoy::config::endpoint::v3::ClusterLoadAssignment>&
568
                  cluster_load_assignments);
569
  void setEdsAndWait(const std::vector<envoy::config::endpoint::v3::ClusterLoadAssignment>&
570
                         cluster_load_assignments,
571
                     IntegrationTestServerStats& server_stats);
572
0
  const std::string& edsPath() const { return eds_path_; }
573
574
private:
575
  const std::string eds_path_;
576
  uint32_t eds_version_{};
577
  uint32_t update_successes_{};
578
};
579
580
} // namespace Envoy