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