File: server_to_server_test.go

package info (click to toggle)
golang-github-go-ap-activitypub 0.0~git20250501.71edba4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 920 kB
  • sloc: makefile: 26
file content (569 lines) | stat: -rw-r--r-- 18,443 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
package tests

// Server to Server tests from: https://test.activitypub.rocks/

import (
	"fmt"
	"testing"

	pub "github.com/go-ap/activitypub"
)

// S2S Server: Activities requiring the object property
// The distribution of the following activities require that they contain the object property:
// Create, Update, Delete, Follow, Add, Remove, Like, Block, Undo.
// Implementation always includes object property for each of the above supported activities
func TestObjectPropertyExists(t *testing.T) {
	desc := `
S2S Server: Activities requiring the object property
  The distribution of the following activities require that they contain the object property:
   Create, Update, Delete, Follow, Add, Remove, Like, Block, Undo.

  Implementation always includes object property for each of the above supported activities
`
	t.Log(desc)

	obj := pub.MentionNew("gigel")

	add := pub.AddNew("https://localhost/myactivity", obj, nil)
	if pub.IsNil(add.Object) {
		t.Errorf("Missing GetID in Add activity %#v", add.Object)
	}
	if add.Object != obj {
		t.Errorf("Add.GetID different than what we initialized %#v %#v", add.Object, obj)
	}

	block := pub.BlockNew("https://localhost/myactivity", obj)
	if pub.IsNil(block.Object) {
		t.Errorf("Missing GetID in Add activity %#v", block.Object)
	}
	if block.Object != obj {
		t.Errorf("Block.GetID different than what we initialized %#v %#v", block.Object, obj)
	}

	create := pub.CreateNew("https://localhost/myactivity", obj)
	if create.Object == nil {
		t.Errorf("Missing GetID in Add activity %#v", create.Object)
	}
	if create.Object != obj {
		t.Errorf("Create.GetID different than what we initialized %#v %#v", create.Object, obj)
	}

	delete := pub.DeleteNew("https://localhost/myactivity", obj)
	if pub.IsNil(delete.Object) {
		t.Errorf("Missing GetID in Delete activity %#v", delete.Object)
	}
	if delete.Object != obj {
		t.Errorf("Delete.GetID different than what we initialized %#v %#v", delete.Object, obj)
	}

	follow := pub.FollowNew("https://localhost/myactivity", obj)
	if pub.IsNil(follow.Object) {
		t.Errorf("Missing GetID in Follow activity %#v", follow.Object)
	}
	if follow.Object != obj {
		t.Errorf("Follow.GetID different than what we initialized %#v %#v", follow.Object, obj)
	}

	like := pub.LikeNew("https://localhost/myactivity", obj)
	if pub.IsNil(like.Object) {
		t.Errorf("Missing GetID in Like activity %#v", like.Object)
	}
	if like.Object != obj {
		t.Errorf("Like.GetID different than what we initialized %#v %#v", add.Object, obj)
	}

	update := pub.UpdateNew("https://localhost/myactivity", obj)
	if pub.IsNil(update.Object) {
		t.Errorf("Missing GetID in Update activity %#v", update.Object)
	}
	if update.Object != obj {
		t.Errorf("Update.GetID different than what we initialized %#v %#v", update.Object, obj)
	}

	undo := pub.UndoNew("https://localhost/myactivity", obj)
	if undo.Object == nil {
		t.Errorf("Missing GetID in Undo activity %#v", undo.Object)
	}
	if undo.Object != obj {
		t.Errorf("Undo.GetID different than what we initialized %#v %#v", undo.Object, obj)
	}
}

// S2S Server: Activities requiring the target property
// The distribution of the following activities require that they contain the target property:
// Add, Remove.
// Implementation always includes target property for each of the above supported activities.
func TestTargetPropertyExists(t *testing.T) {
	desc := `
S2S Server: Activities requiring the target property
  The distribution of the following activities require that they contain the target
property: Add, Remove.

  Implementation always includes target property for each of the above supported activities.
`
	t.Log(desc)

	obj := pub.MentionNew("foo")
	target := pub.MentionNew("bar")

	add := pub.AddNew("https://localhost/myactivity", obj, target)
	if pub.IsNil(add.Target) {
		t.Errorf("Missing Target in Add activity %#v", add.Target)
	}
	if add.Target != target {
		t.Errorf("Add.Target different than what we initialized %#v %#v", add.Target, target)
	}

	remove := pub.RemoveNew("https://localhost/myactivity", obj, target)
	if pub.IsNil(remove.Target) {
		t.Errorf("Missing Target in Remove activity %#v", remove.Target)
	}
	if remove.Target != target {
		t.Errorf("Remove.Target different than what we initialized %#v %#v", remove.Target, target)
	}
}

