]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/misc-endpoints.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / server / tests / misc-endpoints.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
c2ad546d 2
86347717 3import { expect } from 'chai'
bf54587a 4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
4c7e60bc 5import { HttpStatusCode, VideoPrivacy } from '@shared/models'
2b32c5b3 6import { expectLogDoesNotContain } from './shared'
c2ad546d 7
c2ad546d 8describe('Test misc endpoints', function () {
254d3579 9 let server: PeerTubeServer
c2ad546d
C
10
11 before(async function () {
12 this.timeout(120000)
13
254d3579 14 server = await createSingleServer(1)
2feebf3e 15 await setAccessTokensToServers([ server ])
c2ad546d
C
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',
c0e8b12e 24 expectedStatus: HttpStatusCode.OK_200
c2ad546d
C
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',
c0e8b12e 34 expectedStatus: HttpStatusCode.OK_200
c2ad546d
C
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',
c0e8b12e 46 expectedStatus: HttpStatusCode.OK_200
c2ad546d
C
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',
c0e8b12e 56 expectedStatus: HttpStatusCode.OK_200
c2ad546d
C
57 })
58
59 expect(res.body.tracking).to.equal('N')
60 })
31414127
RK
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',
c0e8b12e 66 expectedStatus: HttpStatusCode.FOUND_302
31414127
RK
67 })
68
69 expect(res.header.location).to.equal('/my-account/settings')
70 })
d43c6b1f
C
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,
c0e8b12e 79 expectedStatus: HttpStatusCode.OK_200
d43c6b1f
C
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 })
c2ad546d
C
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',
c0e8b12e 104 expectedStatus: HttpStatusCode.OK_200
c2ad546d
C
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',
c0e8b12e 114 expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301
c2ad546d
C
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',
c0e8b12e 122 expectedStatus: HttpStatusCode.OK_200
c2ad546d
C
123 })
124
125 expect(res.body.software.name).to.equal('peertube')
47d8e266
C
126 expect(res.body.usage.users.activeMonth).to.equal(1)
127 expect(res.body.usage.users.activeHalfyear).to.equal(1)
c2ad546d
C
128 })
129 })
130
2feebf3e
C
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',
c0e8b12e 137 expectedStatus: HttpStatusCode.OK_200
2feebf3e
C
138 })
139
140 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
f4659d73 141 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
2feebf3e
C
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',
c0e8b12e 148 expectedStatus: HttpStatusCode.OK_200
2feebf3e
C
149 })
150
151 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
f4659d73 152 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
2feebf3e
C
153 })
154
155 it('Should add videos, channel and accounts and get sitemap', async function () {
156 this.timeout(35000)
157
89d241a7
C
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 } })
2feebf3e 161
89d241a7
C
162 await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
163 await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
2feebf3e 164
89d241a7
C
165 await server.users.create({ username: 'user1', password: 'password' })
166 await server.users.create({ username: 'user2', password: 'password' })
2feebf3e
C
167
168 const res = await makeGetRequest({
169 url: server.url,
170 path: '/sitemap.xml?t=1', // avoid using cache
c0e8b12e 171 expectedStatus: HttpStatusCode.OK_200
2feebf3e
C
172 })
173
174 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
f4659d73 175 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
2feebf3e 176
e39cfd1d
C
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>')
2feebf3e 180
f4659d73
C
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>')
2feebf3e 183
f4659d73
C
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>')
2feebf3e 186 })
2b32c5b3
C
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 })
2feebf3e
C
204 })
205
7c3b7976
C
206 after(async function () {
207 await cleanupTests([ server ])
c2ad546d
C
208 })
209})