1
#include "tests/cilium_tls_integration.h"
2

            
3
#include <gmock/gmock-actions.h>
4
#include <gmock/gmock-spec-builders.h>
5

            
6
#include <string>
7
#include <utility>
8

            
9
#include "envoy/api/api.h"
10
#include "envoy/common/exception.h"
11
#include "envoy/extensions/transport_sockets/tls/v3/tls.pb.h"
12
#include "envoy/network/transport_socket.h"
13
#include "envoy/ssl/context_manager.h"
14

            
15
#include "source/common/tls/client_ssl_socket.h"
16
#include "source/common/tls/context_config_impl.h"
17

            
18
#include "test/integration/server.h"
19
#include "test/mocks/server/admin.h"
20
#include "test/mocks/server/server_factory_context.h"
21
#include "test/test_common/environment.h"
22
#include "test/test_common/utility.h"
23

            
24
namespace Envoy {
25
namespace Cilium {
26

            
27
Network::UpstreamTransportSocketFactoryPtr
28
12
createClientSslTransportSocketFactory(Ssl::ContextManager& context_manager, Api::Api& api) {
29
12
  std::string yaml_plain = R"EOF(
30
12
  common_tls_context:
31
12
    validation_context:
32
12
      trusted_ca:
33
12
        filename: "{{ test_rundir }}/test/config/integration/certs/cacert.pem"
34
12
)EOF";
35

            
36
12
  envoy::extensions::transport_sockets::tls::v3::UpstreamTlsContext tls_context;
37
12
  TestUtility::loadFromYaml(TestEnvironment::substitute(yaml_plain), tls_context);
38

            
39
12
  NiceMock<Server::Configuration::MockTransportSocketFactoryContext> mock_factory_ctx;
40
12
  ON_CALL(mock_factory_ctx.server_context_, api()).WillByDefault(testing::ReturnRef(api));
41
12
  auto cfg_or_error = Extensions::TransportSockets::Tls::ClientContextConfigImpl::create(
42
12
      tls_context, mock_factory_ctx);
43
  // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
44
12
  THROW_IF_NOT_OK(cfg_or_error.status());
45
12
  auto cfg = std::move(cfg_or_error.value());
46
12
  static auto* client_stats_store = new Stats::TestIsolatedStoreImpl();
47
12
  auto factory_or_error = Extensions::TransportSockets::Tls::ClientSslSocketFactory::create(
48
12
      std::move(cfg), context_manager, *client_stats_store->rootScope());
49
  // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
50
12
  THROW_IF_NOT_OK(factory_or_error.status());
51
12
  return std::move(factory_or_error.value());
52
12
}
53

            
54
} // namespace Cilium
55
} // namespace Envoy