@evanp/activitypub-bot 0.12.1 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/lib/app.js +19 -1
  2. package/lib/index.js +2 -0
  3. package/lib/routes/collection.js +83 -67
  4. package/lib/routes/inbox.js +8 -0
  5. package/lib/routes/object.js +25 -5
  6. package/package.json +3 -3
  7. package/.github/dependabot.yml +0 -11
  8. package/.github/workflows/main.yml +0 -34
  9. package/.github/workflows/tag.yml +0 -106
  10. package/.nvmrc +0 -1
  11. package/Dockerfile +0 -17
  12. package/docs/activitypub.bot.drawio +0 -110
  13. package/tests/activitydistributor.test.js +0 -606
  14. package/tests/activityhandler.test.js +0 -2276
  15. package/tests/activitypubclient.test.js +0 -210
  16. package/tests/actorstorage.test.js +0 -283
  17. package/tests/app.test.js +0 -17
  18. package/tests/authorizer.test.js +0 -301
  19. package/tests/bot.donothing.test.js +0 -30
  20. package/tests/bot.ok.test.js +0 -101
  21. package/tests/botcontext.test.js +0 -720
  22. package/tests/botdatastorage.test.js +0 -88
  23. package/tests/botfactory.provincebotfactory.test.js +0 -430
  24. package/tests/digester.test.js +0 -56
  25. package/tests/fixtures/bots.js +0 -27
  26. package/tests/fixtures/eventloggingbot.js +0 -57
  27. package/tests/fixtures/provincebotfactory.js +0 -53
  28. package/tests/httpsignature.test.js +0 -199
  29. package/tests/httpsignatureauthenticator.test.js +0 -463
  30. package/tests/index.test.js +0 -10
  31. package/tests/keystorage.test.js +0 -124
  32. package/tests/microsyntax.test.js +0 -123
  33. package/tests/objectcache.test.js +0 -133
  34. package/tests/objectstorage.test.js +0 -149
  35. package/tests/remotekeystorage.test.js +0 -78
  36. package/tests/routes.actor.test.js +0 -214
  37. package/tests/routes.collection.test.js +0 -433
  38. package/tests/routes.health.test.js +0 -41
  39. package/tests/routes.inbox.test.js +0 -136
  40. package/tests/routes.object.test.js +0 -525
  41. package/tests/routes.server.test.js +0 -69
  42. package/tests/routes.sharedinbox.test.js +0 -473
  43. package/tests/routes.webfinger.test.js +0 -68
  44. package/tests/urlformatter.test.js +0 -164
  45. package/tests/utils/digest.js +0 -7
  46. package/tests/utils/nock.js +0 -499