// S2S Server: Deduplication of recipient list
// Attempt to submit for delivery an activity that addresses the same actor
// (ie an actor with the same id) twice.
// (For example, the same actor could appear on both the to and cc fields,
// or the actor could be explicitly addressed
// in to but could also be a member of the addressed followers collection of the sending actor.)
// The server should deduplicate the list of inboxes to deliver to before delivering.
// The final recipient list is deduplicated before delivery.
func TestDeduplication(t *testing.T) {
	desc := `
S2S Server: Deduplication of recipient list
  Attempt to submit for delivery an activity that addresses the same actor
(ie an actor with the same id) twice.

  The final recipient list is deduplicated before delivery.
`
	t.Log(desc)

	to := pub.PersonNew("bob")
	o := pub.ObjectNew(pub.ArticleType)
	cc := pub.PersonNew("alice")

	o.ID = "something"
	c := pub.CreateNew("create", o)
	c.To.Append(to)
	c.CC.Append(cc)
	c.BCC.Append(cc)

	c.Recipients()

	checkDedup := func(list pub.ItemCollection, recIds *[]pub.ID) error {
		for _, rec := range list {
			for _, id := range *recIds {
				if rec.GetID() == id {
					return fmt.Errorf("%T[%s] already stored in recipients list, Deduplication faild", rec, id)
				}
			}
			*recIds = append(*recIds, rec.GetID())
		}
		return nil
	}

	var err error
	recIds := make([]pub.ID, 0)
	err = checkDedup(c.To, &recIds)
	if err != nil {
		t.Error(err)
	}
	err = checkDedup(c.Bto, &recIds)
	if err != nil {
		t.Error(err)
	}
	err = checkDedup(c.CC, &recIds)
	if err != nil {
		t.Error(err)
	}
	err = checkDedup(c.BCC, &recIds)
	if err != nil {
		t.Error(err)
	}
}

// S2S Server: Do-not-deliver considerations
// Server does not deliver to recipients which are the same as the actor of the
// Activity being notified about
func TestDoNotDeliverToActor(t *testing.T) {
	desc := `
S2S Server: Do-not-deliver considerations

  Server does not deliver to recipients which are the same as the actor of the
Activity being notified about
`
	t.Log(desc)

	p := pub.PersonNew("main actor")

	to := pub.PersonNew("bob")
	o := pub.ObjectNew(pub.ArticleType)
	cc := pub.PersonNew("alice")

	o.ID = "something"
	c := pub.CreateNew("create", o)
	c.Actor = *p

	c.To.Append(p)
	c.To.Append(to)
	c.CC.Append(cc)
	c.CC.Append(p)
	c.BCC.Append(cc)
	c.BCC.Append(p)

	c.Recipients()

	checkActor := func(list pub.ItemCollection, actor pub.Item) error {
		for _, rec := range list {
			if rec.GetID() == actor.GetID() {
				return fmt.Errorf("%T[%s] Actor of activity should not be in the recipients list", rec, actor.GetID())
			}
		}
		return nil
	}

	var err error
	err = checkActor(c.To, c.Actor)
	if err != nil {
		t.Error(err)
	}
	err = checkActor(c.Bto, c.Actor)
	if err != nil {
		t.Error(err)
	}
	err = checkActor(c.CC, c.Actor)
	if err != nil {
		t.Error(err)
	}
	err = checkActor(c.BCC, c.Actor)
	if err != nil {
		t.Error(err)
	}
}

// S2S Server: Do-not-deliver considerations
// Server does not deliver Block activities to their object.
func TestDoNotDeliverBlockToObject(t *testing.T) {
	desc := `
S2S Server: Do-not-deliver considerations

  Server does not deliver Block activities to their object.
`
	t.Log(desc)

	p := pub.PersonNew("blocked")

	bob := pub.PersonNew("bob")
	jane := pub.PersonNew("jane doe")

	b := pub.BlockNew("block actor", p)
	b.Actor = *bob

	b.To.Append(jane)
	b.To.Append(p)
	b.To.Append(bob)

	b.Recipients()

	checkActor := func(list pub.ItemCollection, ob pub.Item) error {
		for _, rec := range list {
			if rec.GetID() == ob.GetID() {
				return fmt.Errorf("%T[%s] of activity should not be in the recipients list", rec, ob.GetID())
			}
		}
		return nil
	}

	var err error
	err = checkActor(b.To, b.Object)
	if err != nil {
		t.Error(err)
	}
	err = checkActor(b.To, b.Actor)
	if err != nil {
		t.Error(err)
	}
}

