-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathap.test.js
175 lines (150 loc) · 6.93 KB
/
ap.test.js
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
const request = require('supertest')
const dayjs = require('dayjs')
const path = require('path')
const admin = { username: 'admin', password: 'test', grant_type: 'password', client_id: 'self' }
let token
let app
let places = []
beforeAll(async () => {
switch (process.env.DB) {
case 'mariadb':
process.env.config_path = path.resolve(__dirname, './seeds/config.mariadb.json')
break
case 'postgresql':
process.env.config_path = path.resolve(__dirname, './seeds/config.postgres.json')
break
case 'sqlite':
default:
process.env.config_path = path.resolve(__dirname, './seeds/config.sqlite.json')
}
try {
app = await require('../server/routes.js').main()
const { sequelize } = require('../server/api/models/index')
const { col } = require('../server/helpers')
// sequelize.sync({ force: true })
// await sequelize.query('PRAGMA foreign_keys = OFF')
await sequelize.query('DELETE FROM settings')
await sequelize.query(`DELETE FROM ${col('user_followers')}`)
await sequelize.query(`DELETE FROM ${col('events')} where ${col('parentId')} IS NOT NULL`)
await sequelize.query('DELETE FROM ap_users')
await sequelize.query('DELETE FROM events')
await sequelize.query('DELETE FROM event_tags')
await sequelize.query('DELETE FROM resources')
await sequelize.query('DELETE FROM instances')
await sequelize.query('DELETE FROM announcements')
await sequelize.query('DELETE FROM oauth_tokens')
await sequelize.query('DELETE FROM users')
await sequelize.query('DELETE FROM tags')
await sequelize.query('DELETE FROM places')
await sequelize.query('DELETE FROM filters')
await sequelize.query('DELETE FROM collections')
await sequelize.query('DELETE FROM notifications')
await sequelize.query('DELETE FROM tasks')
// await sequelize.query('PRAGMA foreign_keys = ON')
} catch (e) {
console.error(e)
}
})
afterAll(async () => {
await require('../server/initialize.server.js').shutdown(false)
})
describe('Nodeinfo', () => {
test('shoud return a json content', async () => {
const response = await request(app).get('/.well-known/nodeinfo')
.expect('Content-Type', /application\/json/)
.expect(200)
})
test('shoud support nodeinfo 2.0 and 2.1', async () => {
const response = await request(app).get('/.well-known/nodeinfo')
.expect('Content-Type', /application\/json/)
.expect(200)
expect(response.body.links.find(l => l.rel === 'http://nodeinfo.diaspora.software/ns/schema/2.0').href).toBe('http://localhost:13120/.well-known/nodeinfo/2.0')
expect(response.body.links.find(l => l.rel === 'http://nodeinfo.diaspora.software/ns/schema/2.1').href).toBe('http://localhost:13120/.well-known/nodeinfo/2.1')
})
test('shoud implement FEP-2677 - Application Actor', async () => {
const response = await request(app).get('/.well-known/nodeinfo')
.expect('Content-Type', /application\/json/)
.expect(200)
expect(response.body.links.find(l => l.rel === 'https://www.w3.org/ns/activitystreams#Application').href).toBe('http://localhost:13120/federation/u/relay')
})
})
describe('Webfinger', () => {
test('should return a 404 on bad request', () => {
request(app).get('/.well-known/webfinger')
.expect(400)
})
test('should return webfinger response', async () => {
const response = await request(app).get('/.well-known/webfinger?resource=acct:relay@localhost:13120')
.expect(200)
.expect('Content-Type', 'application/jrd+json; charset=utf-8')
expect(response.body.subject).toBe('acct:relay@localhost:13120')
})
})
describe('AP', () => {
test('should return the AP Actor', async () => {
const response = await request(app).get('/federation/u/relay')
.expect(200)
.expect('Content-Type', /json/)
expect(response.body.type).toBe('Application')
})
describe('Location', () => {
test('should fail parsing a location without a name', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/bad-location-without-a-name.json')
expect(parsePlace({ location })).rejects.toThrow()
})
test ('should parse a location with only a name', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/physical-location-without-id.json')
let [place] = await parsePlace({ location })
expect(place.name).toBe('Location without id')
expect(place.ap_id).toBeUndefined()
expect(place.id).toBe(1)
})
test ('should parse a location with id and name', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/physical-location-no-address.json')
let [place] = await parsePlace({ location })
expect(place.name).toBe('Location with a name')
expect(place.address).toBe('Location with a name')
expect(place.id).toBe(2)
})
test ('should parse a location with a simple string address', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/physical-location-with-simple-string-address.json')
let [place] = await parsePlace({ location })
expect(place.name).toBe('Location with a simple string address')
})
test ('should parse a location with a postal address', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/physical-location-with-postal-address.json')
let [place] = await parsePlace({ location })
expect(place.name).toBe('Location with a postal address')
})
test ('should parse a virtual location', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/virtual-location.json')
let [place, online_locations] = await parsePlace({ location })
expect(place.name).toBe('online')
expect(online_locations.length).toBe(1)
expect(online_locations[0]).toBe("https://virtual.location.org")
})
test ('should parse a mixed location', async () => {
const { parsePlace } = require('../server/federation/helpers.js')
const location = require('./fixtures/AP-location/multiple-mixed-locations.json')
let [place, online_locations] = await parsePlace({ location })
expect(place.name).toBe('Location with a name')
expect(online_locations.length).toBe(2)
expect(online_locations[0]).toBe('https://virtual.location.org')
})
})
// test('should not allow to create a new Event from a random instance', async () => {
// const response = await request(app)
// .post('/federation/u/relay/inbox')
// .send({
// actor: 'http://localhost:13120/federation/u/relay'
// })
// .expect(401)
// console.error(response)
// })
})