aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/misc-endpoints.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/misc-endpoints.ts')
-rw-r--r--packages/tests/src/misc-endpoints.ts243
1 files changed, 243 insertions, 0 deletions
diff --git a/packages/tests/src/misc-endpoints.ts b/packages/tests/src/misc-endpoints.ts
new file mode 100644
index 000000000..0067578ed
--- /dev/null
+++ b/packages/tests/src/misc-endpoints.ts
@@ -0,0 +1,243 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { writeJson } from 'fs-extra/esm'
5import { join } from 'path'
6import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
7import {
8 cleanupTests,
9 createSingleServer,
10 makeGetRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@peertube/peertube-server-commands'
14import { expectLogDoesNotContain } from './shared/checks.js'
15
16describe('Test misc endpoints', function () {
17 let server: PeerTubeServer
18 let wellKnownPath: string
19
20 before(async function () {
21 this.timeout(120000)
22
23 server = await createSingleServer(1)
24
25 await setAccessTokensToServers([ server ])
26
27 wellKnownPath = server.getDirectoryPath('well-known')
28 })
29
30 describe('Test a well known endpoints', function () {
31
32 it('Should get security.txt', async function () {
33 const res = await makeGetRequest({
34 url: server.url,
35 path: '/.well-known/security.txt',
36 expectedStatus: HttpStatusCode.OK_200
37 })
38
39 expect(res.text).to.contain('security issue')
40 })
41
42 it('Should get nodeinfo', async function () {
43 const res = await makeGetRequest({
44 url: server.url,
45 path: '/.well-known/nodeinfo',
46 expectedStatus: HttpStatusCode.OK_200
47 })
48
49 expect(res.body.links).to.be.an('array')
50 expect(res.body.links).to.have.lengthOf(1)
51 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
52 })
53
54 it('Should get dnt policy text', async function () {
55 const res = await makeGetRequest({
56 url: server.url,
57 path: '/.well-known/dnt-policy.txt',
58 expectedStatus: HttpStatusCode.OK_200
59 })
60
61 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
62 })
63
64 it('Should get dnt policy', async function () {
65 const res = await makeGetRequest({
66 url: server.url,
67 path: '/.well-known/dnt',
68 expectedStatus: HttpStatusCode.OK_200
69 })
70
71 expect(res.body.tracking).to.equal('N')
72 })
73
74 it('Should get change-password location', async function () {
75 const res = await makeGetRequest({
76 url: server.url,
77 path: '/.well-known/change-password',
78 expectedStatus: HttpStatusCode.FOUND_302
79 })
80
81 expect(res.header.location).to.equal('/my-account/settings')
82 })
83
84 it('Should test webfinger', async function () {
85 const resource = 'acct:peertube@' + server.host
86 const accountUrl = server.url + '/accounts/peertube'
87
88 const res = await makeGetRequest({
89 url: server.url,
90 path: '/.well-known/webfinger?resource=' + resource,
91 expectedStatus: HttpStatusCode.OK_200
92 })
93
94 const data = res.body
95
96 expect(data.subject).to.equal(resource)
97 expect(data.aliases).to.contain(accountUrl)
98
99 const self = data.links.find(l => l.rel === 'self')
100 expect(self).to.exist
101 expect(self.type).to.equal('application/activity+json')
102 expect(self.href).to.equal(accountUrl)
103
104 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
105 expect(remoteInteract).to.exist
106 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
107 })
108
109 it('Should return 404 for non-existing files in /.well-known', async function () {
110 await makeGetRequest({
111 url: server.url,
112 path: '/.well-known/non-existing-file',
113 expectedStatus: HttpStatusCode.NOT_FOUND_404
114 })
115 })
116
117 it('Should return custom file from /.well-known', async function () {
118 const filename = 'existing-file.json'
119
120 await writeJson(join(wellKnownPath, filename), { iThink: 'therefore I am' })
121
122 const { body } = await makeGetRequest({
123 url: server.url,
124 path: '/.well-known/' + filename,
125 expectedStatus: HttpStatusCode.OK_200
126 })
127
128 expect(body.iThink).to.equal('therefore I am')
129 })
130 })
131
132 describe('Test classic static endpoints', function () {
133
134 it('Should get robots.txt', async function () {
135 const res = await makeGetRequest({
136 url: server.url,
137 path: '/robots.txt',
138 expectedStatus: HttpStatusCode.OK_200
139 })
140
141 expect(res.text).to.contain('User-agent')
142 })
143
144 it('Should get security.txt', async function () {
145 await makeGetRequest({
146 url: server.url,
147 path: '/security.txt',
148 expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301
149 })
150 })
151
152 it('Should get nodeinfo', async function () {
153 const res = await makeGetRequest({
154 url: server.url,
155 path: '/nodeinfo/2.0.json',
156 expectedStatus: HttpStatusCode.OK_200
157 })
158
159 expect(res.body.software.name).to.equal('peertube')
160 expect(res.body.usage.users.activeMonth).to.equal(1)
161 expect(res.body.usage.users.activeHalfyear).to.equal(1)
162 })
163 })
164
165 describe('Test bots endpoints', function () {
166
167 it('Should get the empty sitemap', async function () {
168 const res = await makeGetRequest({
169 url: server.url,
170 path: '/sitemap.xml',
171 expectedStatus: HttpStatusCode.OK_200
172 })
173
174 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
175 expect(res.text).to.contain('<url><loc>' + server.url + '/about/instance</loc></url>')
176 })
177
178 it('Should get the empty cached sitemap', async function () {
179 const res = await makeGetRequest({
180 url: server.url,
181 path: '/sitemap.xml',
182 expectedStatus: HttpStatusCode.OK_200
183 })
184
185 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
186 expect(res.text).to.contain('<url><loc>' + server.url + '/about/instance</loc></url>')
187 })
188
189 it('Should add videos, channel and accounts and get sitemap', async function () {
190 this.timeout(35000)
191
192 await server.videos.upload({ attributes: { name: 'video 1', nsfw: false } })
193 await server.videos.upload({ attributes: { name: 'video 2', nsfw: false } })
194 await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
195
196 await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
197 await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
198
199 await server.users.create({ username: 'user1', password: 'password' })
200 await server.users.create({ username: 'user2', password: 'password' })
201
202 const res = await makeGetRequest({
203 url: server.url,
204 path: '/sitemap.xml?t=1', // avoid using cache
205 expectedStatus: HttpStatusCode.OK_200
206 })
207
208 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
209 expect(res.text).to.contain('<url><loc>' + server.url + '/about/instance</loc></url>')
210
211 expect(res.text).to.contain('<video:title>video 1</video:title>')
212 expect(res.text).to.contain('<video:title>video 2</video:title>')
213 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
214
215 expect(res.text).to.contain('<url><loc>' + server.url + '/video-channels/channel1</loc></url>')
216 expect(res.text).to.contain('<url><loc>' + server.url + '/video-channels/channel2</loc></url>')
217
218 expect(res.text).to.contain('<url><loc>' + server.url + '/accounts/user1</loc></url>')
219 expect(res.text).to.contain('<url><loc>' + server.url + '/accounts/user2</loc></url>')
220 })
221
222 it('Should not fail with big title/description videos', async function () {
223 const name = 'v'.repeat(115)
224
225 await server.videos.upload({ attributes: { name, description: 'd'.repeat(2500), nsfw: false } })
226
227 const res = await makeGetRequest({
228 url: server.url,
229 path: '/sitemap.xml?t=2', // avoid using cache
230 expectedStatus: HttpStatusCode.OK_200
231 })
232
233 await expectLogDoesNotContain(server, 'Warning in sitemap generation')
234 await expectLogDoesNotContain(server, 'Error in sitemap generation')
235
236 expect(res.text).to.contain(`<video:title>${'v'.repeat(97)}...</video:title>`)
237 })
238 })
239
240 after(async function () {
241 await cleanupTests([ server ])
242 })
243})