@@ -1,41 +0,0 @@
1
- import { describe, it } from 'node:test'
2
- import assert from 'node:assert'
3
- import { makeApp } from '../lib/app.js'
4
- import request from 'supertest'
5
- import bots from './fixtures/bots.js'
6
-
7
- describe('health check routes', async () => {
8
- const databaseUrl = 'sqlite::memory:'
9
- const origin = 'https://activitypubbot.test'
10
- const app = await makeApp(databaseUrl, origin, bots, 'silent')
11
- describe('GET /livez', async () => {
12
- let response = null
13
- it('should work without an error', async () => {
14
- response = await request(app).get('/livez')
15
- })
16
- it('should return 200 OK', async () => {
17
- assert.strictEqual(response.status, 200)
18
- })
19
- it('should return plain text', async () => {
20
- assert.strictEqual(response.type, 'text/plain')
21
- })
22
- it('should return an OK flag', async () => {
23
- assert.strictEqual(response.text, 'OK')
24
- })
25
- })
26
- describe('GET /readyz', async () => {
27
- let response = null
28
- it('should work without an error', async () => {
29
- response = await request(app).get('/readyz')
30
- })
31
- it('should return 200 OK', async () => {
32
- assert.strictEqual(response.status, 200)
33
- })
34
- it('should return plain text', async () => {
35
- assert.strictEqual(response.type, 'text/plain')
36
- })
37
- it('should return an OK flag', async () => {
38
- assert.strictEqual(response.text, 'OK')
39
- })
40
- })
41
- })
@@ -1,136 +0,0 @@
1
- import { describe, it, before } from 'node:test'
2
- import assert from 'node:assert'
3
- import as2 from '../lib/activitystreams.js'
4
- import request from 'supertest'
5
-
6
- import { makeApp } from '../lib/app.js'
7
-
8
- import { nockSetup, nockSignature, nockFormat } from './utils/nock.js'
9
- import { makeDigest } from './utils/digest.js'
10
- import bots from './fixtures/bots.js'
11
-
12
- describe('routes.inbox', async () => {
13
- const host = 'activitypubbot.test'
14
- const origin = `https://${host}`
15
- const databaseUrl = 'sqlite::memory:'
16
- let app = null
17
-
18
- before(async () => {
19
- nockSetup('social.example')
20
- app = await makeApp(databaseUrl, origin, bots, 'silent')
21
- })
22
-
23
- describe('can handle an incoming activity', async () => {
24
- const username = 'actor1'
25
- const botName = 'test0'
26
- const path = `/user/${botName}/inbox`
27
- const url = `${origin}${path}`
28
- const date = new Date().toUTCString()
29
- const activity = await as2.import({
30
- type: 'Activity',
31
- actor: nockFormat({ username }),
32
- id: nockFormat({ username, type: 'activity', num: 1 })
33
- })
34
- const body = await activity.write()
35
- const digest = makeDigest(body)
36
- const signature = await nockSignature({
37
- method: 'POST',
38
- username,
39
- url,
40
- digest,
41
- date
42
- })
43
- let response = null
44
- it('should work without an error', async () => {
45
- response = await request(app)
46
- .post(path)
47
- .send(body)
48
- .set('Signature', signature)
49
- .set('Date', date)
50
- .set('Host', host)
51
- .set('Digest', digest)
52
- .set('Content-Type', 'application/activity+json')
53
- assert.ok(response)
54
- await app.onIdle()
55
- })
56
- it('should return a 200 status', async () => {
57
- assert.strictEqual(response.status, 200)
58
- })
59
- it('should appear in the inbox', async () => {
60
- const { actorStorage } = app.locals
61
- assert.strictEqual(
62
- true,
63
- await actorStorage.isInCollection(
64
- botName,
65
- 'inbox',
66
- activity
67
- )
68
- )
69
- })
70
- })
71
-
72
- describe('can handle a duplicate incoming activity', async () => {
73
- const username = 'actor2'
74
- const botName = 'test1'
75
- const path = `/user/${botName}/inbox`
76
- const url = `${origin}${path}`
77
- const date = new Date().toUTCString()
78
- const activity = await as2.import({
79
- type: 'Activity',
80
- actor: nockFormat({ username }),
81
- id: nockFormat({ username, type: 'activity', num: 2 }),
82
- to: 'as:Public'
83
- })
84
- const body = await activity.write()
85
- const digest = makeDigest(body)
86
- const signature = await nockSignature({
87
- method: 'POST',
88
- username,
89
- url,
90
- digest,
91
- date
92
- })
93
- let response = null
94
- it('should work without an error', async () => {
95
- response = await request(app)
96
- .post(path)
97
- .send(body)
98
- .set('Signature', signature)
99
- .set('Date', date)
100
- .set('Host', host)
101
- .set('Digest', digest)
102
- .set('Content-Type', 'application/activity+json')
103
- assert.ok(response)
104
- await app.onIdle()
105
- })
106
- it('should return a 200 status', async () => {
107
- assert.strictEqual(response.status, 200)
108
- })
109
- it('should appear in the inbox', async () => {
110
- const { actorStorage } = app.locals
111
- assert.strictEqual(
112
- true,
113
- await actorStorage.isInCollection(
114
- botName,
115
- 'inbox',
116
- activity
117
- )
118
- )
119
- })
120
- it('should fail the second time', async () => {
121
- response = await request(app)
122
- .post(path)
123
- .send(body)
124
- .set('Signature', signature)
125
- .set('Date', date)
126
- .set('Host', host)
127
- .set('Digest', digest)
128
- .set('Content-Type', 'application/activity+json')
129
- assert.ok(response)
130
- await app.onIdle()
131
- })
132
- it('should return a 400 status', async () => {
133
- assert.strictEqual(response.status, 400)
134
- })
135
- })
136
- })