Seppo.Social -> Seppo.mro.name
[Seppo.git] / test / t_peertube.ml
blob2c8acb70a2c723b14cda64a49a93f6bec55a20ce
1 open Seppo_lib
3 (*
4 Peertube signature tests:
5 https://github.com/Chocobozzz/PeerTube/blob/develop/server/tests/api/activitypub/helpers.ts
6 *)
8 (*
9 Keys from https://github.com/Chocobozzz/PeerTube/blob/develop/server/tests/fixtures/ap-json/peertube/keys.json
10 fixture from https://github.com/Chocobozzz/PeerTube/blob/develop/server/tests/fixtures/ap-json/mastodon/http-signature.json
11 Inbox https://github.com/Chocobozzz/PeerTube/blob/develop/server/tests/api/activitypub/helpers.ts#L151
13 let test_signature () =
14 Logr.info (fun m -> m "peertube.test.test_signature");
15 let
16 pk =
17 Lwt.bind
18 (As2.PubKeyPem.pk_from_pem ("data/peertube.priv.pem", "data/peertube.pub.pem"))
19 (fun (_pub, pk) -> Lwt.return pk)
20 |> Lwt_main.run
21 and
22 j = As2.json_from_file "data/peertube.json"
23 |> Result.get_ok
25 let js k = Ezjsonm.find j [ "headers"; k ]
26 |> Ezjsonm.get_string
27 and _rt = ""
28 and ho = "localhost"
29 and da = "Mon, 22 Oct 2018 13:34:22 GMT"
30 and di = "SHA-256=FEr5j2WSSfdEMcG3NTOXuGU0lUchfTJx4+BtUlWOwDk="
31 and co = "application/activity+json"
32 and si' =
33 "oLKbgxdFXdXsHJ3x/UsG9Svu7oa8Dyqiy6Jif4wqNuhAqRVMRaG18f+dd2OcfFX3XRGF8p8flZkU6vvoEQBauTwGRGcgXAJuKC1zYIWGk+PeiW8lNUnE4qGapWcTiFnIo7FKauNdsgqg/tvgs1pQIdHkDDjZMI64twP7sTN/4vG1PCq+kyqi/DM+ORLi/W7vFuLVHt2Iz7ikfw/R3/mMtS4FwLops+tVYBQ2iQ9DVRhTwLKVbeL/LLVB/tdGzNZ4F4nImBAQQ9I7WpPM6J/k+cBmoEbrUKs8ptx9gbX3OSsl5wlvPVMNzU9F9yb2MrB/Y/J4qssKz+LbiaktKGj7OQ=="
35 let si =
36 "keyId=\"http://localhost:3000/users/ronan2#main-key\",\
37 algorithm=\"rsa-sha256\",\
38 headers=\"(request-target) host date digest content-type\",\
39 signature=\"" ^ si' ^ "\""
40 and da',_,_ = Ptime.of_rfc3339 "2018-10-22T13:34:22+00:00" |> Result.get_ok in
41 js "host" |> Assrt.equals_string __LOC__ ho;
42 js "date" |> Assrt.equals_string __LOC__ da;
43 js "digest" |> Assrt.equals_string __LOC__ di;
44 js "content-type" |> Assrt.equals_string __LOC__ co;
45 js "signature" |> Assrt.equals_string __LOC__ si;
47 let open Cohttp in
48 let h = Http.signed_headers
49 (As2.PubKeyPem.sign pk)
50 (Uri.of_string "http://localhost:3000/users/ronan2")
51 da'
53 (Uri.of_string "http://localhost:3000/accounts/ronan/inbox")
55 Header.get h "signature"
56 |> Option.get
57 |> Assrt.equals_string ""
58 ("keyId=\"http://localhost:3000/users/ronan2#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target)
59 host date digest content-type\",signature=\"" ^ si' ^ "\"")
61 assert true
63 let () =
64 Unix.chdir "../../../test/";
65 test_signature ()