Debian Codegraph @

tests/server_to_server_test.go

raw symbols SCIP
1 package tests
2
3 // Server to Server tests from: https://test.activitypub.rocks/
4
5 import (
6 "fmt"
7 "testing"
8
9 pub "github.com/go-ap/activitypub"
10 )
11
12 // S2S Server: Activities requiring the object property
13 // The distribution of the following activities require that they contain the object property:
14 // Create, Update, Delete, Follow, Add, Remove, Like, Block, Undo.
15 // Implementation always includes object property for each of the above supported activities
16 func TestObjectPropertyExists(t *testing.T) {
17 desc := `
18 S2S Server: Activities requiring the object property
19 The distribution of the following activities require that they contain the object property:
20 Create, Update, Delete, Follow, Add, Remove, Like, Block, Undo.
21
22 Implementation always includes object property for each of the above supported activities
23 `
24 t.Log(desc)
25
26 obj := pub.MentionNew("gigel")
27
28 add := pub.AddNew("https://localhost/myactivity", obj, nil)
29 if pub.IsNil(add.Object) {
30 t.Errorf("Missing GetID in Add activity %#v", add.Object)
31 }
32 if add.Object != obj {
33 t.Errorf("Add.GetID different than what we initialized %#v %#v", add.Object, obj)
34 }
35
36 block := pub.BlockNew("https://localhost/myactivity", obj)
37 if pub.IsNil(block.Object) {
38 t.Errorf("Missing GetID in Add activity %#v", block.Object)
39 }
40 if block.Object != obj {
41 t.Errorf("Block.GetID different than what we initialized %#v %#v", block.Object, obj)
42 }
43
44 create := pub.CreateNew("https://localhost/myactivity", obj)
45 if create.Object == nil {
46 t.Errorf("Missing GetID in Add activity %#v", create.Object)
47 }
48 if create.Object != obj {
49 t.Errorf("Create.GetID different than what we initialized %#v %#v", create.Object, obj)
50 }
51
52 delete := pub.DeleteNew("https://localhost/myactivity", obj)
53 if pub.IsNil(delete.Object) {
54 t.Errorf("Missing GetID in Delete activity %#v", delete.Object)
55 }
56 if delete.Object != obj {
57 t.Errorf("Delete.GetID different than what we initialized %#v %#v", delete.Object, obj)
58 }
59
60 follow := pub.FollowNew("https://localhost/myactivity", obj)
61 if pub.IsNil(follow.Object) {
62 t.Errorf("Missing GetID in Follow activity %#v", follow.Object)
63 }
64 if follow.Object != obj {
65 t.Errorf("Follow.GetID different than what we initialized %#v %#v", follow.Object, obj)
66 }
67
68 like := pub.LikeNew("https://localhost/myactivity", obj)
69 if pub.IsNil(like.Object) {
70 t.Errorf("Missing GetID in Like activity %#v", like.Object)
71 }
72 if like.Object != obj {
73 t.Errorf("Like.GetID different than what we initialized %#v %#v", add.Object, obj)
74 }
75
76 update := pub.UpdateNew("https://localhost/myactivity", obj)
77 if pub.IsNil(update.Object) {
78 t.Errorf("Missing GetID in Update activity %#v", update.Object)
79 }
80 if update.Object != obj {
81 t.Errorf("Update.GetID different than what we initialized %#v %#v", update.Object, obj)
82 }
83
84 undo := pub.UndoNew("https://localhost/myactivity", obj)
85 if undo.Object == nil {
86 t.Errorf("Missing GetID in Undo activity %#v", undo.Object)
87 }
88 if undo.Object != obj {
89 t.Errorf("Undo.GetID different than what we initialized %#v %#v", undo.Object, obj)
90 }
91 }
92
93 // S2S Server: Activities requiring the target property
94 // The distribution of the following activities require that they contain the target property:
95 // Add, Remove.
96 // Implementation always includes target property for each of the above supported activities.
97 func TestTargetPropertyExists(t *testing.T) {
98 desc := `
99 S2S Server: Activities requiring the target property
100 The distribution of the following activities require that they contain the target
101 property: Add, Remove.
102
103 Implementation always includes target property for each of the above supported activities.
104 `
105 t.Log(desc)
106
107 obj := pub.MentionNew("foo")
108 target := pub.MentionNew("bar")
109
110 add := pub.AddNew("https://localhost/myactivity", obj, target)
111 if pub.IsNil(add.Target) {
112 t.Errorf("Missing Target in Add activity %#v", add.Target)
113 }
114 if add.Target != target {
115 t.Errorf("Add.Target different than what we initialized %#v %#v", add.Target, target)
116 }
117
118 remove := pub.RemoveNew("https://localhost/myactivity", obj, target)
119 if pub.IsNil(remove.Target) {
120 t.Errorf("Missing Target in Remove activity %#v", remove.Target)
121 }
122 if remove.Target != target {
123 t.Errorf("Remove.Target different than what we initialized %#v %#v", remove.Target, target)
124 }
125 }
126
127 // S2S Server: Deduplication of recipient list
128 // Attempt to submit for delivery an activity that addresses the same actor
129 // (ie an actor with the same id) twice.
130 // (For example, the same actor could appear on both the to and cc fields,
131 // or the actor could be explicitly addressed
132 // in to but could also be a member of the addressed followers collection of the sending actor.)
133 // The server should deduplicate the list of inboxes to deliver to before delivering.
134 // The final recipient list is deduplicated before delivery.
135 func TestDeduplication(t *testing.T) {
136 desc := `
137 S2S Server: Deduplication of recipient list
138 Attempt to submit for delivery an activity that addresses the same actor
139 (ie an actor with the same id) twice.
140
141 The final recipient list is deduplicated before delivery.
142 `
143 t.Log(desc)
144
145 to := pub.PersonNew("bob")
146 o := pub.ObjectNew(pub.ArticleType)
147 cc := pub.PersonNew("alice")
148
149 o.ID = "something"
150 c := pub.CreateNew("create", o)
151 c.To.Append(to)
152 c.CC.Append(cc)
153 c.BCC.Append(cc)
154
155 c.Recipients()
156
157 checkDedup := func(list pub.ItemCollection, recIds *[]pub.ID) error {
158 for _, rec := range list {
159 for _, id := range *recIds {
160 if rec.GetID() == id {
161 return fmt.Errorf("%T[%s] already stored in recipients list, Deduplication faild", rec, id)
162 }
163 }
164 *recIds = append(*recIds, rec.GetID())
165 }
166 return nil
167 }
168
169 var err error
170 recIds := make([]pub.ID, 0)
171 err = checkDedup(c.To, &recIds)
172 if err != nil {
173 t.Error(err)
174 }
175 err = checkDedup(c.Bto, &recIds)
176 if err != nil {
177 t.Error(err)
178 }
179 err = checkDedup(c.CC, &recIds)
180 if err != nil {
181 t.Error(err)
182 }
183 err = checkDedup(c.BCC, &recIds)
184 if err != nil {
185 t.Error(err)
186 }
187 }
188
189 // S2S Server: Do-not-deliver considerations
190 // Server does not deliver to recipients which are the same as the actor of the
191 // Activity being notified about
192 func TestDoNotDeliverToActor(t *testing.T) {
193 desc := `
194 S2S Server: Do-not-deliver considerations
195
196 Server does not deliver to recipients which are the same as the actor of the
197 Activity being notified about
198 `
199 t.Skip(desc)
200
201 p := pub.PersonNew("main actor")
202
203 to := pub.PersonNew("bob")
204 o := pub.ObjectNew(pub.ArticleType)
205 cc := pub.PersonNew("alice")
206
207 o.ID = "something"
208 c := pub.CreateNew("create", o)
209 c.Actor = *p
210
211 _ = c.To.Append(p)
212 _ = c.To.Append(to)
213 _ = c.CC.Append(cc)
214 _ = c.CC.Append(p)
215 _ = c.BCC.Append(cc)
216 _ = c.BCC.Append(p)
217
218 recipients := c.Recipients()
219
220 checkActor := func(list pub.ItemCollection, actor pub.Item) error {
221 for _, rec := range list {
222 if rec.GetID() == actor.GetID() {
223 return fmt.Errorf("%T[%s] Actor of activity should not be in the recipients list", rec, actor.GetID())
224 }
225 }
226 return nil
227 }
228
229 var err error
230 err = checkActor(recipients, c.Actor)
231 if err != nil {
232 t.Error(err)
233 }
234 err = checkActor(c.To, c.Actor)
235 if err != nil {
236 t.Error(err)
237 }
238 err = checkActor(c.Bto, c.Actor)
239 if err != nil {
240 t.Error(err)
241 }
242 err = checkActor(c.CC, c.Actor)
243 if err != nil {
244 t.Error(err)
245 }
246 err = checkActor(c.BCC, c.Actor)
247 if err != nil {
248 t.Error(err)
249 }
250 }
251
252 // S2S Server: Do-not-deliver considerations
253 // Server does not deliver Block activities to their object.
254 func TestDoNotDeliverBlockToObject(t *testing.T) {
255 desc := `
256 S2S Server: Do-not-deliver considerations
257
258 Server does not deliver Block activities to their object.
259 `
260 t.Log(desc)
261
262 p := pub.PersonNew("blocked")
263
264 bob := pub.PersonNew("bob")
265 jane := pub.PersonNew("jane doe")
266
267 b := pub.BlockNew("block actor", p)
268 b.Actor = *bob
269
270 _ = b.To.Append(jane)
271 _ = b.To.Append(p)
272 _ = b.To.Append(bob)
273
274 recipients := b.Recipients()
275
276 checkActor := func(list pub.ItemCollection, ob pub.Item) error {
277 for _, rec := range list {
278 if rec.GetID() == ob.GetID() {
279 return fmt.Errorf("%T[%s] of activity should not be in the recipients list", rec, ob.GetID())
280 }
281 }
282 return nil
283 }
284
285 var err error
286 err = checkActor(recipients, b.Object)
287 if err != nil {
288 t.Error(err)
289 }
290 err = checkActor(b.To, b.Object)
291 if err != nil {
292 t.Error(err)
293 }
294 t.Skip("Checking for actor is no longer valid")
295 err = checkActor(b.To, b.Actor)
296 if err != nil {
297 t.Error(err)
298 }
299 }
300
301 // S2S Sever: Support for sharedInbox
302 // Delivers to sharedInbox endpoints to reduce the number of receiving actors delivered
303 // to by identifying all followers which share the same sharedInbox who would otherwise be
304 // individual recipients and instead deliver objects to said sharedInbox.
305 func TestSharedInboxIdentifySharedInbox(t *testing.T) {
306 desc := `
307 S2S Sever: Support for sharedInbox
308
309 Delivers to sharedInbox endpoints to reduce the number of receiving actors delivered
310 to by identifying all followers which share the same sharedInbox who would otherwise be
311 individual recipients and instead deliver objects to said sharedInbox.
312 `
313 t.Skip(desc)
314 }
315
316 // S2S Sever: Support for sharedInbox
317 // Deliver to actor inboxes and collections otherwise addressed which do not have a sharedInbox.
318 func TestSharedInboxActorsWOSharedInbox(t *testing.T) {
319 desc := `
320 S2S Server: Do-not-deliver considerations
321
322 Server does not deliver Block activities to their object.
323 `
324 t.Skip(desc)
325 }
326
327 // S2S Server: Deduplicating received activities
328 // Server deduplicates activities received in inbox by comparing activity ids
329 func TestInboxDeduplication(t *testing.T) {
330 desc := `
331 S2S Server: Deduplicating received activities
332
333 Server deduplicates activities received in inbox by comparing activity ids
334 `
335 t.Skip(desc)
336 }
337
338 // S2S Server: Special forwarding mechanism
339 // ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
340 // Forwards incoming activities to the values of to, bto, cc, bcc, audience if and only if criteria are met.
341 func TestForwardingMechanismsToRecipients(t *testing.T) {
342 desc := `
343 S2S Server: Special forwarding mechanism
344 ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
345
346 Forwards incoming activities to the values of to, bto, cc, bcc, audience if and only if criteria are met.
347 `
348 t.Skip(desc)
349 }
350
351 // S2S Server: Special forwarding mechanism
352 // ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
353 // Recurse through to, bto, cc, bcc, audience object values to determine whether/where
354 // to forward according to criteria in 7.1.2
355 func TestForwardingMechanismsRecurseRecipients(t *testing.T) {
356 desc := `
357 S2S Server: Special forwarding mechanism
358 ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
359
360 Recurse through to, bto, cc, bcc, audience object values to determine whether/where
361 to forward according to criteria in 7.1.2
362 `
363 t.Skip(desc)
364 }
365
366 // S2S Server: Special forwarding mechanism
367 // ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
368 // Limits depth of this recursion.
369 func TestForwardingMechanismsLimitsRecursion(t *testing.T) {
370 desc := `
371 S2S Server: Special forwarding mechanism
372 ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
373
374 Limits depth of this recursion.
375 `
376 t.Skip(desc)
377 }
378
379 // S2S Server: Verification of content authorship
380 // Before accepting activities delivered to an actor's inbox some sort of verification
381 // should be performed. (For example, if the delivering actor has a public key on their profile,
382 // the request delivering the activity may be signed with HTTP Signatures.)
383 // Don't trust content received from a server other than the content's origin without some form of verification.
384 func TestVerification(t *testing.T) {
385 desc := `
386 S2S Server: Verification of content authorship
387 Before accepting activities delivered to an actor's inbox some sort of verification
388 should be performed. (For example, if the delivering actor has a public key on their profile,
389 the request delivering the activity may be signed with HTTP Signatures.)
390
391 Don't trust content received from a server other than the content's origin without some form of verification.
392 `
393 t.Skip(desc)
394 }
395
396 // S2S Server: Update activity
397 // On receiving an Update activity to an actor's inbox, the server:
398 // Takes care to be sure that the Update is authorized to modify its object
399 func TestUpdateIsAuthorized(t *testing.T) {
400 desc := `
401 S2S Server: Update activity
402 On receiving an Update activity to an actor's inbox, the server:
403
404 Takes care to be sure that the Update is authorized to modify its object
405 `
406 t.Skip(desc)
407 }
408
409 // S2S Server: Update activity
410 // On receiving an Update activity to an actor's inbox, the server:
411 // Completely replaces its copy of the activity with the newly received value
412 func TestUpdateReplacesActivity(t *testing.T) {
413 desc := `
414 S2S Server: Update activity
415 On receiving an Update activity to an actor's inbox, the server:
416
417 Completely replaces its copy of the activity with the newly received value
418 `
419 t.Skip(desc)
420 }
421
422 // S2S Server: Delete activity
423 // Delete removes object's representation, assuming object is owned by sending actor/server
424 func TestDeleteRemoves(t *testing.T) {
425 desc := `
426 S2S Server: Delete activity
427
428 Delete removes object's representation, assuming object is owned by sending actor/server
429 `
430 t.Skip(desc)
431 }
432
433 // S2S Server: Delete activity
434 // Replaces deleted object with a Tombstone object (optional)
435 func TestDeleteReplacesWithTombstone(t *testing.T) {
436 desc := `
437 S2S Server: Delete activity
438
439 Replaces deleted object with a Tombstone object (optional)
440 `
441 t.Skip(desc)
442 }
443
444 // S2S Server: Following, and handling accept/reject of follows
445 // Follow should add the activity's actor to the receiving actor's Followers Collection.
446 func TestFollowAddsToFollowers(t *testing.T) {
447 desc := `
448 S2S Server: Following, and handling accept/reject of follows
449
450 Follow should add the activity's actor to the receiving actor's Followers Collection.
451 `
452 t.Skip(desc)
453 }
454
455 // S2S Server: Following, and handling accept/reject of follows
456 // Generates either an Accept or Reject activity with Follow as object and deliver to actor of the Follow
457 func TestGeneratesAcceptOrReject(t *testing.T) {
458 desc := `
459 S2S Server: Following, and handling accept/reject of follows
460
461 Generates either an Accept or Reject activity with Follow as object and deliver to actor of the Follow
462 `
463 t.Skip(desc)
464 }
465
466 // S2S Server: Following, and handling accept/reject of follows
467 // If receiving an Accept in reply to a Follow activity, adds actor to receiver's Following Collection
468 func TestAddsFollowerIfAccept(t *testing.T) {
469 desc := `
470 S2S Server: Following, and handling accept/reject of follows
471
472 If receiving an Accept in reply to a Follow activity, adds actor to receiver's Following Collection
473 `
474 t.Skip(desc)
475 }
476
477 // S2S Server: Following, and handling accept/reject of follows
478 // If receiving a Reject in reply to a Follow activity, does not add actor to receiver's Following Collection
479 func TestDoesntAddFollowerIfReject(t *testing.T) {
480 desc := `
481 S2S Server: Following, and handling accept/reject of follows
482
483 If receiving a Reject in reply to a Follow activity, does not add actor to receiver's Following Collection
484 `
485 t.Skip(desc)
486 }
487
488 // S2S Server: Activity acceptance side-effects
489 // Test accepting the following activities to an actor's inbox and observe the side effects:
490 //
491 // Create makes record of the object existing
492 func TestCreateMakesRecord(t *testing.T) {
493 desc := `
494 S2S Server: Activity acceptance side-effects
495 Test accepting the following activities to an actor's inbox and observe the side effects:
496
497 Create makes record of the object existing
498 `
499 t.Skip(desc)
500 }
501
502 // S2S Server: Activity acceptance side-effects
503 // Test accepting the following activities to an actor's inbox and observe the side effects:
504 //
505 // Add should add the activity's object to the Collection specified in the target property,
506 // unless not allowed per requirements
507 func TestAddObjectToTarget(t *testing.T) {
508 desc := `
509 S2S Server: Activity acceptance side-effects
510 Test accepting the following activities to an actor's inbox and observe the side effects:
511
512 Add should add the activity's object to the Collection specified in the target property,
513 unless not allowed per requirements
514 `
515 t.Skip(desc)
516 }
517
518 // S2S Server: Activity acceptance side-effects
519 // Test accepting the following activities to an actor's inbox and observe the side effects:
520 //
521 // Remove should remove the object from the Collection specified in the target property,
522 // unless not allowed per requirements
523 func TestRemoveObjectFromTarget(t *testing.T) {
524 desc := `
525 S2S Server: Activity acceptance side-effects
526 Test accepting the following activities to an actor's inbox and observe the side effects:
527
528 Remove should remove the object from the Collection specified in the target property,
529 unless not allowed per requirements
530 `
531 t.Skip(desc)
532 }
533
534 // S2S Server: Activity acceptance side-effects
535 // Test accepting the following activities to an actor's inbox and observe the side effects:
536 //
537 // Like increments the object's count of likes by adding the received activity to the likes
538 // collection if this collection is present
539 func TestLikeIncrementsLikes(t *testing.T) {
540 desc := `
541 S2S Server: Activity acceptance side-effects
542 Test accepting the following activities to an actor's inbox and observe the side effects:
543
544 Like increments the object's count of likes by adding the received activity to the likes
545 collection if this collection is present
546 `
547 t.Skip(desc)
548 }
549
550 // S2S Server: Activity acceptance side-effects
551 // Test accepting the following activities to an actor's inbox and observe the side effects:
552 //
553 // Announce increments object's count of shares by adding the received activity to the
554 // 'shares' collection if this collection is present
555 func TestAnnounceIncrementsShares(t *testing.T) {
556 desc := `
557 S2S Server: Activity acceptance side-effects
558 Test accepting the following activities to an actor's inbox and observe the side effects:
559
560 Announce increments object's count of shares by adding the received activity to the
561 'shares' collection if this collection is present
562 `
563 t.Skip(desc)
564 }
565
566 // S2S Server: Activity acceptance side-effects
567 // Test accepting the following activities to an actor's inbox and observe the side effects:
568 //
569 // Undo performs Undo of object in federated context
570 func TestUndoPerformsUndoOnObject(t *testing.T) {
571 desc := `
572 S2S Server: Activity acceptance side-effects
573 Test accepting the following activities to an actor's inbox and observe the side effects:
574
575 Undo performs Undo of object in federated context
576 `
577 t.Skip(desc)
578 }