This commit is contained in:
parent
9e85fa2b2b
commit
f577e2dede
|
@ -14,9 +14,11 @@ depends: [
|
|||
"lwt"
|
||||
"bos"
|
||||
"mirage-crypto-rng"
|
||||
"alcotest" {with-test}
|
||||
]
|
||||
build: [
|
||||
["dune" "subst"] {pinned}
|
||||
["dune" "build" "-p" name "-j" jobs]
|
||||
["dune" "runtest" "-p" name "-j" jobs] {with-test}
|
||||
]
|
||||
synopsis: "ACME-like certificate signing service for shell servers"
|
||||
|
|
3
test/dune
Normal file
3
test/dune
Normal file
|
@ -0,0 +1,3 @@
|
|||
(test
|
||||
(name test)
|
||||
(libraries cert_service alcotest mirage-crypto-rng.unix))
|
44
test/test.ml
Normal file
44
test/test.ml
Normal file
|
@ -0,0 +1,44 @@
|
|||
let () = Mirage_crypto_rng_unix.initialize ()
|
||||
|
||||
let csr_privkey =
|
||||
lazy
|
||||
(`RSA (Mirage_crypto_pk.Rsa.generate ~bits:1024 ()))
|
||||
|
||||
let dn_of_name name =
|
||||
[X509.(Distinguished_name.Relative_distinguished_name.singleton
|
||||
(CN name))]
|
||||
|
||||
let csr name =
|
||||
X509.Signing_request.create
|
||||
(dn_of_name name)
|
||||
(Lazy.force csr_privkey)
|
||||
|
||||
let check_csr_dn_good () =
|
||||
let name = "reynir" in
|
||||
let csr = csr name in
|
||||
Alcotest.(check @@ result unit Alcotest.reject)
|
||||
"good dn in csr"
|
||||
(Ok ())
|
||||
(Cert_service.check_csr_dn
|
||||
csr name)
|
||||
|
||||
let check_csr_dn_different () =
|
||||
let name = "reynir" in
|
||||
let csr = csr name in
|
||||
match Cert_service.check_csr_dn csr "notreynir" with
|
||||
| Ok () -> Alcotest.fail "check succeeded, expected failure"
|
||||
| Error (`Msg _) -> ()
|
||||
|
||||
let cert_tests = [
|
||||
"check_csr_dn_good", `Quick, check_csr_dn_good;
|
||||
"check_csr_dn_different", `Quick, check_csr_dn_different;
|
||||
]
|
||||
|
||||
let tests : unit Alcotest.test list= [
|
||||
"check_csr_dn", cert_tests
|
||||
]
|
||||
|
||||
let () =
|
||||
Alcotest.run
|
||||
"Cert-service tests"
|
||||
tests
|
Loading…
Reference in a new issue