This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,16 @@
; This library registers TLS-related command-line arguments if the tls library
; is available, otherwise it is an empty library. It would be more instructive
; to list it as an optional library where used, if possible.
(library
(name testlib_tls)
(library_flags (:standard -linkall))
(libraries
(select testlib_tls.ml from
(caqti
caqti-tls
cmdliner
ptime.clock.os
testlib
x509
-> testlib_tls.enabled.ml)
(-> testlib_tls.disabled.ml))))

View file

@ -0,0 +1 @@
(* Empty module used when TLS is unavailable. *)

View file

@ -0,0 +1,53 @@
(* Copyright (C) 2024 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the LGPL-3.0 Linking Exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* and the LGPL-3.0 Linking Exception along with this library. If not, see
* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
*)
open Testlib
let () =
let open Cmdliner in
let x509_authenticator_conv =
let parse spec =
X509.Authenticator.of_string spec
|> Result.map (fun f -> f (fun () -> Some (Ptime_clock.now ())))
in
let pp ppf _ = Format.pp_print_string ppf "<authenticator>" in
Arg.conv (parse, pp)
in
let x509_authenticator =
let doc =
"X509 authenticator for validating TLS connections when using the tls \
library. The input is parsed by X509.Authenticator.of_string"
in
let env = Cmd.Env.info "CAQTI_TEST_X509_AUTHENTICATOR" in
Arg.(value @@ opt (some x509_authenticator_conv) None @@
info ~doc ~env ["x509-authenticator"])
in
let process x509_authenticator common_args =
(match x509_authenticator with
| None -> common_args
| Some authenticator ->
let tls_client_config =
Result.get_ok (Tls.Config.client ~authenticator ())
in
let connect_config =
common_args.connect_config
|> Caqti_connect_config.set Caqti_tls.Config.client
(Some tls_client_config)
in
{common_args with connect_config})
in
Testlib.register_common_arg Term.(const process $ x509_authenticator)

View file

@ -0,0 +1,21 @@
(* Copyright (C) 2024 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the LGPL-3.0 Linking Exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* and the LGPL-3.0 Linking Exception along with this library. If not, see
* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
*)
(** TLS component for the internal test library
This library registers the command-line arguments needed to enable and set
up TLS-based encryption and authentication for pure-OCaml drivers. *)