func_http_main.cc 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <cstdint>
  6. #include <iostream>
  7. #include <string>
  8. #include <utility>
  9. #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
  10. #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
  11. #include "opentelemetry/nostd/shared_ptr.h"
  12. #include "opentelemetry/nostd/string_view.h"
  13. #include "opentelemetry/sdk/common/attribute_utils.h"
  14. #include "opentelemetry/sdk/common/global_log_handler.h"
  15. #include "opentelemetry/sdk/trace/exporter.h"
  16. #include "opentelemetry/sdk/trace/processor.h"
  17. #include "opentelemetry/sdk/trace/provider.h"
  18. #include "opentelemetry/sdk/trace/simple_processor_factory.h"
  19. #include "opentelemetry/sdk/trace/tracer_provider.h"
  20. #include "opentelemetry/sdk/trace/tracer_provider_factory.h"
  21. #include "opentelemetry/trace/provider.h"
  22. #include "opentelemetry/trace/span.h"
  23. #include "opentelemetry/trace/tracer.h"
  24. #include "opentelemetry/trace/tracer_provider.h"
  25. namespace trace = opentelemetry::trace;
  26. namespace trace_sdk = opentelemetry::sdk::trace;
  27. namespace otlp = opentelemetry::exporter::otlp;
  28. namespace nostd = opentelemetry::nostd;
  29. namespace internal_log = opentelemetry::sdk::common::internal_log;
  30. const int TEST_PASSED = 0;
  31. const int TEST_FAILED = 1;
  32. /*
  33. Command line parameters.
  34. */
  35. enum test_mode : std::uint8_t
  36. {
  37. MODE_NONE,
  38. MODE_HTTP,
  39. MODE_HTTPS
  40. };
  41. bool opt_help = false;
  42. bool opt_list = false;
  43. bool opt_debug = false;
  44. bool opt_secure = false;
  45. // HTTPS by default
  46. std::string opt_endpoint = "https://localhost:4318/v1/traces";
  47. std::string opt_cert_dir;
  48. std::string opt_test_name;
  49. test_mode opt_mode = MODE_NONE;
  50. /*
  51. Log parsing
  52. */
  53. struct TestResult
  54. {
  55. bool found_connection_failed = false;
  56. bool found_connection_refused = false;
  57. bool found_request_send_failure = false;
  58. bool found_export_error = false;
  59. bool found_export_success = false;
  60. bool found_unknown_min_tls = false;
  61. bool found_unknown_max_tls = false;
  62. void reset()
  63. {
  64. found_connection_failed = false;
  65. found_connection_refused = false;
  66. found_request_send_failure = false;
  67. found_export_error = false;
  68. found_export_success = false;
  69. found_unknown_min_tls = false;
  70. found_unknown_max_tls = false;
  71. }
  72. };
  73. struct TestResult g_test_result;
  74. void parse_error_msg(TestResult *result, const std::string &msg)
  75. {
  76. static std::string connection_failed("Session state: connection failed.");
  77. if (msg.find(connection_failed) != std::string::npos)
  78. {
  79. result->found_connection_failed = true;
  80. }
  81. static std::string connection_refused("Connection refused");
  82. if (msg.find(connection_refused) != std::string::npos)
  83. {
  84. result->found_connection_refused = true;
  85. }
  86. static std::string request_send_failed("Session state: request send failed.");
  87. if (msg.find(request_send_failed) != std::string::npos)
  88. {
  89. result->found_request_send_failure = true;
  90. }
  91. static std::string export_failed("ERROR: Export 1 trace span(s) error: 1");
  92. if (msg.find(export_failed) != std::string::npos)
  93. {
  94. result->found_export_error = true;
  95. }
  96. static std::string unknown_min_tls("Unknown min TLS version");
  97. if (msg.find(unknown_min_tls) != std::string::npos)
  98. {
  99. result->found_unknown_min_tls = true;
  100. }
  101. static std::string unknown_max_tls("Unknown max TLS version");
  102. if (msg.find(unknown_max_tls) != std::string::npos)
  103. {
  104. result->found_unknown_max_tls = true;
  105. }
  106. }
  107. void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {}
  108. void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {}
  109. void parse_debug_msg(TestResult *result, const std::string &msg)
  110. {
  111. static std::string export_success("Export 1 trace span(s) success");
  112. if (msg.find(export_success) != std::string::npos)
  113. {
  114. result->found_export_success = true;
  115. }
  116. }
  117. class TestLogHandler : public opentelemetry::sdk::common::internal_log::LogHandler
  118. {
  119. public:
  120. void Handle(opentelemetry::sdk::common::internal_log::LogLevel level,
  121. const char * /* file */,
  122. int /* line */,
  123. const char *msg,
  124. const opentelemetry::sdk::common::AttributeMap & /* attributes */) noexcept override
  125. {
  126. if (msg == nullptr)
  127. {
  128. msg = "<no msg>";
  129. }
  130. switch (level)
  131. {
  132. case opentelemetry::sdk::common::internal_log::LogLevel::None:
  133. break;
  134. case opentelemetry::sdk::common::internal_log::LogLevel::Error:
  135. std::cout << " - [E] " << msg << '\n';
  136. parse_error_msg(&g_test_result, msg);
  137. break;
  138. case opentelemetry::sdk::common::internal_log::LogLevel::Warning:
  139. std::cout << " - [W] " << msg << '\n';
  140. parse_warning_msg(&g_test_result, msg);
  141. break;
  142. case opentelemetry::sdk::common::internal_log::LogLevel::Info:
  143. std::cout << " - [I] " << msg << '\n';
  144. parse_info_msg(&g_test_result, msg);
  145. break;
  146. case opentelemetry::sdk::common::internal_log::LogLevel::Debug:
  147. std::cout << " - [D] " << msg << '\n';
  148. parse_debug_msg(&g_test_result, msg);
  149. break;
  150. }
  151. }
  152. };
  153. void init(const otlp::OtlpHttpExporterOptions &opts)
  154. {
  155. // Create OTLP exporter instance
  156. auto exporter = otlp::OtlpHttpExporterFactory::Create(opts);
  157. auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter));
  158. std::shared_ptr<opentelemetry::trace::TracerProvider> provider =
  159. trace_sdk::TracerProviderFactory::Create(std::move(processor));
  160. // Set the global trace provider
  161. trace_sdk::Provider::SetTracerProvider(provider);
  162. }
  163. void payload()
  164. {
  165. static const nostd::string_view k_tracer_name("func_test");
  166. static const nostd::string_view k_span_name("func_http_main");
  167. static const nostd::string_view k_attr_test_name("test_name");
  168. auto provider = trace::Provider::GetTracerProvider();
  169. auto tracer = provider->GetTracer(k_tracer_name, "1.0");
  170. auto span = tracer->StartSpan(k_span_name);
  171. span->SetAttribute(k_attr_test_name, opt_test_name);
  172. span->End();
  173. }
  174. void cleanup()
  175. {
  176. std::shared_ptr<opentelemetry::trace::TracerProvider> none;
  177. trace_sdk::Provider::SetTracerProvider(none);
  178. }
  179. void instrumented_payload(const otlp::OtlpHttpExporterOptions &opts)
  180. {
  181. g_test_result.reset();
  182. init(opts);
  183. payload();
  184. cleanup();
  185. }
  186. void usage(FILE *out)
  187. {
  188. static const char *msg =
  189. "Usage: func_otlp_http [options] test_name\n"
  190. "Valid options are:\n"
  191. " --help Print this help\n"
  192. " --list List test names\n"
  193. " --endpoint url OTLP HTTP endpoint (https://localhost:4318/v1/traces by default)\n"
  194. " --cert-dir dir Directory that contains test ssl certificates\n"
  195. " --mode mode Test server mode (used to verify expected results)\n"
  196. " - none: no endpoint\n"
  197. " - http: http endpoint\n"
  198. " - https: https endpoint\n";
  199. fprintf(out, "%s", msg);
  200. }
  201. int parse_args(int argc, char *argv[])
  202. {
  203. int remaining_argc = argc;
  204. char **remaining_argv = argv;
  205. while (remaining_argc > 0)
  206. {
  207. if (strcmp(*remaining_argv, "--help") == 0)
  208. {
  209. opt_help = true;
  210. return 0;
  211. }
  212. if (strcmp(*remaining_argv, "--list") == 0)
  213. {
  214. opt_list = true;
  215. return 0;
  216. }
  217. if (strcmp(*remaining_argv, "--debug") == 0)
  218. {
  219. opt_debug = true;
  220. remaining_argc--;
  221. remaining_argv++;
  222. continue;
  223. }
  224. if (remaining_argc >= 2)
  225. {
  226. if (strcmp(*remaining_argv, "--cert-dir") == 0)
  227. {
  228. remaining_argc--;
  229. remaining_argv++;
  230. opt_cert_dir = *remaining_argv;
  231. remaining_argc--;
  232. remaining_argv++;
  233. continue;
  234. }
  235. if (strcmp(*remaining_argv, "--endpoint") == 0)
  236. {
  237. remaining_argc--;
  238. remaining_argv++;
  239. opt_endpoint = *remaining_argv;
  240. remaining_argc--;
  241. remaining_argv++;
  242. continue;
  243. }
  244. if (strcmp(*remaining_argv, "--mode") == 0)
  245. {
  246. remaining_argc--;
  247. remaining_argv++;
  248. std::string mode = *remaining_argv;
  249. remaining_argc--;
  250. remaining_argv++;
  251. if (mode == "none")
  252. {
  253. opt_mode = MODE_NONE;
  254. }
  255. else if (mode == "http")
  256. {
  257. opt_mode = MODE_HTTP;
  258. }
  259. else if (mode == "https")
  260. {
  261. opt_mode = MODE_HTTPS;
  262. }
  263. else
  264. {
  265. // Unknown mode
  266. return 2;
  267. }
  268. continue;
  269. }
  270. }
  271. opt_test_name = *remaining_argv;
  272. remaining_argc--;
  273. remaining_argv++;
  274. if (remaining_argc)
  275. {
  276. // Unknown option
  277. return 1;
  278. }
  279. }
  280. return 0;
  281. }
  282. typedef int (*test_func_t)();
  283. struct test_case
  284. {
  285. std::string m_name;
  286. test_func_t m_func;
  287. };
  288. int test_basic();
  289. int test_cert_not_found();
  290. int test_cert_invalid();
  291. int test_cert_unreadable();
  292. int test_cert_ok();
  293. int test_client_cert_not_found();
  294. int test_client_cert_invalid();
  295. int test_client_cert_unreadable();
  296. int test_client_cert_no_key();
  297. int test_client_key_not_found();
  298. int test_client_key_invalid();
  299. int test_client_key_unreadable();
  300. int test_client_key_ok();
  301. int test_min_tls_unknown();
  302. int test_min_tls_10();
  303. int test_min_tls_11();
  304. int test_min_tls_12();
  305. int test_min_tls_13();
  306. int test_max_tls_unknown();
  307. int test_max_tls_10();
  308. int test_max_tls_11();
  309. int test_max_tls_12();
  310. int test_max_tls_13();
  311. int test_range_tls_10();
  312. int test_range_tls_11();
  313. int test_range_tls_12();
  314. int test_range_tls_13();
  315. int test_range_tls_10_11();
  316. int test_range_tls_10_12();
  317. int test_range_tls_10_13();
  318. int test_range_tls_11_10();
  319. int test_range_tls_11_12();
  320. int test_range_tls_11_13();
  321. int test_range_tls_12_10();
  322. int test_range_tls_12_11();
  323. int test_range_tls_12_13();
  324. int test_range_tls_13_10();
  325. int test_range_tls_13_11();
  326. int test_range_tls_13_12();
  327. int test_gzip_compression();
  328. static const test_case all_tests[] = {{"basic", test_basic},
  329. {"cert-not-found", test_cert_not_found},
  330. {"cert-invalid", test_cert_invalid},
  331. {"cert-unreadable", test_cert_unreadable},
  332. {"cert-ok", test_cert_ok},
  333. {"client-cert-not-found", test_client_cert_not_found},
  334. {"client-cert-invalid", test_client_cert_invalid},
  335. {"client-cert-unreadable", test_client_cert_unreadable},
  336. {"client-cert-no-key", test_client_cert_no_key},
  337. {"client-key-not-found", test_client_key_not_found},
  338. {"client-key-invalid", test_client_key_invalid},
  339. {"client-key-unreadable", test_client_key_unreadable},
  340. {"client-key-ok", test_client_key_ok},
  341. {"min-tls-unknown", test_min_tls_unknown},
  342. {"min-tls-10", test_min_tls_10},
  343. {"min-tls-11", test_min_tls_11},
  344. {"min-tls-12", test_min_tls_12},
  345. {"min-tls-13", test_min_tls_13},
  346. {"max-tls-unknown", test_max_tls_unknown},
  347. {"max-tls-10", test_max_tls_10},
  348. {"max-tls-11", test_max_tls_11},
  349. {"max-tls-12", test_max_tls_12},
  350. {"max-tls-13", test_max_tls_13},
  351. {"range-tls-10", test_range_tls_10},
  352. {"range-tls-11", test_range_tls_11},
  353. {"range-tls-12", test_range_tls_12},
  354. {"range-tls-13", test_range_tls_13},
  355. {"range-tls-10-11", test_range_tls_10_11},
  356. {"range-tls-10-12", test_range_tls_10_12},
  357. {"range-tls-10-13", test_range_tls_10_13},
  358. {"range-tls-11-10", test_range_tls_11_10},
  359. {"range-tls-11-12", test_range_tls_11_12},
  360. {"range-tls-11-13", test_range_tls_11_13},
  361. {"range-tls-12-10", test_range_tls_12_10},
  362. {"range-tls-12-11", test_range_tls_12_11},
  363. {"range-tls-12-13", test_range_tls_12_13},
  364. {"range-tls-13-10", test_range_tls_13_10},
  365. {"range-tls-13-11", test_range_tls_13_11},
  366. {"range-tls-13-12", test_range_tls_13_12},
  367. {"gzip-compression", test_gzip_compression},
  368. {"", nullptr}};
  369. void list_test_cases()
  370. {
  371. const test_case *current = all_tests;
  372. while (current->m_func != nullptr)
  373. {
  374. std::cout << current->m_name << '\n';
  375. current++;
  376. }
  377. }
  378. int run_test_case(const std::string &name)
  379. {
  380. const test_case *current = all_tests;
  381. while (current->m_func != nullptr)
  382. {
  383. if (current->m_name == name)
  384. {
  385. int rc = current->m_func();
  386. return rc;
  387. }
  388. current++;
  389. }
  390. std::cerr << "Unknown test <" << name << ">" << '\n';
  391. return 1;
  392. }
  393. int main(int argc, char *argv[])
  394. {
  395. // Program name
  396. argc--;
  397. argv++;
  398. int rc = parse_args(argc, argv);
  399. if (rc != 0)
  400. {
  401. usage(stderr);
  402. return 1;
  403. }
  404. if (opt_help)
  405. {
  406. usage(stdout);
  407. return 0;
  408. }
  409. if (opt_list)
  410. {
  411. list_test_cases();
  412. return 0;
  413. }
  414. if (opt_endpoint.find("https:") != std::string::npos)
  415. {
  416. opt_secure = true;
  417. }
  418. else
  419. {
  420. opt_secure = false;
  421. }
  422. opentelemetry::nostd::shared_ptr<internal_log::LogHandler> log_handler(new TestLogHandler);
  423. internal_log::GlobalLogHandler::SetLogHandler(log_handler);
  424. internal_log::GlobalLogHandler::SetLogLevel(internal_log::LogLevel::Debug);
  425. rc = run_test_case(opt_test_name);
  426. return rc;
  427. }
  428. void set_common_opts(otlp::OtlpHttpExporterOptions &opts)
  429. {
  430. opts.url = opt_endpoint;
  431. if (opt_debug)
  432. {
  433. opts.console_debug = true;
  434. }
  435. #ifdef ENABLE_ASYNC_EXPORT
  436. // Work around, ASYNC export not working.
  437. opts.max_concurrent_requests = 0;
  438. #endif
  439. }
  440. int expect_connection_failed()
  441. {
  442. if (g_test_result.found_export_error && g_test_result.found_connection_failed)
  443. {
  444. return TEST_PASSED;
  445. }
  446. return TEST_FAILED;
  447. }
  448. int expect_success()
  449. {
  450. if (g_test_result.found_export_success)
  451. {
  452. return TEST_PASSED;
  453. }
  454. return TEST_FAILED;
  455. }
  456. int expect_request_send_failed()
  457. {
  458. if (g_test_result.found_export_error && g_test_result.found_request_send_failure)
  459. {
  460. return TEST_PASSED;
  461. }
  462. return TEST_FAILED;
  463. }
  464. int expect_unknown_min_tls()
  465. {
  466. if (g_test_result.found_export_error && g_test_result.found_unknown_min_tls)
  467. {
  468. return TEST_PASSED;
  469. }
  470. return TEST_FAILED;
  471. }
  472. int expect_unknown_max_tls()
  473. {
  474. if (g_test_result.found_export_error && g_test_result.found_unknown_max_tls)
  475. {
  476. return TEST_PASSED;
  477. }
  478. return TEST_FAILED;
  479. }
  480. int expect_export_failed()
  481. {
  482. /*
  483. Can not test exact root cause:
  484. - connect failed ?
  485. - send request failed ?
  486. - exact error message ?
  487. so only verifying export failed.
  488. */
  489. if (g_test_result.found_export_error)
  490. {
  491. return TEST_PASSED;
  492. }
  493. return TEST_FAILED;
  494. }
  495. int test_basic()
  496. {
  497. otlp::OtlpHttpExporterOptions opts;
  498. set_common_opts(opts);
  499. instrumented_payload(opts);
  500. if (opt_mode == MODE_NONE)
  501. {
  502. return expect_connection_failed();
  503. }
  504. if (!opt_secure && (opt_mode == MODE_HTTP))
  505. {
  506. return expect_success();
  507. }
  508. if (!opt_secure && (opt_mode == MODE_HTTPS))
  509. {
  510. return expect_export_failed();
  511. }
  512. if (opt_secure && (opt_mode == MODE_HTTP))
  513. {
  514. return expect_connection_failed();
  515. }
  516. return expect_connection_failed();
  517. }
  518. int test_cert_not_found()
  519. {
  520. otlp::OtlpHttpExporterOptions opts;
  521. set_common_opts(opts);
  522. opts.ssl_ca_cert_path = opt_cert_dir + "/no-such-file.pem";
  523. instrumented_payload(opts);
  524. if (opt_mode == MODE_NONE)
  525. {
  526. return expect_connection_failed();
  527. }
  528. if (!opt_secure && (opt_mode == MODE_HTTP))
  529. {
  530. return expect_success();
  531. }
  532. if (!opt_secure && (opt_mode == MODE_HTTPS))
  533. {
  534. return expect_export_failed();
  535. }
  536. return expect_connection_failed();
  537. }
  538. int test_cert_invalid()
  539. {
  540. otlp::OtlpHttpExporterOptions opts;
  541. set_common_opts(opts);
  542. opts.ssl_ca_cert_path = opt_cert_dir + "/garbage.pem";
  543. instrumented_payload(opts);
  544. if (opt_mode == MODE_NONE)
  545. {
  546. return expect_connection_failed();
  547. }
  548. if (!opt_secure && (opt_mode == MODE_HTTP))
  549. {
  550. return expect_success();
  551. }
  552. if (!opt_secure && (opt_mode == MODE_HTTPS))
  553. {
  554. return expect_export_failed();
  555. }
  556. return expect_connection_failed();
  557. }
  558. int test_cert_unreadable()
  559. {
  560. otlp::OtlpHttpExporterOptions opts;
  561. set_common_opts(opts);
  562. opts.ssl_ca_cert_path = opt_cert_dir + "/unreadable.pem";
  563. instrumented_payload(opts);
  564. if (opt_mode == MODE_NONE)
  565. {
  566. return expect_connection_failed();
  567. }
  568. if (!opt_secure && (opt_mode == MODE_HTTP))
  569. {
  570. return expect_success();
  571. }
  572. if (!opt_secure && (opt_mode == MODE_HTTPS))
  573. {
  574. return expect_export_failed();
  575. }
  576. return expect_connection_failed();
  577. }
  578. int test_cert_ok()
  579. {
  580. otlp::OtlpHttpExporterOptions opts;
  581. set_common_opts(opts);
  582. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  583. instrumented_payload(opts);
  584. if (opt_mode == MODE_NONE)
  585. {
  586. return expect_connection_failed();
  587. }
  588. if (!opt_secure && (opt_mode == MODE_HTTP))
  589. {
  590. return expect_success();
  591. }
  592. if (!opt_secure && (opt_mode == MODE_HTTPS))
  593. {
  594. return expect_export_failed();
  595. }
  596. if (opt_secure && (opt_mode == MODE_HTTP))
  597. {
  598. return expect_connection_failed();
  599. }
  600. return expect_success();
  601. }
  602. int test_client_cert_not_found()
  603. {
  604. otlp::OtlpHttpExporterOptions opts;
  605. set_common_opts(opts);
  606. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  607. opts.ssl_client_cert_path = opt_cert_dir + "/no-such-file.pem";
  608. instrumented_payload(opts);
  609. if (opt_mode == MODE_NONE)
  610. {
  611. return expect_connection_failed();
  612. }
  613. if (!opt_secure && (opt_mode == MODE_HTTP))
  614. {
  615. return expect_success();
  616. }
  617. if (!opt_secure && (opt_mode == MODE_HTTPS))
  618. {
  619. return expect_export_failed();
  620. }
  621. return expect_connection_failed();
  622. }
  623. int test_client_cert_invalid()
  624. {
  625. otlp::OtlpHttpExporterOptions opts;
  626. set_common_opts(opts);
  627. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  628. opts.ssl_client_cert_path = opt_cert_dir + "/garbage.pem";
  629. instrumented_payload(opts);
  630. if (opt_mode == MODE_NONE)
  631. {
  632. return expect_connection_failed();
  633. }
  634. if (!opt_secure && (opt_mode == MODE_HTTP))
  635. {
  636. return expect_success();
  637. }
  638. if (!opt_secure && (opt_mode == MODE_HTTPS))
  639. {
  640. return expect_export_failed();
  641. }
  642. return expect_connection_failed();
  643. }
  644. int test_client_cert_unreadable()
  645. {
  646. otlp::OtlpHttpExporterOptions opts;
  647. set_common_opts(opts);
  648. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  649. opts.ssl_client_cert_path = opt_cert_dir + "/unreadable.pem";
  650. instrumented_payload(opts);
  651. if (opt_mode == MODE_NONE)
  652. {
  653. return expect_connection_failed();
  654. }
  655. if (!opt_secure && (opt_mode == MODE_HTTP))
  656. {
  657. return expect_success();
  658. }
  659. if (!opt_secure && (opt_mode == MODE_HTTPS))
  660. {
  661. return expect_export_failed();
  662. }
  663. return expect_connection_failed();
  664. }
  665. int test_client_cert_no_key()
  666. {
  667. otlp::OtlpHttpExporterOptions opts;
  668. set_common_opts(opts);
  669. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  670. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  671. instrumented_payload(opts);
  672. if (opt_mode == MODE_NONE)
  673. {
  674. return expect_connection_failed();
  675. }
  676. if (!opt_secure && (opt_mode == MODE_HTTP))
  677. {
  678. return expect_success();
  679. }
  680. if (!opt_secure && (opt_mode == MODE_HTTPS))
  681. {
  682. return expect_export_failed();
  683. }
  684. return expect_connection_failed();
  685. }
  686. int test_client_key_not_found()
  687. {
  688. otlp::OtlpHttpExporterOptions opts;
  689. set_common_opts(opts);
  690. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  691. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  692. opts.ssl_client_key_path = opt_cert_dir + "/no-such-file.pem";
  693. instrumented_payload(opts);
  694. if (opt_mode == MODE_NONE)
  695. {
  696. return expect_connection_failed();
  697. }
  698. if (!opt_secure && (opt_mode == MODE_HTTP))
  699. {
  700. return expect_success();
  701. }
  702. if (!opt_secure && (opt_mode == MODE_HTTPS))
  703. {
  704. return expect_export_failed();
  705. }
  706. return expect_connection_failed();
  707. }
  708. int test_client_key_invalid()
  709. {
  710. otlp::OtlpHttpExporterOptions opts;
  711. set_common_opts(opts);
  712. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  713. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  714. opts.ssl_client_key_path = opt_cert_dir + "/garbage.pem";
  715. instrumented_payload(opts);
  716. if (opt_mode == MODE_NONE)
  717. {
  718. return expect_connection_failed();
  719. }
  720. if (!opt_secure && (opt_mode == MODE_HTTP))
  721. {
  722. return expect_success();
  723. }
  724. if (!opt_secure && (opt_mode == MODE_HTTPS))
  725. {
  726. return expect_export_failed();
  727. }
  728. return expect_connection_failed();
  729. }
  730. int test_client_key_unreadable()
  731. {
  732. otlp::OtlpHttpExporterOptions opts;
  733. set_common_opts(opts);
  734. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  735. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  736. opts.ssl_client_key_path = opt_cert_dir + "/unreadable.pem";
  737. instrumented_payload(opts);
  738. if (opt_mode == MODE_NONE)
  739. {
  740. return expect_connection_failed();
  741. }
  742. if (!opt_secure && (opt_mode == MODE_HTTP))
  743. {
  744. return expect_success();
  745. }
  746. if (!opt_secure && (opt_mode == MODE_HTTPS))
  747. {
  748. return expect_export_failed();
  749. }
  750. return expect_connection_failed();
  751. }
  752. int test_client_key_ok()
  753. {
  754. otlp::OtlpHttpExporterOptions opts;
  755. set_common_opts(opts);
  756. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  757. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  758. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  759. instrumented_payload(opts);
  760. if (opt_mode == MODE_NONE)
  761. {
  762. return expect_connection_failed();
  763. }
  764. if (!opt_secure && (opt_mode == MODE_HTTP))
  765. {
  766. return expect_success();
  767. }
  768. if (!opt_secure && (opt_mode == MODE_HTTPS))
  769. {
  770. return expect_export_failed();
  771. }
  772. if (opt_secure && (opt_mode == MODE_HTTP))
  773. {
  774. return expect_connection_failed();
  775. }
  776. return expect_success();
  777. }
  778. int test_min_tls_unknown()
  779. {
  780. otlp::OtlpHttpExporterOptions opts;
  781. set_common_opts(opts);
  782. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  783. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  784. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  785. opts.ssl_min_tls = "99.99";
  786. instrumented_payload(opts);
  787. if (opt_mode == MODE_NONE)
  788. {
  789. return expect_connection_failed();
  790. }
  791. if (!opt_secure && (opt_mode == MODE_HTTP))
  792. {
  793. return expect_success();
  794. }
  795. if (!opt_secure && (opt_mode == MODE_HTTPS))
  796. {
  797. return expect_export_failed();
  798. }
  799. return expect_unknown_min_tls();
  800. }
  801. int test_min_tls_10()
  802. {
  803. otlp::OtlpHttpExporterOptions opts;
  804. set_common_opts(opts);
  805. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  806. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  807. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  808. opts.ssl_min_tls = "1.0";
  809. instrumented_payload(opts);
  810. if (opt_mode == MODE_NONE)
  811. {
  812. return expect_connection_failed();
  813. }
  814. if (!opt_secure && (opt_mode == MODE_HTTP))
  815. {
  816. return expect_success();
  817. }
  818. if (!opt_secure && (opt_mode == MODE_HTTPS))
  819. {
  820. return expect_export_failed();
  821. }
  822. if (opt_secure && (opt_mode == MODE_HTTP))
  823. {
  824. return expect_connection_failed();
  825. }
  826. return expect_unknown_min_tls();
  827. }
  828. int test_min_tls_11()
  829. {
  830. otlp::OtlpHttpExporterOptions opts;
  831. set_common_opts(opts);
  832. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  833. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  834. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  835. opts.ssl_min_tls = "1.1";
  836. instrumented_payload(opts);
  837. if (opt_mode == MODE_NONE)
  838. {
  839. return expect_connection_failed();
  840. }
  841. if (!opt_secure && (opt_mode == MODE_HTTP))
  842. {
  843. return expect_success();
  844. }
  845. if (!opt_secure && (opt_mode == MODE_HTTPS))
  846. {
  847. return expect_export_failed();
  848. }
  849. if (opt_secure && (opt_mode == MODE_HTTP))
  850. {
  851. return expect_connection_failed();
  852. }
  853. return expect_unknown_min_tls();
  854. }
  855. int test_min_tls_12()
  856. {
  857. otlp::OtlpHttpExporterOptions opts;
  858. set_common_opts(opts);
  859. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  860. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  861. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  862. opts.ssl_min_tls = "1.2";
  863. instrumented_payload(opts);
  864. if (opt_mode == MODE_NONE)
  865. {
  866. return expect_connection_failed();
  867. }
  868. if (!opt_secure && (opt_mode == MODE_HTTP))
  869. {
  870. return expect_success();
  871. }
  872. if (!opt_secure && (opt_mode == MODE_HTTPS))
  873. {
  874. return expect_export_failed();
  875. }
  876. if (opt_secure && (opt_mode == MODE_HTTP))
  877. {
  878. return expect_connection_failed();
  879. }
  880. return expect_success();
  881. }
  882. int test_min_tls_13()
  883. {
  884. otlp::OtlpHttpExporterOptions opts;
  885. set_common_opts(opts);
  886. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  887. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  888. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  889. opts.ssl_min_tls = "1.3";
  890. instrumented_payload(opts);
  891. if (opt_mode == MODE_NONE)
  892. {
  893. return expect_connection_failed();
  894. }
  895. if (!opt_secure && (opt_mode == MODE_HTTP))
  896. {
  897. return expect_success();
  898. }
  899. if (!opt_secure && (opt_mode == MODE_HTTPS))
  900. {
  901. return expect_export_failed();
  902. }
  903. if (opt_secure && (opt_mode == MODE_HTTP))
  904. {
  905. return expect_connection_failed();
  906. }
  907. return expect_success();
  908. }
  909. int test_max_tls_unknown()
  910. {
  911. otlp::OtlpHttpExporterOptions opts;
  912. set_common_opts(opts);
  913. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  914. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  915. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  916. opts.ssl_max_tls = "99.99";
  917. instrumented_payload(opts);
  918. if (opt_mode == MODE_NONE)
  919. {
  920. return expect_connection_failed();
  921. }
  922. if (!opt_secure && (opt_mode == MODE_HTTP))
  923. {
  924. return expect_success();
  925. }
  926. if (!opt_secure && (opt_mode == MODE_HTTPS))
  927. {
  928. return expect_export_failed();
  929. }
  930. return expect_unknown_max_tls();
  931. }
  932. int test_max_tls_10()
  933. {
  934. otlp::OtlpHttpExporterOptions opts;
  935. set_common_opts(opts);
  936. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  937. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  938. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  939. opts.ssl_max_tls = "1.0";
  940. instrumented_payload(opts);
  941. if (opt_mode == MODE_NONE)
  942. {
  943. return expect_connection_failed();
  944. }
  945. if (!opt_secure && (opt_mode == MODE_HTTP))
  946. {
  947. return expect_success();
  948. }
  949. if (!opt_secure && (opt_mode == MODE_HTTPS))
  950. {
  951. return expect_export_failed();
  952. }
  953. if (opt_secure && (opt_mode == MODE_HTTP))
  954. {
  955. return expect_export_failed();
  956. }
  957. // No support for TLS 1.0
  958. return expect_unknown_max_tls();
  959. }
  960. int test_max_tls_11()
  961. {
  962. otlp::OtlpHttpExporterOptions opts;
  963. set_common_opts(opts);
  964. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  965. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  966. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  967. opts.ssl_max_tls = "1.1";
  968. instrumented_payload(opts);
  969. if (opt_mode == MODE_NONE)
  970. {
  971. return expect_connection_failed();
  972. }
  973. if (!opt_secure && (opt_mode == MODE_HTTP))
  974. {
  975. return expect_success();
  976. }
  977. if (!opt_secure && (opt_mode == MODE_HTTPS))
  978. {
  979. return expect_export_failed();
  980. }
  981. if (opt_secure && (opt_mode == MODE_HTTP))
  982. {
  983. return expect_export_failed();
  984. }
  985. // No support for TLS 1.1
  986. return expect_unknown_max_tls();
  987. }
  988. int test_max_tls_12()
  989. {
  990. otlp::OtlpHttpExporterOptions opts;
  991. set_common_opts(opts);
  992. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  993. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  994. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  995. opts.ssl_max_tls = "1.2";
  996. instrumented_payload(opts);
  997. if (opt_mode == MODE_NONE)
  998. {
  999. return expect_connection_failed();
  1000. }
  1001. if (!opt_secure && (opt_mode == MODE_HTTP))
  1002. {
  1003. return expect_success();
  1004. }
  1005. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1006. {
  1007. return expect_export_failed();
  1008. }
  1009. if (opt_secure && (opt_mode == MODE_HTTP))
  1010. {
  1011. return expect_connection_failed();
  1012. }
  1013. return expect_success();
  1014. }
  1015. int test_max_tls_13()
  1016. {
  1017. otlp::OtlpHttpExporterOptions opts;
  1018. set_common_opts(opts);
  1019. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1020. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1021. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1022. opts.ssl_max_tls = "1.3";
  1023. instrumented_payload(opts);
  1024. if (opt_mode == MODE_NONE)
  1025. {
  1026. return expect_connection_failed();
  1027. }
  1028. if (!opt_secure && (opt_mode == MODE_HTTP))
  1029. {
  1030. return expect_success();
  1031. }
  1032. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1033. {
  1034. return expect_export_failed();
  1035. }
  1036. if (opt_secure && (opt_mode == MODE_HTTP))
  1037. {
  1038. return expect_connection_failed();
  1039. }
  1040. return expect_success();
  1041. }
  1042. int test_range_tls_10()
  1043. {
  1044. otlp::OtlpHttpExporterOptions opts;
  1045. set_common_opts(opts);
  1046. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1047. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1048. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1049. opts.ssl_min_tls = "1.0";
  1050. opts.ssl_max_tls = "1.0";
  1051. instrumented_payload(opts);
  1052. if (opt_mode == MODE_NONE)
  1053. {
  1054. return expect_connection_failed();
  1055. }
  1056. if (!opt_secure && (opt_mode == MODE_HTTP))
  1057. {
  1058. return expect_success();
  1059. }
  1060. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1061. {
  1062. return expect_export_failed();
  1063. }
  1064. if (opt_secure && (opt_mode == MODE_HTTP))
  1065. {
  1066. return expect_connection_failed();
  1067. }
  1068. // No support for TLS 1.0
  1069. return expect_unknown_min_tls();
  1070. }
  1071. int test_range_tls_11()
  1072. {
  1073. otlp::OtlpHttpExporterOptions opts;
  1074. set_common_opts(opts);
  1075. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1076. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1077. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1078. opts.ssl_min_tls = "1.1";
  1079. opts.ssl_max_tls = "1.1";
  1080. instrumented_payload(opts);
  1081. if (opt_mode == MODE_NONE)
  1082. {
  1083. return expect_connection_failed();
  1084. }
  1085. if (!opt_secure && (opt_mode == MODE_HTTP))
  1086. {
  1087. return expect_success();
  1088. }
  1089. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1090. {
  1091. return expect_export_failed();
  1092. }
  1093. if (opt_secure && (opt_mode == MODE_HTTP))
  1094. {
  1095. return expect_connection_failed();
  1096. }
  1097. // No support for TLS 1.0
  1098. return expect_unknown_min_tls();
  1099. }
  1100. int test_range_tls_12()
  1101. {
  1102. otlp::OtlpHttpExporterOptions opts;
  1103. set_common_opts(opts);
  1104. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1105. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1106. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1107. opts.ssl_min_tls = "1.2";
  1108. opts.ssl_max_tls = "1.2";
  1109. instrumented_payload(opts);
  1110. if (opt_mode == MODE_NONE)
  1111. {
  1112. return expect_connection_failed();
  1113. }
  1114. if (!opt_secure && (opt_mode == MODE_HTTP))
  1115. {
  1116. return expect_success();
  1117. }
  1118. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1119. {
  1120. return expect_export_failed();
  1121. }
  1122. if (opt_secure && (opt_mode == MODE_HTTP))
  1123. {
  1124. return expect_connection_failed();
  1125. }
  1126. return expect_success();
  1127. }
  1128. int test_range_tls_13()
  1129. {
  1130. otlp::OtlpHttpExporterOptions opts;
  1131. set_common_opts(opts);
  1132. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1133. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1134. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1135. opts.ssl_min_tls = "1.3";
  1136. opts.ssl_max_tls = "1.3";
  1137. instrumented_payload(opts);
  1138. if (opt_mode == MODE_NONE)
  1139. {
  1140. return expect_connection_failed();
  1141. }
  1142. if (!opt_secure && (opt_mode == MODE_HTTP))
  1143. {
  1144. return expect_success();
  1145. }
  1146. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1147. {
  1148. return expect_export_failed();
  1149. }
  1150. if (opt_secure && (opt_mode == MODE_HTTP))
  1151. {
  1152. return expect_connection_failed();
  1153. }
  1154. return expect_success();
  1155. }
  1156. int test_range_tls_10_11()
  1157. {
  1158. otlp::OtlpHttpExporterOptions opts;
  1159. set_common_opts(opts);
  1160. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1161. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1162. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1163. opts.ssl_min_tls = "1.0";
  1164. opts.ssl_max_tls = "1.1";
  1165. instrumented_payload(opts);
  1166. if (opt_mode == MODE_NONE)
  1167. {
  1168. return expect_connection_failed();
  1169. }
  1170. if (!opt_secure && (opt_mode == MODE_HTTP))
  1171. {
  1172. return expect_success();
  1173. }
  1174. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1175. {
  1176. return expect_export_failed();
  1177. }
  1178. if (opt_secure && (opt_mode == MODE_HTTP))
  1179. {
  1180. return expect_connection_failed();
  1181. }
  1182. // No support for TLS 1.0, TLS 1.1
  1183. return expect_unknown_min_tls();
  1184. }
  1185. int test_range_tls_10_12()
  1186. {
  1187. otlp::OtlpHttpExporterOptions opts;
  1188. set_common_opts(opts);
  1189. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1190. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1191. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1192. opts.ssl_min_tls = "1.0";
  1193. opts.ssl_max_tls = "1.2";
  1194. instrumented_payload(opts);
  1195. if (opt_mode == MODE_NONE)
  1196. {
  1197. return expect_connection_failed();
  1198. }
  1199. if (!opt_secure && (opt_mode == MODE_HTTP))
  1200. {
  1201. return expect_success();
  1202. }
  1203. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1204. {
  1205. return expect_export_failed();
  1206. }
  1207. if (opt_secure && (opt_mode == MODE_HTTP))
  1208. {
  1209. return expect_connection_failed();
  1210. }
  1211. return expect_unknown_min_tls();
  1212. }
  1213. int test_range_tls_10_13()
  1214. {
  1215. otlp::OtlpHttpExporterOptions opts;
  1216. set_common_opts(opts);
  1217. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1218. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1219. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1220. opts.ssl_min_tls = "1.0";
  1221. opts.ssl_max_tls = "1.3";
  1222. instrumented_payload(opts);
  1223. if (opt_mode == MODE_NONE)
  1224. {
  1225. return expect_connection_failed();
  1226. }
  1227. if (!opt_secure && (opt_mode == MODE_HTTP))
  1228. {
  1229. return expect_success();
  1230. }
  1231. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1232. {
  1233. return expect_export_failed();
  1234. }
  1235. if (opt_secure && (opt_mode == MODE_HTTP))
  1236. {
  1237. return expect_connection_failed();
  1238. }
  1239. return expect_unknown_min_tls();
  1240. }
  1241. int test_range_tls_11_10()
  1242. {
  1243. otlp::OtlpHttpExporterOptions opts;
  1244. set_common_opts(opts);
  1245. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1246. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1247. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1248. opts.ssl_min_tls = "1.1";
  1249. opts.ssl_max_tls = "1.0";
  1250. instrumented_payload(opts);
  1251. if (opt_mode == MODE_NONE)
  1252. {
  1253. return expect_connection_failed();
  1254. }
  1255. if (!opt_secure && (opt_mode == MODE_HTTP))
  1256. {
  1257. return expect_success();
  1258. }
  1259. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1260. {
  1261. return expect_export_failed();
  1262. }
  1263. // Impossible
  1264. return expect_connection_failed();
  1265. }
  1266. int test_range_tls_11_12()
  1267. {
  1268. otlp::OtlpHttpExporterOptions opts;
  1269. set_common_opts(opts);
  1270. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1271. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1272. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1273. opts.ssl_min_tls = "1.1";
  1274. opts.ssl_max_tls = "1.2";
  1275. instrumented_payload(opts);
  1276. if (opt_mode == MODE_NONE)
  1277. {
  1278. return expect_connection_failed();
  1279. }
  1280. if (!opt_secure && (opt_mode == MODE_HTTP))
  1281. {
  1282. return expect_success();
  1283. }
  1284. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1285. {
  1286. return expect_export_failed();
  1287. }
  1288. if (opt_secure && (opt_mode == MODE_HTTP))
  1289. {
  1290. return expect_connection_failed();
  1291. }
  1292. return expect_unknown_min_tls();
  1293. }
  1294. int test_range_tls_11_13()
  1295. {
  1296. otlp::OtlpHttpExporterOptions opts;
  1297. set_common_opts(opts);
  1298. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1299. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1300. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1301. opts.ssl_min_tls = "1.1";
  1302. opts.ssl_max_tls = "1.3";
  1303. instrumented_payload(opts);
  1304. if (opt_mode == MODE_NONE)
  1305. {
  1306. return expect_connection_failed();
  1307. }
  1308. if (!opt_secure && (opt_mode == MODE_HTTP))
  1309. {
  1310. return expect_success();
  1311. }
  1312. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1313. {
  1314. return expect_export_failed();
  1315. }
  1316. if (opt_secure && (opt_mode == MODE_HTTP))
  1317. {
  1318. return expect_connection_failed();
  1319. }
  1320. return expect_unknown_min_tls();
  1321. }
  1322. int test_range_tls_12_10()
  1323. {
  1324. otlp::OtlpHttpExporterOptions opts;
  1325. set_common_opts(opts);
  1326. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1327. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1328. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1329. opts.ssl_min_tls = "1.2";
  1330. opts.ssl_max_tls = "1.0";
  1331. instrumented_payload(opts);
  1332. if (opt_mode == MODE_NONE)
  1333. {
  1334. return expect_connection_failed();
  1335. }
  1336. if (!opt_secure && (opt_mode == MODE_HTTP))
  1337. {
  1338. return expect_success();
  1339. }
  1340. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1341. {
  1342. return expect_export_failed();
  1343. }
  1344. // Impossible
  1345. return expect_connection_failed();
  1346. }
  1347. int test_range_tls_12_11()
  1348. {
  1349. otlp::OtlpHttpExporterOptions opts;
  1350. set_common_opts(opts);
  1351. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1352. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1353. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1354. opts.ssl_min_tls = "1.2";
  1355. opts.ssl_max_tls = "1.1";
  1356. instrumented_payload(opts);
  1357. if (opt_mode == MODE_NONE)
  1358. {
  1359. return expect_connection_failed();
  1360. }
  1361. if (!opt_secure && (opt_mode == MODE_HTTP))
  1362. {
  1363. return expect_success();
  1364. }
  1365. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1366. {
  1367. return expect_export_failed();
  1368. }
  1369. // Impossible
  1370. return expect_connection_failed();
  1371. }
  1372. int test_range_tls_12_13()
  1373. {
  1374. otlp::OtlpHttpExporterOptions opts;
  1375. set_common_opts(opts);
  1376. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1377. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1378. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1379. opts.ssl_min_tls = "1.2";
  1380. opts.ssl_max_tls = "1.3";
  1381. instrumented_payload(opts);
  1382. if (opt_mode == MODE_NONE)
  1383. {
  1384. return expect_connection_failed();
  1385. }
  1386. if (!opt_secure && (opt_mode == MODE_HTTP))
  1387. {
  1388. return expect_success();
  1389. }
  1390. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1391. {
  1392. return expect_export_failed();
  1393. }
  1394. if (opt_secure && (opt_mode == MODE_HTTP))
  1395. {
  1396. return expect_connection_failed();
  1397. }
  1398. return expect_success();
  1399. }
  1400. int test_range_tls_13_10()
  1401. {
  1402. otlp::OtlpHttpExporterOptions opts;
  1403. set_common_opts(opts);
  1404. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1405. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1406. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1407. opts.ssl_min_tls = "1.3";
  1408. opts.ssl_max_tls = "1.0";
  1409. instrumented_payload(opts);
  1410. if (opt_mode == MODE_NONE)
  1411. {
  1412. return expect_connection_failed();
  1413. }
  1414. if (!opt_secure && (opt_mode == MODE_HTTP))
  1415. {
  1416. return expect_success();
  1417. }
  1418. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1419. {
  1420. return expect_export_failed();
  1421. }
  1422. // Impossible
  1423. return expect_connection_failed();
  1424. }
  1425. int test_range_tls_13_11()
  1426. {
  1427. otlp::OtlpHttpExporterOptions opts;
  1428. set_common_opts(opts);
  1429. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1430. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1431. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1432. opts.ssl_min_tls = "1.3";
  1433. opts.ssl_max_tls = "1.1";
  1434. instrumented_payload(opts);
  1435. if (opt_mode == MODE_NONE)
  1436. {
  1437. return expect_connection_failed();
  1438. }
  1439. if (!opt_secure && (opt_mode == MODE_HTTP))
  1440. {
  1441. return expect_success();
  1442. }
  1443. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1444. {
  1445. return expect_export_failed();
  1446. }
  1447. // Impossible
  1448. return expect_connection_failed();
  1449. }
  1450. int test_range_tls_13_12()
  1451. {
  1452. otlp::OtlpHttpExporterOptions opts;
  1453. set_common_opts(opts);
  1454. opts.ssl_ca_cert_path = opt_cert_dir + "/ca.pem";
  1455. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  1456. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  1457. opts.ssl_min_tls = "1.3";
  1458. opts.ssl_max_tls = "1.2";
  1459. instrumented_payload(opts);
  1460. if (opt_mode == MODE_NONE)
  1461. {
  1462. return expect_connection_failed();
  1463. }
  1464. if (!opt_secure && (opt_mode == MODE_HTTP))
  1465. {
  1466. return expect_success();
  1467. }
  1468. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1469. {
  1470. return expect_export_failed();
  1471. }
  1472. // Impossible
  1473. return expect_connection_failed();
  1474. }
  1475. int test_gzip_compression()
  1476. {
  1477. otlp::OtlpHttpExporterOptions opts;
  1478. set_common_opts(opts);
  1479. opts.compression = "gzip";
  1480. instrumented_payload(opts);
  1481. if (opt_mode == MODE_NONE)
  1482. {
  1483. return expect_connection_failed();
  1484. }
  1485. if (!opt_secure && (opt_mode == MODE_HTTP))
  1486. {
  1487. return expect_success();
  1488. }
  1489. if (!opt_secure && (opt_mode == MODE_HTTPS))
  1490. {
  1491. return expect_export_failed();
  1492. }
  1493. if (opt_secure && (opt_mode == MODE_HTTP))
  1494. {
  1495. return expect_connection_failed();
  1496. }
  1497. // Impossible
  1498. return expect_connection_failed();
  1499. }