@evanp/activitypub-bot 0.13.0 → 0.13.2
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.
- package/package.json +2 -2
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/main.yml +0 -34
- package/.github/workflows/tag.yml +0 -106
- package/.nvmrc +0 -1
- package/Dockerfile +0 -17
- package/docs/activitypub.bot.drawio +0 -110
- package/tests/activitydistributor.test.js +0 -606
- package/tests/activityhandler.test.js +0 -2276
- package/tests/activitypubclient.test.js +0 -210
- package/tests/actorstorage.test.js +0 -283
- package/tests/app.test.js +0 -17
- package/tests/authorizer.test.js +0 -301
- package/tests/bot.donothing.test.js +0 -30
- package/tests/bot.ok.test.js +0 -101
- package/tests/botcontext.test.js +0 -720
- package/tests/botdatastorage.test.js +0 -88
- package/tests/botfactory.provincebotfactory.test.js +0 -430
- package/tests/digester.test.js +0 -56
- package/tests/fixtures/bots.js +0 -27
- package/tests/fixtures/eventloggingbot.js +0 -57
- package/tests/fixtures/provincebotfactory.js +0 -53
- package/tests/httpsignature.test.js +0 -199
- package/tests/httpsignatureauthenticator.test.js +0 -463
- package/tests/index.test.js +0 -12
- package/tests/keystorage.test.js +0 -124
- package/tests/microsyntax.test.js +0 -123
- package/tests/objectcache.test.js +0 -133
- package/tests/objectstorage.test.js +0 -149
- package/tests/remotekeystorage.test.js +0 -78
- package/tests/routes.actor.test.js +0 -214
- package/tests/routes.collection.test.js +0 -310
- package/tests/routes.health.test.js +0 -41
- package/tests/routes.inbox.test.js +0 -216
- package/tests/routes.object.test.js +0 -525
- package/tests/routes.server.test.js +0 -69
- package/tests/routes.sharedinbox.test.js +0 -473
- package/tests/routes.webfinger.test.js +0 -68
- package/tests/urlformatter.test.js +0 -164
- package/tests/utils/digest.js +0 -7
- package/tests/utils/nock.js +0 -499
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import { describe, it, before } 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
|
-
import as2 from '../lib/activitystreams.js'
|
|
7
|
-
import { nockSetup, nockFormat, nockSignature, makeActor } from './utils/nock.js'
|
|
8
|
-
|
|
9
|
-
const uppercase = (string) => string.charAt(0).toUpperCase() + string.slice(1)
|
|
10
|
-
|
|
11
|
-
describe('object collection routes', async () => {
|
|
12
|
-
const databaseUrl = 'sqlite::memory:'
|
|
13
|
-
const host = 'activitypubbot.test'
|
|
14
|
-
const origin = `https://${host}`
|
|
15
|
-
const remote = 'social.example'
|
|
16
|
-
const username = 'ok'
|
|
17
|
-
const type = 'object'
|
|
18
|
-
const nanoid = 'hUQC9HWian7dzOxZJlJBA'
|
|
19
|
-
let app = null
|
|
20
|
-
let obj = null
|
|
21
|
-
let reply = null
|
|
22
|
-
let like = null
|
|
23
|
-
let share = null
|
|
24
|
-
let privateObj = null
|
|
25
|
-
const privateNanoid = 'Ic3Sa_0xOQKvlPsWU16as'
|
|
26
|
-
|
|
27
|
-
before(async () => {
|
|
28
|
-
app = await makeApp(databaseUrl, origin, bots, 'silent')
|
|
29
|
-
const { formatter, objectStorage, actorStorage } = app.locals
|
|
30
|
-
nockSetup(remote)
|
|
31
|
-
obj = await as2.import({
|
|
32
|
-
id: formatter.format({ username, type, nanoid }),
|
|
33
|
-
type: uppercase(type),
|
|
34
|
-
attributedTo: formatter.format({ username }),
|
|
35
|
-
summaryMap: {
|
|
36
|
-
en: 'Test object for the object collection routes'
|
|
37
|
-
},
|
|
38
|
-
replies: formatter.format({ username, type, nanoid, collection: 'replies' }),
|
|
39
|
-
likes: formatter.format({ username, type, nanoid, collection: 'likes' }),
|
|
40
|
-
shares: formatter.format({ username, type, nanoid, collection: 'shares' }),
|
|
41
|
-
to: ['as:Public']
|
|
42
|
-
})
|
|
43
|
-
await objectStorage.create(obj)
|
|
44
|
-
await objectStorage.addToCollection(obj.id, 'thread', obj)
|
|
45
|
-
reply = await as2.import({
|
|
46
|
-
id: nockFormat({
|
|
47
|
-
domain: remote,
|
|
48
|
-
username: 'replier1',
|
|
49
|
-
type: 'note',
|
|
50
|
-
num: 1
|
|
51
|
-
}),
|
|
52
|
-
type: 'Note',
|
|
53
|
-
attributedTo: nockFormat({
|
|
54
|
-
domain: remote,
|
|
55
|
-
username: 'replier1'
|
|
56
|
-
}),
|
|
57
|
-
content: 'This is a reply to the test object',
|
|
58
|
-
inReplyTo: obj.id,
|
|
59
|
-
to: [formatter.format({ username }), 'as:Public']
|
|
60
|
-
})
|
|
61
|
-
await objectStorage.addToCollection(obj.id, 'replies', reply)
|
|
62
|
-
await objectStorage.addToCollection(obj.id, 'thread', reply)
|
|
63
|
-
like = await as2.import({
|
|
64
|
-
id: nockFormat({
|
|
65
|
-
domain: remote,
|
|
66
|
-
username: 'liker1',
|
|
67
|
-
type: 'like',
|
|
68
|
-
num: 1,
|
|
69
|
-
obj: obj.id
|
|
70
|
-
}),
|
|
71
|
-
type: 'Like',
|
|
72
|
-
attributedTo: nockFormat({
|
|
73
|
-
domain: remote,
|
|
74
|
-
username: 'liker1'
|
|
75
|
-
}),
|
|
76
|
-
object: obj.id,
|
|
77
|
-
to: [formatter.format({ username }), 'as:Public']
|
|
78
|
-
})
|
|
79
|
-
await objectStorage.addToCollection(obj.id, 'likes', like)
|
|
80
|
-
share = await as2.import({
|
|
81
|
-
id: nockFormat({
|
|
82
|
-
domain: remote,
|
|
83
|
-
username: 'sharer1',
|
|
84
|
-
type: 'announce',
|
|
85
|
-
num: 1,
|
|
86
|
-
obj: obj.id
|
|
87
|
-
}),
|
|
88
|
-
type: 'Announce',
|
|
89
|
-
attributedTo: nockFormat({
|
|
90
|
-
domain: remote,
|
|
91
|
-
username: 'sharer1'
|
|
92
|
-
}),
|
|
93
|
-
object: obj.id,
|
|
94
|
-
to: [formatter.format({ username }), 'as:Public']
|
|
95
|
-
})
|
|
96
|
-
await objectStorage.addToCollection(obj.id, 'shares', share)
|
|
97
|
-
privateObj = await as2.import({
|
|
98
|
-
id: formatter.format({ username, type, nanoid: privateNanoid }),
|
|
99
|
-
type: uppercase(type),
|
|
100
|
-
attributedTo: formatter.format({ username }),
|
|
101
|
-
summaryMap: {
|
|
102
|
-
en: 'Test object for the object collection routes'
|
|
103
|
-
},
|
|
104
|
-
replies: formatter.format({ username, type, nanoid, collection: 'replies' }),
|
|
105
|
-
likes: formatter.format({ username, type, nanoid, collection: 'likes' }),
|
|
106
|
-
shares: formatter.format({ username, type, nanoid, collection: 'shares' }),
|
|
107
|
-
to: formatter.format({ username, collection: 'followers' })
|
|
108
|
-
})
|
|
109
|
-
await objectStorage.create(privateObj)
|
|
110
|
-
const follower = await makeActor('follower1', remote)
|
|
111
|
-
await actorStorage.addToCollection(
|
|
112
|
-
username,
|
|
113
|
-
'followers',
|
|
114
|
-
follower
|
|
115
|
-
)
|
|
116
|
-
assert.ok(
|
|
117
|
-
await actorStorage.isInCollection(username, 'followers', follower)
|
|
118
|
-
)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
describe('GET /user/{username}/{type}/{nanoid}', async () => {
|
|
122
|
-
let response = null
|
|
123
|
-
const url = `/user/${username}/${type}/${nanoid}`
|
|
124
|
-
it('should work without an error', async () => {
|
|
125
|
-
response = await request(app)
|
|
126
|
-
.get(url)
|
|
127
|
-
})
|
|
128
|
-
it('should return a 200 status', async () => {
|
|
129
|
-
assert.strictEqual(response.status, 200)
|
|
130
|
-
})
|
|
131
|
-
it('should return AS2', async () => {
|
|
132
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
133
|
-
})
|
|
134
|
-
it('should return an object', async () => {
|
|
135
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
136
|
-
})
|
|
137
|
-
it('should return an object with the right id', async () => {
|
|
138
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
139
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}`)
|
|
140
|
-
})
|
|
141
|
-
it('should return an object with the right type', async () => {
|
|
142
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
143
|
-
assert.strictEqual(response.body.type, 'Object')
|
|
144
|
-
})
|
|
145
|
-
it('should return an object with the right summary', async () => {
|
|
146
|
-
assert.strictEqual(typeof response.body.summaryMap, 'object')
|
|
147
|
-
assert.strictEqual(response.body.summaryMap.en, 'Test object for the object collection routes')
|
|
148
|
-
})
|
|
149
|
-
it('should return an object with the right replies', async () => {
|
|
150
|
-
assert.strictEqual(typeof response.body.replies, 'string')
|
|
151
|
-
assert.strictEqual(response.body.replies, `${origin}/user/${username}/${type}/${nanoid}/replies`)
|
|
152
|
-
})
|
|
153
|
-
it('should return an object with the right likes', async () => {
|
|
154
|
-
assert.strictEqual(typeof response.body.likes, 'string')
|
|
155
|
-
assert.strictEqual(response.body.likes, `${origin}/user/${username}/${type}/${nanoid}/likes`)
|
|
156
|
-
})
|
|
157
|
-
it('should return an object with the right shares', async () => {
|
|
158
|
-
assert.strictEqual(typeof response.body.shares, 'string')
|
|
159
|
-
assert.strictEqual(response.body.shares, `${origin}/user/${username}/${type}/${nanoid}/shares`)
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
describe('GET /user/{username}/{type}/{nanoid}/replies', async () => {
|
|
164
|
-
let response = null
|
|
165
|
-
const url = `/user/${username}/${type}/${nanoid}/replies`
|
|
166
|
-
it('should work without an error', async () => {
|
|
167
|
-
response = await request(app)
|
|
168
|
-
.get(url)
|
|
169
|
-
})
|
|
170
|
-
it('should return a 200 status', async () => {
|
|
171
|
-
assert.strictEqual(response.status, 200)
|
|
172
|
-
})
|
|
173
|
-
it('should return AS2', async () => {
|
|
174
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
175
|
-
})
|
|
176
|
-
it('should return an object', async () => {
|
|
177
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
178
|
-
})
|
|
179
|
-
it('should return an object the right id', async () => {
|
|
180
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
181
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/replies`)
|
|
182
|
-
})
|
|
183
|
-
it('should return an object with the right type', async () => {
|
|
184
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
185
|
-
assert.strictEqual(response.body.type, 'OrderedCollection')
|
|
186
|
-
})
|
|
187
|
-
it('should return an object with the right totalItems', async () => {
|
|
188
|
-
assert.strictEqual(typeof response.body.totalItems, 'number')
|
|
189
|
-
assert.strictEqual(response.body.totalItems, 1)
|
|
190
|
-
})
|
|
191
|
-
it('should return an object with the right first', async () => {
|
|
192
|
-
assert.strictEqual(typeof response.body.first, 'string')
|
|
193
|
-
assert.strictEqual(response.body.first, `${origin}/user/${username}/${type}/${nanoid}/replies/1`)
|
|
194
|
-
})
|
|
195
|
-
it('should return an object with the right last', async () => {
|
|
196
|
-
assert.strictEqual(typeof response.body.last, 'string')
|
|
197
|
-
assert.strictEqual(response.body.last, `${origin}/user/${username}/${type}/${nanoid}/replies/1`)
|
|
198
|
-
})
|
|
199
|
-
it('should return an object with the right repliesOf', async () => {
|
|
200
|
-
assert.strictEqual(typeof response.body.repliesOf, 'string')
|
|
201
|
-
assert.strictEqual(response.body.repliesOf, `${origin}/user/${username}/${type}/${nanoid}`)
|
|
202
|
-
})
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
describe('GET /user/{username}/{type}/{nanoid}/replies/1', async () => {
|
|
206
|
-
let response = null
|
|
207
|
-
const url = `/user/${username}/${type}/${nanoid}/replies/1`
|
|
208
|
-
it('should work without an error', async () => {
|
|
209
|
-
response = await request(app)
|
|
210
|
-
.get(url)
|
|
211
|
-
})
|
|
212
|
-
it('should return a 200 status', async () => {
|
|
213
|
-
assert.strictEqual(response.status, 200)
|
|
214
|
-
})
|
|
215
|
-
it('should return AS2', async () => {
|
|
216
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
217
|
-
})
|
|
218
|
-
it('should return an object', async () => {
|
|
219
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
220
|
-
})
|
|
221
|
-
it('should return an object the right id', async () => {
|
|
222
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
223
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/replies/1`)
|
|
224
|
-
})
|
|
225
|
-
it('should return an object with the right type', async () => {
|
|
226
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
227
|
-
assert.strictEqual(response.body.type, 'OrderedCollectionPage')
|
|
228
|
-
})
|
|
229
|
-
it('should return an object with the right partOf', async () => {
|
|
230
|
-
assert.strictEqual(typeof response.body.partOf, 'string')
|
|
231
|
-
assert.strictEqual(response.body.partOf, `${origin}/user/${username}/${type}/${nanoid}/replies`)
|
|
232
|
-
})
|
|
233
|
-
it('should return an object with the right items', async () => {
|
|
234
|
-
assert.strictEqual(typeof response.body.items, 'object')
|
|
235
|
-
assert.strictEqual(response.body.items.length, 1)
|
|
236
|
-
assert.strictEqual(response.body.items[0], reply.id)
|
|
237
|
-
})
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
describe('GET /user/{username}/{type}/{nanoid}/likes', async () => {
|
|
241
|
-
let response = null
|
|
242
|
-
const url = `/user/${username}/${type}/${nanoid}/likes`
|
|
243
|
-
it('should work without an error', async () => {
|
|
244
|
-
response = await request(app)
|
|
245
|
-
.get(url)
|
|
246
|
-
})
|
|
247
|
-
it('should return a 200 status', async () => {
|
|
248
|
-
assert.strictEqual(response.status, 200)
|
|
249
|
-
})
|
|
250
|
-
it('should return AS2', async () => {
|
|
251
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
252
|
-
})
|
|
253
|
-
it('should return an object', async () => {
|
|
254
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
255
|
-
})
|
|
256
|
-
it('should return an object the right id', async () => {
|
|
257
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
258
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/likes`)
|
|
259
|
-
})
|
|
260
|
-
it('should return an object with the right type', async () => {
|
|
261
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
262
|
-
assert.strictEqual(response.body.type, 'OrderedCollection')
|
|
263
|
-
})
|
|
264
|
-
it('should return an object with the right totalItems', async () => {
|
|
265
|
-
assert.strictEqual(typeof response.body.totalItems, 'number')
|
|
266
|
-
assert.strictEqual(response.body.totalItems, 1)
|
|
267
|
-
})
|
|
268
|
-
it('should return an object with the right first', async () => {
|
|
269
|
-
assert.strictEqual(typeof response.body.first, 'string')
|
|
270
|
-
assert.strictEqual(response.body.first, `${origin}/user/${username}/${type}/${nanoid}/likes/1`)
|
|
271
|
-
})
|
|
272
|
-
it('should return an object with the right last', async () => {
|
|
273
|
-
assert.strictEqual(typeof response.body.last, 'string')
|
|
274
|
-
assert.strictEqual(response.body.last, `${origin}/user/${username}/${type}/${nanoid}/likes/1`)
|
|
275
|
-
})
|
|
276
|
-
it('should return an object with the right likesOf', async () => {
|
|
277
|
-
assert.strictEqual(typeof response.body.likesOf, 'string')
|
|
278
|
-
assert.strictEqual(response.body.likesOf, `${origin}/user/${username}/${type}/${nanoid}`)
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
describe('GET /user/{username}/{type}/{nanoid}/likes/1', async () => {
|
|
283
|
-
let response = null
|
|
284
|
-
const url = `/user/${username}/${type}/${nanoid}/likes/1`
|
|
285
|
-
it('should work without an error', async () => {
|
|
286
|
-
response = await request(app)
|
|
287
|
-
.get(url)
|
|
288
|
-
})
|
|
289
|
-
it('should return a 200 status', async () => {
|
|
290
|
-
assert.strictEqual(response.status, 200)
|
|
291
|
-
})
|
|
292
|
-
it('should return AS2', async () => {
|
|
293
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
294
|
-
})
|
|
295
|
-
it('should return an object', async () => {
|
|
296
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
297
|
-
})
|
|
298
|
-
it('should return an object the right id', async () => {
|
|
299
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
300
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/likes/1`)
|
|
301
|
-
})
|
|
302
|
-
it('should return an object with the right type', async () => {
|
|
303
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
304
|
-
assert.strictEqual(response.body.type, 'OrderedCollectionPage')
|
|
305
|
-
})
|
|
306
|
-
it('should return an object with the right partOf', async () => {
|
|
307
|
-
assert.strictEqual(typeof response.body.partOf, 'string')
|
|
308
|
-
assert.strictEqual(response.body.partOf, `${origin}/user/${username}/${type}/${nanoid}/likes`)
|
|
309
|
-
})
|
|
310
|
-
it('should return an object with the right items', async () => {
|
|
311
|
-
assert.strictEqual(typeof response.body.items, 'object')
|
|
312
|
-
assert.strictEqual(response.body.items.length, 1)
|
|
313
|
-
assert.strictEqual(response.body.items[0], like.id)
|
|
314
|
-
})
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
describe('GET /user/{username}/{type}/{nanoid}/shares', async () => {
|
|
318
|
-
let response = null
|
|
319
|
-
const url = `/user/${username}/${type}/${nanoid}/shares`
|
|
320
|
-
it('should work without an error', async () => {
|
|
321
|
-
response = await request(app)
|
|
322
|
-
.get(url)
|
|
323
|
-
})
|
|
324
|
-
it('should return a 200 status', async () => {
|
|
325
|
-
assert.strictEqual(response.status, 200)
|
|
326
|
-
})
|
|
327
|
-
it('should return AS2', async () => {
|
|
328
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
329
|
-
})
|
|
330
|
-
it('should return an object', async () => {
|
|
331
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
332
|
-
})
|
|
333
|
-
it('should return an object the right id', async () => {
|
|
334
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
335
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/shares`)
|
|
336
|
-
})
|
|
337
|
-
it('should return an object with the right type', async () => {
|
|
338
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
339
|
-
assert.strictEqual(response.body.type, 'OrderedCollection')
|
|
340
|
-
})
|
|
341
|
-
it('should return an object with the right totalItems', async () => {
|
|
342
|
-
assert.strictEqual(typeof response.body.totalItems, 'number')
|
|
343
|
-
assert.strictEqual(response.body.totalItems, 1)
|
|
344
|
-
})
|
|
345
|
-
it('should return an object with the right first', async () => {
|
|
346
|
-
assert.strictEqual(typeof response.body.first, 'string')
|
|
347
|
-
assert.strictEqual(response.body.first, `${origin}/user/${username}/${type}/${nanoid}/shares/1`)
|
|
348
|
-
})
|
|
349
|
-
it('should return an object with the right last', async () => {
|
|
350
|
-
assert.strictEqual(typeof response.body.last, 'string')
|
|
351
|
-
assert.strictEqual(response.body.last, `${origin}/user/${username}/${type}/${nanoid}/shares/1`)
|
|
352
|
-
})
|
|
353
|
-
it('should return an object with the right sharesOf', async () => {
|
|
354
|
-
assert.strictEqual(typeof response.body.sharesOf, 'string')
|
|
355
|
-
assert.strictEqual(response.body.sharesOf, `${origin}/user/${username}/${type}/${nanoid}`)
|
|
356
|
-
})
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
describe('GET /user/{username}/{type}/{nanoid}/shares/1', async () => {
|
|
360
|
-
let response = null
|
|
361
|
-
const url = `/user/${username}/${type}/${nanoid}/shares/1`
|
|
362
|
-
it('should work without an error', async () => {
|
|
363
|
-
response = await request(app)
|
|
364
|
-
.get(url)
|
|
365
|
-
})
|
|
366
|
-
it('should return a 200 status', async () => {
|
|
367
|
-
assert.strictEqual(response.status, 200)
|
|
368
|
-
})
|
|
369
|
-
it('should return AS2', async () => {
|
|
370
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
371
|
-
})
|
|
372
|
-
it('should return an object', async () => {
|
|
373
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
374
|
-
})
|
|
375
|
-
it('should return an object the right id', async () => {
|
|
376
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
377
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/shares/1`)
|
|
378
|
-
})
|
|
379
|
-
it('should return an object with the right type', async () => {
|
|
380
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
381
|
-
assert.strictEqual(response.body.type, 'OrderedCollectionPage')
|
|
382
|
-
})
|
|
383
|
-
it('should return an object with the right partOf', async () => {
|
|
384
|
-
assert.strictEqual(typeof response.body.partOf, 'string')
|
|
385
|
-
assert.strictEqual(response.body.partOf, `${origin}/user/${username}/${type}/${nanoid}/shares`)
|
|
386
|
-
})
|
|
387
|
-
it('should return an object with the right items', async () => {
|
|
388
|
-
assert.strictEqual(typeof response.body.items, 'object')
|
|
389
|
-
assert.strictEqual(response.body.items.length, 1)
|
|
390
|
-
assert.strictEqual(response.body.items[0], share.id)
|
|
391
|
-
})
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
describe('Get private object anonymously', async () => {
|
|
395
|
-
let response = null
|
|
396
|
-
const url = `/user/${username}/${type}/${privateNanoid}`
|
|
397
|
-
it('should work without an error', async () => {
|
|
398
|
-
response = await request(app)
|
|
399
|
-
.get(url)
|
|
400
|
-
})
|
|
401
|
-
it('should return a 403 status', async () => {
|
|
402
|
-
assert.strictEqual(response.status, 403)
|
|
403
|
-
})
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
describe('Get private object collection anonymously', async () => {
|
|
407
|
-
let response = null
|
|
408
|
-
const url = `/user/${username}/${type}/${privateNanoid}/replies`
|
|
409
|
-
it('should work without an error', async () => {
|
|
410
|
-
response = await request(app)
|
|
411
|
-
.get(url)
|
|
412
|
-
})
|
|
413
|
-
it('should return a 403 status', async () => {
|
|
414
|
-
assert.strictEqual(response.status, 403)
|
|
415
|
-
})
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
describe('Get private object collection page anonymously', async () => {
|
|
419
|
-
let response = null
|
|
420
|
-
const url = `/user/${username}/${type}/${privateNanoid}/replies/1`
|
|
421
|
-
it('should work without an error', async () => {
|
|
422
|
-
response = await request(app)
|
|
423
|
-
.get(url)
|
|
424
|
-
})
|
|
425
|
-
it('should return a 403 status', async () => {
|
|
426
|
-
assert.strictEqual(response.status, 403)
|
|
427
|
-
})
|
|
428
|
-
})
|
|
429
|
-
|
|
430
|
-
describe('Get private object with follower', async () => {
|
|
431
|
-
let response = null
|
|
432
|
-
it('should work without an error', async () => {
|
|
433
|
-
const path = `/user/${username}/${type}/${privateNanoid}`
|
|
434
|
-
const url = `${origin}${path}`
|
|
435
|
-
const date = new Date().toISOString()
|
|
436
|
-
const signature = await nockSignature({ username: 'follower1', url, date })
|
|
437
|
-
response = await request(app)
|
|
438
|
-
.get(path)
|
|
439
|
-
.set('Signature', signature)
|
|
440
|
-
.set('Date', date)
|
|
441
|
-
.set('Host', host)
|
|
442
|
-
})
|
|
443
|
-
it('should return a 200 status', async () => {
|
|
444
|
-
assert.strictEqual(response.status, 200)
|
|
445
|
-
})
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
describe('GET /user/{username}/{type}/{nanoid}/thread', async () => {
|
|
449
|
-
let response = null
|
|
450
|
-
const url = `/user/${username}/${type}/${nanoid}/thread`
|
|
451
|
-
it('should work without an error', async () => {
|
|
452
|
-
response = await request(app)
|
|
453
|
-
.get(url)
|
|
454
|
-
})
|
|
455
|
-
it('should return a 200 status', async () => {
|
|
456
|
-
assert.strictEqual(response.status, 200)
|
|
457
|
-
})
|
|
458
|
-
it('should return AS2', async () => {
|
|
459
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
460
|
-
})
|
|
461
|
-
it('should return an object', async () => {
|
|
462
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
463
|
-
})
|
|
464
|
-
it('should return an object the right id', async () => {
|
|
465
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
466
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/thread`)
|
|
467
|
-
})
|
|
468
|
-
it('should return an object with the right type', async () => {
|
|
469
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
470
|
-
assert.strictEqual(response.body.type, 'OrderedCollection')
|
|
471
|
-
})
|
|
472
|
-
it('should return an object with the right totalItems', async () => {
|
|
473
|
-
assert.strictEqual(typeof response.body.totalItems, 'number')
|
|
474
|
-
assert.strictEqual(response.body.totalItems, 2)
|
|
475
|
-
})
|
|
476
|
-
it('should return an object with the right first', async () => {
|
|
477
|
-
assert.strictEqual(typeof response.body.first, 'string')
|
|
478
|
-
assert.strictEqual(response.body.first, `${origin}/user/${username}/${type}/${nanoid}/thread/1`)
|
|
479
|
-
})
|
|
480
|
-
it('should return an object with the right last', async () => {
|
|
481
|
-
assert.strictEqual(typeof response.body.last, 'string')
|
|
482
|
-
assert.strictEqual(response.body.last, `${origin}/user/${username}/${type}/${nanoid}/thread/1`)
|
|
483
|
-
})
|
|
484
|
-
it('should return an object with the right root', async () => {
|
|
485
|
-
assert.strictEqual(typeof response.body.root, 'string')
|
|
486
|
-
assert.strictEqual(response.body.root, `${origin}/user/${username}/${type}/${nanoid}`)
|
|
487
|
-
})
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
describe('GET /user/{username}/{type}/{nanoid}/thread/1', async () => {
|
|
491
|
-
let response = null
|
|
492
|
-
const url = `/user/${username}/${type}/${nanoid}/thread/1`
|
|
493
|
-
it('should work without an error', async () => {
|
|
494
|
-
response = await request(app)
|
|
495
|
-
.get(url)
|
|
496
|
-
})
|
|
497
|
-
it('should return a 200 status', async () => {
|
|
498
|
-
assert.strictEqual(response.status, 200)
|
|
499
|
-
})
|
|
500
|
-
it('should return AS2', async () => {
|
|
501
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
502
|
-
})
|
|
503
|
-
it('should return an object', async () => {
|
|
504
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
505
|
-
})
|
|
506
|
-
it('should return an object the right id', async () => {
|
|
507
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
508
|
-
assert.strictEqual(response.body.id, `${origin}/user/${username}/${type}/${nanoid}/thread/1`)
|
|
509
|
-
})
|
|
510
|
-
it('should return an object with the right type', async () => {
|
|
511
|
-
assert.strictEqual(typeof response.body.type, 'string')
|
|
512
|
-
assert.strictEqual(response.body.type, 'OrderedCollectionPage')
|
|
513
|
-
})
|
|
514
|
-
it('should return an object with the right partOf', async () => {
|
|
515
|
-
assert.strictEqual(typeof response.body.partOf, 'string')
|
|
516
|
-
assert.strictEqual(response.body.partOf, `${origin}/user/${username}/${type}/${nanoid}/thread`)
|
|
517
|
-
})
|
|
518
|
-
it('should return an object with the right items', async () => {
|
|
519
|
-
assert.strictEqual(typeof response.body.items, 'object')
|
|
520
|
-
assert.strictEqual(response.body.items.length, 2)
|
|
521
|
-
assert.strictEqual(response.body.items[0], reply.id)
|
|
522
|
-
assert.strictEqual(response.body.items[1], obj.id)
|
|
523
|
-
})
|
|
524
|
-
})
|
|
525
|
-
})
|
|
@@ -1,69 +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('server 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 /', async () => {
|
|
12
|
-
let response = null
|
|
13
|
-
it('should work without an error', async () => {
|
|
14
|
-
response = await request(app).get('/')
|
|
15
|
-
})
|
|
16
|
-
it('should return 200 OK', async () => {
|
|
17
|
-
assert.strictEqual(response.status, 200)
|
|
18
|
-
})
|
|
19
|
-
it('should return AS2', async () => {
|
|
20
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
21
|
-
})
|
|
22
|
-
it('should return an object', async () => {
|
|
23
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
24
|
-
})
|
|
25
|
-
it('should return an object with an id', async () => {
|
|
26
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
27
|
-
})
|
|
28
|
-
it('should return an object with an id matching the origin', async () => {
|
|
29
|
-
assert.strictEqual(response.body.id, origin + '/')
|
|
30
|
-
})
|
|
31
|
-
it('should return an object with a publicKey', async () => {
|
|
32
|
-
assert.strictEqual(typeof response.body.publicKey, 'string')
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
describe('GET /publickey', async () => {
|
|
36
|
-
let response = null
|
|
37
|
-
it('should work without an error', async () => {
|
|
38
|
-
response = await request(app).get('/publickey')
|
|
39
|
-
})
|
|
40
|
-
it('should return 200 OK', async () => {
|
|
41
|
-
assert.strictEqual(response.status, 200)
|
|
42
|
-
})
|
|
43
|
-
it('should return AS2', async () => {
|
|
44
|
-
assert.strictEqual(response.type, 'application/activity+json')
|
|
45
|
-
})
|
|
46
|
-
it('should return an object', async () => {
|
|
47
|
-
assert.strictEqual(typeof response.body, 'object')
|
|
48
|
-
})
|
|
49
|
-
it('should return an object with an id', async () => {
|
|
50
|
-
assert.strictEqual(typeof response.body.id, 'string')
|
|
51
|
-
})
|
|
52
|
-
it('should return an object with an id matching the origin', async () => {
|
|
53
|
-
assert.strictEqual(response.body.id, origin + '/publickey')
|
|
54
|
-
})
|
|
55
|
-
it('should return an object with an owner', async () => {
|
|
56
|
-
assert.strictEqual(typeof response.body.owner, 'string')
|
|
57
|
-
})
|
|
58
|
-
it('should return an object with the origin as owner', async () => {
|
|
59
|
-
assert.strictEqual(response.body.owner, origin + '/')
|
|
60
|
-
})
|
|
61
|
-
it('should return an object with a publicKeyPem', async () => {
|
|
62
|
-
assert.strictEqual(typeof response.body.publicKeyPem, 'string')
|
|
63
|
-
})
|
|
64
|
-
it('publicKeyPem should be an RSA PKCS-8 key', async () => {
|
|
65
|
-
assert.match(response.body.publicKeyPem, /^-----BEGIN PUBLIC KEY-----\n/)
|
|
66
|
-
assert.match(response.body.publicKeyPem, /\n-----END PUBLIC KEY-----\n$/)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
})
|