4 Peertube signature tests:
5 https://github.com/Chocobozzz/PeerTube/blob/develop/server/tests/api/activitypub/helpers.ts
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");
18 (As2.PubKeyPem.pk_from_pem
("data/peertube.priv.pem", "data/peertube.pub.pem"))
19 (fun (_pub
, pk
) -> Lwt.return pk
)
22 j
= As2.json_from_file
"data/peertube.json"
25 let js k
= Ezjsonm.find j
[ "headers"; k
]
29 and da
= "Mon, 22 Oct 2018 13:34:22 GMT"
30 and di
= "SHA-256=FEr5j2WSSfdEMcG3NTOXuGU0lUchfTJx4+BtUlWOwDk="
31 and co
= "application/activity+json"
33 "oLKbgxdFXdXsHJ3x/UsG9Svu7oa8Dyqiy6Jif4wqNuhAqRVMRaG18f+dd2OcfFX3XRGF8p8flZkU6vvoEQBauTwGRGcgXAJuKC1zYIWGk+PeiW8lNUnE4qGapWcTiFnIo7FKauNdsgqg/tvgs1pQIdHkDDjZMI64twP7sTN/4vG1PCq+kyqi/DM+ORLi/W7vFuLVHt2Iz7ikfw/R3/mMtS4FwLops+tVYBQ2iQ9DVRhTwLKVbeL/LLVB/tdGzNZ4F4nImBAQQ9I7WpPM6J/k+cBmoEbrUKs8ptx9gbX3OSsl5wlvPVMNzU9F9yb2MrB/Y/J4qssKz+LbiaktKGj7OQ=="
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;
48 let h = Http.signed_headers
49 (As2.PubKeyPem.sign pk
)
50 (Uri.of_string
"http://localhost:3000/users/ronan2")
53 (Uri.of_string
"http://localhost:3000/accounts/ronan/inbox")
55 Header.get
h "signature"
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' ^
"\"")
64 Unix.chdir
"../../../test/";