]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/misc-endpoints.ts
Fix InvalidVideoTitle console warning
[github/Chocobozzz/PeerTube.git] / server / tests / misc-endpoints.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
6 import { expectLogDoesNotContain } from './shared'
7
8 describe('Test misc endpoints', function () {
9 let server: PeerTubeServer
10
11 before(async function () {
12 this.timeout(120000)
13
14 server = await createSingleServer(1)
15 await setAccessTokensToServers([ server ])
16 })
17
18 describe('Test a well known endpoints', function () {
19
20 it('Should get security.txt', async function () {
21 const res = await makeGetRequest({
22 url: server.url,
23 path: '/.well-known/security.txt',
24 expectedStatus: HttpStatusCode.OK_200
25 })
26
27 expect(res.text).to.contain('security issue')
28 })
29
30 it('Should get nodeinfo', async function () {
31 const res = await makeGetRequest({
32 url: server.url,
33 path: '/.well-known/nodeinfo',
34 expectedStatus: HttpStatusCode.OK_200
35 })
36
37 expect(res.body.links).to.be.an('array')
38 expect(res.body.links).to.have.lengthOf(1)
39 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
40 })
41
42 it('Should get dnt policy text', async function () {
43 const res = await makeGetRequest({
44 url: server.url,
45 path: '/.well-known/dnt-policy.txt',
46 expectedStatus: HttpStatusCode.OK_200
47 })
48
49 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
50 })
51
52 it('Should get dnt policy', async function () {
53 const res = await makeGetRequest({
54 url: server.url,
55 path: '/.well-known/dnt',
56 expectedStatus: HttpStatusCode.OK_200
57 })
58
59 expect(res.body.tracking).to.equal('N')
60 })
61
62 it('Should get change-password location', async function () {
63 const res = await makeGetRequest({
64 url: server.url,
65 path: '/.well-known/change-password',
66 expectedStatus: HttpStatusCode.FOUND_302
67 })
68
69 expect(res.header.location).to.equal('/my-account/settings')
70 })
71
72 it('Should test webfinger', async function () {
73 const resource = 'acct:peertube@' + server.host
74 const accountUrl = server.url + '/accounts/peertube'
75
76 const res = await makeGetRequest({
77 url: server.url,
78 path: '/.well-known/webfinger?resource=' + resource,
79 expectedStatus: HttpStatusCode.OK_200
80 })
81
82 const data = res.body
83
84 expect(data.subject).to.equal(resource)
85 expect(data.aliases).to.contain(accountUrl)
86
87 const self = data.links.find(l => l.rel === 'self')
88 expect(self).to.exist
89 expect(self.type).to.equal('application/activity+json')
90 expect(self.href).to.equal(accountUrl)
91
92 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
93 expect(remoteInteract).to.exist
94 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
95 })
96 })
97
98 describe('Test classic static endpoints', function () {
99
100 it('Should get robots.txt', async function () {
101 const res = await makeGetRequest({
102 url: server.url,
103 path: '/robots.txt',
104 expectedStatus: HttpStatusCode.OK_200
105 })
106
107 expect(res.text).to.contain('User-agent')
108 })
109
110 it('Should get security.txt', async function () {
111 await makeGetRequest({
112 url: server.url,
113 path: '/security.txt',
114 expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301
115 })
116 })
117
118 it('Should get nodeinfo', async function () {
119 const res = await makeGetRequest({
120 url: server.url,
121 path: '/nodeinfo/2.0.json',
122 expectedStatus: HttpStatusCode.OK_200
123 })
124
125 expect(res.body.software.name).to.equal('peertube')
126 expect(res.body.usage.users.activeMonth).to.equal(1)
127 expect(res.body.usage.users.activeHalfyear).to.equal(1)
128 })
129 })
130
131 describe('Test bots endpoints', function () {
132
133 it('Should get the empty sitemap', async function () {
134 const res = await makeGetRequest({
135 url: server.url,
136 path: '/sitemap.xml',
137 expectedStatus: HttpStatusCode.OK_200
138 })
139
140 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
141 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
142 })
143
144 it('Should get the empty cached sitemap', async function () {
145 const res = await makeGetRequest({
146 url: server.url,
147 path: '/sitemap.xml',
148 expectedStatus: HttpStatusCode.OK_200
149 })
150
151 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
152 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
153 })
154
155 it('Should add videos, channel and accounts and get sitemap', async function () {
156 this.timeout(35000)
157
158 await server.videos.upload({ attributes: { name: 'video 1', nsfw: false } })
159 await server.videos.upload({ attributes: { name: 'video 2', nsfw: false } })
160 await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
161
162 await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
163 await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
164
165 await server.users.create({ username: 'user1', password: 'password' })
166 await server.users.create({ username: 'user2', password: 'password' })
167
168 const res = await makeGetRequest({
169 url: server.url,
170 path: '/sitemap.xml?t=1', // avoid using cache
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>http://localhost:' + server.port + '/about/instance</loc></url>')
176
177 expect(res.text).to.contain('<video:title>video 1</video:title>')
178 expect(res.text).to.contain('<video:title>video 2</video:title>')
179 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
180
181 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
182 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
183
184 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
185 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
186 })
187
188 it('Should not fail with big title/description videos', async function () {
189 const name = 'v'.repeat(115)
190
191 await server.videos.upload({ attributes: { name, description: 'd'.repeat(2500), nsfw: false } })
192
193 const res = await makeGetRequest({
194 url: server.url,
195 path: '/sitemap.xml?t=2', // avoid using cache
196 expectedStatus: HttpStatusCode.OK_200
197 })
198
199 await expectLogDoesNotContain(server, 'Warning in sitemap generation')
200 await expectLogDoesNotContain(server, 'Error in sitemap generation')
201
202 expect(res.text).to.contain(`<video:title>${'v'.repeat(97)}...</video:title>`)
203 })
204 })
205
206 after(async function () {
207 await cleanupTests([ server ])
208 })
209 })