-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_webfinger.ts
More file actions
61 lines (49 loc) · 1.79 KB
/
test_webfinger.ts
File metadata and controls
61 lines (49 loc) · 1.79 KB
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
import assert from 'node:assert/strict'
import { after, beforeEach, describe, it } from 'node:test'
import { BaseApiClient } from './base.ts'
import { WEBFINGER_ALIASES, WEBFINGER_LINKS } from '../../server/meta/webfinger.ts'
describe('/.well-known/webfinger', function () {
let client: BaseApiClient
beforeEach(async function () {
if (client) {
await client.reset()
} else {
client = await BaseApiClient.initialize()
}
})
after(async function () {
await client?.finalize()
})
it('errors out with 400 if no resource is requested', async function () {
const response = await client.get('/.well-known/webfinger')
assert.equal(response.status(), 400)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 400, details: 'No resource requested.' },
)
})
it('errors out with 404 if an unknown resource is requested', async function () {
const response = await client.get('/.well-known/webfinger?resource=unknown')
assert.equal(response.status(), 404)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 404, details: 'The requested resource was not found.' },
)
})
it('retrieves the expected data when requested', async function () {
for (let i = 0; i < WEBFINGER_ALIASES.length; i++) {
const resource = WEBFINGER_ALIASES[i]
const response = await client.get(`/.well-known/webfinger?resource=${resource}`)
assert.equal(response.headers()['content-type'], 'application/jrd+json; charset=utf-8')
const expected = {
subject: resource,
aliases: [...WEBFINGER_ALIASES.slice(0, i), ...WEBFINGER_ALIASES.slice(i + 1)],
links: WEBFINGER_LINKS,
}
assert.deepEqual(
await response.json(),
expected,
)
}
})
})