Repository: envoyproxy/envoy
File: test/extensions/filters/http/jwt_authn/jwks_async_fetcher_test.cc (C++)

Code before:
    if (config_.has_async_fetch()) {
      // Param is for fast_listener,
      if (GetParam()) {
        config_.mutable_async_fetch()->set_fast_listener(true);
      }
    }

    if (initManagerUsed()) {
      EXPECT_CALL(context_.init_manager_, add(_))
          .WillOnce(Invoke([this](const Init::Target& target) {
            init_target_handle_ = target.createHandle("test");
          }));
    }

    // if async_fetch is enabled, timer is created
    if (config_.has_async_fetch()) {
      timer_ = new NiceMock<Event::MockTimer>(&context_.server_factory_context_.dispatcher_);
    }

    Router::RetryPolicyConstSharedPtr retry_policy = nullptr;
    if (config_.has_retry_policy()) {
      envoy::config::route::v3::RetryPolicy route_retry_policy =
          Http::Utility::convertCoreToRouteRetryPolicy(config_.retry_policy(),
                                                       "5xx,gateway-error,connect-failure,reset");
      // Use the null validation visitor because it used by the async client in the previous
      // implementation.
      auto policy_or_error = Router::RetryPolicyImpl::create(
          route_retry_policy, ProtobufMessage::getNullValidationVisitor(),
          context_.serverFactoryContext());
      THROW_IF_NOT_OK_REF(policy_or_error.status());
      retry_policy = std::move(policy_or_error.value());
    }

    async_fetcher_ = std::make_unique<JwksAsyncFetcher>(
        config_, std::move(retry_policy), context_,
        [this](Upstream::ClusterManager&, Router::RetryPolicyConstSharedPtr, const RemoteJwks&) {
          return std::make_unique<MockJwksFetcher>(
              [this](Common::JwksFetcher::JwksReceiver& receiver) {
                fetch_receiver_array_.push_back(&receiver);
              });
        },
        stats_,
        [this](google::jwt_verify::JwksPtr&& jwks) { out_jwks_array_.push_back(std::move(jwks)); });

    if (initManagerUsed()) {
      init_target_handle_->initialize(init_watcher_);
    }
  }

  RemoteJwks config_;
  JwksAsyncFetcherPtr async_fetcher_;

Review comment (suggestion):
```suggestion
      // Use the null validation visitor because it was used by the async client in the previous
      // implementation.
```

Code after:
    if (config_.has_async_fetch()) {
      // Param is for fast_listener,
      if (GetParam()) {
        config_.mutable_async_fetch()->set_fast_listener(true);
      }
    }

    if (initManagerUsed()) {
      EXPECT_CALL(context_.init_manager_, add(_))
          .WillOnce(Invoke([this](const Init::Target& target) {
            init_target_handle_ = target.createHandle("test");
          }));
    }

    // if async_fetch is enabled, timer is created
    if (config_.has_async_fetch()) {
      timer_ = new NiceMock<Event::MockTimer>(&context_.server_factory_context_.dispatcher_);
    }

    Router::RetryPolicyConstSharedPtr retry_policy = nullptr;
    if (config_.has_retry_policy()) {
      envoy::config::route::v3::RetryPolicy route_retry_policy =
          Http::Utility::convertCoreToRouteRetryPolicy(config_.retry_policy(),
                                                       "5xx,gateway-error,connect-failure,reset");
      // Use the null validation visitor because it was used by the async client in the previous
      // implementation.
      auto policy_or_error = Router::RetryPolicyImpl::create(
          route_retry_policy, ProtobufMessage::getNullValidationVisitor(),
          context_.serverFactoryContext());
      THROW_IF_NOT_OK_REF(policy_or_error.status());
      retry_policy = std::move(policy_or_error.value());
    }

    async_fetcher_ = std::make_unique<JwksAsyncFetcher>(
        config_, std::move(retry_policy), context_,
        [this](Upstream::ClusterManager&, Router::RetryPolicyConstSharedPtr, const RemoteJwks&) {
          return std::make_unique<MockJwksFetcher>(
              [this](Common::JwksFetcher::JwksReceiver& receiver) {
                fetch_receiver_array_.push_back(&receiver);
              });
        },
        stats_,
        [this](google::jwt_verify::JwksPtr&& jwks) { out_jwks_array_.push_back(std::move(jwks)); });

    if (initManagerUsed()) {
      init_target_handle_->initialize(init_watcher_);
    }
  }

  RemoteJwks config_;
  JwksAsyncFetcherPtr async_fetcher_;