3 * _| || |_/ ___| ___ _ __ _ __ ___ | |
4 * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
5 * |_ _|___) | __/ |_) | |_) | (_) |_|
6 * |_||_| |____/ \___| .__/| .__/ \___/(_)
13 * Copyright (C) The #Seppo contributors. All rights reserved.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 let test_uri_from_string () =
32 Logr.debug
(fun m
-> m
"%s.%s" "webfinger" "uri_from_string");
33 Uri.make ~scheme
:Rfc7565.scheme
34 ~userinfo
:"a:b/c" ~host
:"d.e" ()
36 |> Assrt.equals_string __LOC__
"acct://a:b%2Fc@d.e";
37 "mailto:demo@d.seppo.social"
40 |> Option.value ~default
:"-"
41 |> Assrt.equals_string __LOC__
"-";
44 |> Rfc7565.of_string
|> Result.get_ok
46 |> Assrt.equals_string __LOC__
"acct:ab/c@d.e";
48 |> Rfc7565.of_string
|> Result.get_ok
49 |> Webfinger.well_known_uri
51 |> Option.value ~default
:"-"
52 |> Assrt.equals_string __LOC__
"d.e";
54 |> Rfc7565.of_string
|> Result.get_ok
55 |> Webfinger.well_known_uri
57 |> Assrt.equals_string __LOC__
"https://d.e/.well-known/webfinger?resource=acct:ab/c@d.e";
58 "acct:demo@d.seppo.social"
59 |> Rfc7565.of_string
|> Result.get_ok
60 |> Webfinger.well_known_uri
62 |> Option.value ~default
:"-"
63 |> Assrt.equals_string __LOC__
"d.seppo.social";
65 |> Rfc7565.of_string
|> Result.get_ok
67 |> Assrt.equals_string __LOC__
"acct:a@b.c";
69 |> Rfc7565.of_string
|> Result.get_ok
71 |> Assrt.equals_string __LOC__
"acct:a@b.c";
74 |> Webfinger.Rfc7565.of_string_
75 |> Webfinger.Rfc7565.to_string
76 |> Assrt.equals_string __LOC__ "acct:a@b.c"
81 Logr.debug
(fun m
-> m
"%s.%s" "webfinger" "handle");
82 (match "uh@ah.oh" |> Rfc7565.of_string
with
83 | Ok acct
-> acct
|> Rfc7565.to_string
|> Assrt.equals_string __LOC__
"acct:uh@ah.oh"
84 | Error _
-> failwith __LOC__
91 |> Assrt.equals_string __LOC__
"acct:ok@example.com"
93 let test_webfinger () =
94 Logr.debug
(fun m
-> m
"webfinger");
95 Webfinger.jsonm
(Auth.Uid
"usr", Uri.of_string
"scheme://example.com/p/a/t/h/")
97 |> Ezjsonm.value_to_string ~minify
:false
98 |> Assrt.equals_string __LOC__
100 "subject": "acct:usr@example.com",
103 "href": "scheme://example.com/p/a/t/h/activitypub/actor.jsa",
105 "type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
108 "href": "scheme://example.com/p/a/t/h/",
109 "rel": "http://webfinger.net/rel/profile-page",
113 "href": "scheme://example.com/p/a/t/h/o/p/",
115 "type": "application/atom+xml"
118 "rel": "http://ostatus.org/schema/1.0/subscribe",
119 "template": "scheme://example.com/p/a/t/h/seppo.cgi/activitypub/actor.xml?id={uri}"
126 Logr.debug
(fun m
-> m
"webfinger_decode");
127 let j = "data/webfinger/gnusocial.json" |> File.in_channel
Ezjsonm.value_from_channel
in
128 let q = As2_vocab.Decode.Webfinger.query_result
j |> Result.get_ok
in
129 q.subject
|> Assrt.equals_string __LOC__
"acct:administrator@gnusocial.net";
130 As2_vocab.Encode.Webfinger.query_result ~base
:Uri.empty
q
131 |> Ezjsonm.value_to_string ~minify
:false
132 |> Assrt.equals_string __LOC__
{|{
133 "subject": "acct:administrator@gnusocial.net",
135 "https://gnusocial.net/index.php/user/1",
136 "https://gnusocial.net/administrator",
137 "https://gnusocial.net/user/1",
138 "https://gnusocial.net/index.php/administrator"
142 "href": "https://gnusocial.net/administrator",
143 "rel": "http://webfinger.net/rel/profile-page",
147 "rel": "http://ostatus.org/schema/1.0/subscribe",
148 "template": "https://gnusocial.net/main/remotefollowsub?profile={uri}"
151 "href": "https://gnusocial.net/index.php/user/1",
153 "type": "application/activity+json"
157 let j = "data/webfinger/pleroma.json" |> File.in_channel
Ezjsonm.value_from_channel
in
158 let q = j |> As2_vocab.Decode.Webfinger.query_result
|> Result.get_ok
in
159 q.subject
|> Assrt.equals_string __LOC__
"acct:gabek@social.gabekangas.com";
163 Logr.debug
(fun m
-> m
"webfinger_test.test_webfinger_sift");
164 let base = Uri.of_string
"https://example.com/sub/" in
165 let p = Webfinger.make
(Auth.Uid
"usr", base) in
167 |> As2_vocab.Types.Webfinger.profile_page
170 |> Assrt.equals_string __LOC__
".";
172 |> As2_vocab.Types.Webfinger.self_link
175 |> Assrt.equals_string __LOC__
"activitypub/actor.jsa";
177 |> As2_vocab.Encode.Webfinger.query_result ~
base
178 |> Ezjsonm.value_to_string ~minify
:false
179 |> Assrt.equals_string __LOC__
{|{
180 "subject": "acct:usr@example.com",
183 "href": "https://example.com/sub/activitypub/actor.jsa",
185 "type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
188 "href": "https://example.com/sub/",
189 "rel": "http://webfinger.net/rel/profile-page",
193 "href": "https://example.com/sub/o/p/",
195 "type": "application/atom+xml"
198 "rel": "http://ostatus.org/schema/1.0/subscribe",
199 "template": "https://example.com/sub/seppo.cgi/activitypub/actor.xml?id={uri}"
206 ("@actapopuli@fediverse.blog.json" ,"https://fediverse.blog/@/actapopuli/");
207 ("@administrator@gnusocial.net.json","https://gnusocial.net/index.php/user/1");
208 ("@btsavage@threads.net.json" ,"https://threads.net/ap/users/17841401679436667/");
209 ("@dansup@pixelfed.social.json" ,"https://pixelfed.social/users/dansup");
210 ("@demo@seppo.social.json" ,"https://seppo.social/demo/activitypub/actor.jsa");
211 ("@framasoft@mobilizon.fr.json" ,"https://mobilizon.fr/@framasoft");
212 ("@gargron@mastodon.social.json" ,"https://mastodon.social/users/Gargron");
213 ("@Greensky@open.audio.json" ,"https://open.audio/federation/actors/Greensky");
214 ("@kainoa@calckey.social.json" ,"https://calckey.social/users/9aprgabaeb");
215 ("@karolat@stereophonic.space.json" ,"https://stereophonic.space/users/karolat");
216 ("@lemmy_support@lemmy.ml.json" ,"https://lemmy.ml/c/lemmy_support");
217 ("@manton@manton.org.json" ,"https://manton.org/activitypub/manton");
218 ("@matt@write.as.json" ,"https://write.as/api/collections/matt");
219 ("@mike@macgirvin.com.json" ,"https://macgirvin.com/channel/mike");
220 ("@peertube@framapiaf.org.json" ,"https://framapiaf.org/users/peertube");
221 ("@syuilo@misskey.io.json" ,"https://misskey.io/users/7rkrarq81i");
222 ("@tobias@friendi.ca.json" ,"https://friendi.ca/author/tobias/");
223 ("atom.json" ,"https://example.com/activitypub/");
224 ("bonfire.json" ,"https://campground.bonfire.cafe/pub/actors/stpaultim");
225 ("gnusocial.json" ,"https://gnusocial.net/index.php/user/1");
226 ("mini.json" ,"https://example.com/activitypub/");
227 ("misskey.json" ,"https://misskey.io/users/7rkrarq81i");
228 ("pleroma.json" ,"https://social.gabekangas.com/users/gabek");
229 ("zap.json" ,"https://macgirvin.com/channel/mike");
231 let dir = "data/webfinger/" in
235 | "@contribute@hubzilla.org.json" -> false
236 | f
-> f
|> St.is_suffix ~affix
:".json"
239 |> File.in_channel
Ezjsonm.value_from_channel
240 |> As2_vocab.Decode.Webfinger.query_result
243 |> As2_vocab.Types.Webfinger.self_link
245 (* Logr.debug (fun m -> m {|%s.%s ("%s","%a");|} "Webfinger" "test_many" f Uri.pp a); *)
246 a |> Uri.to_string
|> Assrt.equals_string __LOC__
(List.assoc f
ex);
251 |> Assrt.equals_int __LOC__
(ex |> List.length
)
254 Unix.chdir
"../../../test/";
255 Printexc.record_backtrace
true;
256 test_uri_from_string ();