// S2S Sever: Support for sharedInbox
// Delivers to sharedInbox endpoints to reduce the number of receiving actors delivered
// to by identifying all followers which share the same sharedInbox who would otherwise be
// individual recipients and instead deliver objects to said sharedInbox.
func TestSharedInboxIdentifySharedInbox(t *testing.T) {
	desc := `
S2S Sever: Support for sharedInbox

  Delivers to sharedInbox endpoints to reduce the number of receiving actors delivered 
to by identifying all followers which share the same sharedInbox who would otherwise be
individual recipients and instead deliver objects to said sharedInbox.
`
	t.Skip(desc)
}

// S2S Sever: Support for sharedInbox
// Deliver to actor inboxes and collections otherwise addressed which do not have a sharedInbox.
func TestSharedInboxActorsWOSharedInbox(t *testing.T) {
	desc := `
S2S Server: Do-not-deliver considerations

  Server does not deliver Block activities to their object.
`
	t.Skip(desc)
}

// S2S Server: Deduplicating received activities
// Server deduplicates activities received in inbox by comparing activity ids
func TestInboxDeduplication(t *testing.T) {
	desc := `
S2S Server: Deduplicating received activities

  Server deduplicates activities received in inbox by comparing activity ids
`
	t.Skip(desc)
}

// S2S Server: Special forwarding mechanism
// ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
// Forwards incoming activities to the values of to, bto, cc, bcc, audience if and only if criteria are met.
func TestForwardingMechanismsToRecipients(t *testing.T) {
	desc := `
S2S Server: Special forwarding mechanism
 ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".

  Forwards incoming activities to the values of to, bto, cc, bcc, audience if and only if criteria are met.
`
	t.Skip(desc)
}

// S2S Server: Special forwarding mechanism
// ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
// Recurse through to, bto, cc, bcc, audience object values to determine whether/where
// to forward according to criteria in 7.1.2
func TestForwardingMechanismsRecurseRecipients(t *testing.T) {
	desc := `
S2S Server: Special forwarding mechanism
ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".

  Recurse through to, bto, cc, bcc, audience object values to determine whether/where
  to forward according to criteria in 7.1.2
`
	t.Skip(desc)
}

// S2S Server: Special forwarding mechanism
// ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".
// Limits depth of this recursion.
func TestForwardingMechanismsLimitsRecursion(t *testing.T) {
	desc := `
S2S Server: Special forwarding mechanism
 ActivityPub contains a special mechanism for forwarding replies to avoid "ghost replies".

  Limits depth of this recursion.
`
	t.Skip(desc)
}

// S2S Server: Verification of content authorship
// Before accepting activities delivered to an actor's inbox some sort of verification
// should be performed. (For example, if the delivering actor has a public key on their profile,
// the request delivering the activity may be signed with HTTP Signatures.)
// Don't trust content received from a server other than the content's origin without some form of verification.
func TestVerification(t *testing.T) {
	desc := `
S2S Server: Verification of content authorship
 Before accepting activities delivered to an actor's inbox some sort of verification
 should be performed. (For example, if the delivering actor has a public key on their profile,
 the request delivering the activity may be signed with HTTP Signatures.)

  Don't trust content received from a server other than the content's origin without some form of verification.
`
	t.Skip(desc)
}

// S2S Server: Update activity
// On receiving an Update activity to an actor's inbox, the server:
// Takes care to be sure that the Update is authorized to modify its object
func TestUpdateIsAuthorized(t *testing.T) {
	desc := `
S2S Server: Update activity
 On receiving an Update activity to an actor's inbox, the server:

  Takes care to be sure that the Update is authorized to modify its object
`
	t.Skip(desc)
}

// S2S Server: Update activity
// On receiving an Update activity to an actor's inbox, the server:
// Completely replaces its copy of the activity with the newly received value
func TestUpdateReplacesActivity(t *testing.T) {
	desc := `
S2S Server: Update activity
 On receiving an Update activity to an actor's inbox, the server:

  Completely replaces its copy of the activity with the newly received value
`
	t.Skip(desc)
}

// S2S Server: Delete activity
// Delete removes object's representation, assuming object is owned by sending actor/server
func TestDeleteRemoves(t *testing.T) {
	desc := `
S2S Server: Delete activity

  Delete removes object's representation, assuming object is owned by sending actor/server
`
	t.Skip(desc)
}

// S2S Server: Delete activity
// Replaces deleted object with a Tombstone object (optional)
func TestDeleteReplacesWithTombstone(t *testing.T) {
	desc := `
S2S Server: Delete activity

  Replaces deleted object with a Tombstone object (optional)
`
	t.Skip(desc)
}

// S2S Server: Following, and handling accept/reject of follows
// Follow should add the activity's actor to the receiving actor's Followers Collection.
func TestFollowAddsToFollowers(t *testing.T) {
	desc := `
S2S Server: Following, and handling accept/reject of follows

  Follow should add the activity's actor to the receiving actor's Followers Collection.
`
	t.Skip(desc)
}

// S2S Server: Following, and handling accept/reject of follows
// Generates either an Accept or Reject activity with Follow as object and deliver to actor of the Follow
func TestGeneratesAcceptOrReject(t *testing.T) {
	desc := `
S2S Server: Following, and handling accept/reject of follows

  Generates either an Accept or Reject activity with Follow as object and deliver to actor of the Follow
`
	t.Skip(desc)
}

// S2S Server: Following, and handling accept/reject of follows
// If receiving an Accept in reply to a Follow activity, adds actor to receiver's Following Collection
func TestAddsFollowerIfAccept(t *testing.T) {
	desc := `
S2S Server: Following, and handling accept/reject of follows

  If receiving an Accept in reply to a Follow activity, adds actor to receiver's Following Collection
`
	t.Skip(desc)
}

// S2S Server: Following, and handling accept/reject of follows
// If receiving a Reject in reply to a Follow activity, does not add actor to receiver's Following Collection
func TestDoesntAddFollowerIfReject(t *testing.T) {
	desc := `
S2S Server: Following, and handling accept/reject of follows

  If receiving a Reject in reply to a Follow activity, does not add actor to receiver's Following Collection
`
	t.Skip(desc)
}

//S2S Server: Activity acceptance side-effects
// Test accepting the following activities to an actor's inbox and observe the side effects:
//
// Create makes record of the object existing
func TestCreateMakesRecord(t *testing.T) {
	desc := `
S2S Server: Activity acceptance side-effects
 Test accepting the following activities to an actor's inbox and observe the side effects:

  Create makes record of the object existing
`
	t.Skip(desc)
}

//S2S Server: Activity acceptance side-effects
// Test accepting the following activities to an actor's inbox and observe the side effects:
//
// Add should add the activity's object to the Collection specified in the target property,
// unless not allowed per requirements
func TestAddObjectToTarget(t *testing.T) {
	desc := `
S2S Server: Activity acceptance side-effects
 Test accepting the following activities to an actor's inbox and observe the side effects:

  Add should add the activity's object to the Collection specified in the target property,
  unless not allowed per requirements
`
	t.Skip(desc)
}

//S2S Server: Activity acceptance side-effects
// Test accepting the following activities to an actor's inbox and observe the side effects:
//
// Remove should remove the object from the Collection specified in the target property,
// unless not allowed per requirements
func TestRemoveObjectFromTarget(t *testing.T) {
	desc := `
S2S Server: Activity acceptance side-effects
 Test accepting the following activities to an actor's inbox and observe the side effects:

  Remove should remove the object from the Collection specified in the target property,
  unless not allowed per requirements
`
	t.Skip(desc)
}

//S2S Server: Activity acceptance side-effects
// Test accepting the following activities to an actor's inbox and observe the side effects:
//
// Like increments the object's count of likes by adding the received activity to the likes
// collection if this collection is present
func TestLikeIncrementsLikes(t *testing.T) {
	desc := `
S2S Server: Activity acceptance side-effects
 Test accepting the following activities to an actor's inbox and observe the side effects:

  Like increments the object's count of likes by adding the received activity to the likes
  collection if this collection is present
`
	t.Skip(desc)
}

//S2S Server: Activity acceptance side-effects
// Test accepting the following activities to an actor's inbox and observe the side effects:
//
// Announce increments object's count of shares by adding the received activity to the
// 'shares' collection if this collection is present
func TestAnnounceIncrementsShares(t *testing.T) {
	desc := `
S2S Server: Activity acceptance side-effects
 Test accepting the following activities to an actor's inbox and observe the side effects:

  Announce increments object's count of shares by adding the received activity to the
 'shares' collection if this collection is present
`
	t.Skip(desc)
}

//S2S Server: Activity acceptance side-effects
// Test accepting the following activities to an actor's inbox and observe the side effects:
//
// Undo performs Undo of object in federated context
func TestUndoPerformsUndoOnObject(t *testing.T) {
	desc := `
S2S Server: Activity acceptance side-effects
 Test accepting the following activities to an actor's inbox and observe the side effects:

  Undo performs Undo of object in federated context
`
	t.Skip(desc)
}