diff options
Diffstat (limited to 'server/tests/misc-endpoints.ts')
-rw-r--r-- | server/tests/misc-endpoints.ts | 237 |
1 files changed, 0 insertions, 237 deletions
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts deleted file mode 100644 index f9cf2b717..000000000 --- a/server/tests/misc-endpoints.ts +++ /dev/null | |||
@@ -1,237 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { writeJson } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | ||
7 | import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
8 | import { expectLogDoesNotContain } from './shared' | ||
9 | |||
10 | describe('Test misc endpoints', function () { | ||
11 | let server: PeerTubeServer | ||
12 | let wellKnownPath: string | ||
13 | |||
14 | before(async function () { | ||
15 | this.timeout(120000) | ||
16 | |||
17 | server = await createSingleServer(1) | ||
18 | |||
19 | await setAccessTokensToServers([ server ]) | ||
20 | |||
21 | wellKnownPath = server.getDirectoryPath('well-known') | ||
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', | ||
30 | expectedStatus: HttpStatusCode.OK_200 | ||
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', | ||
40 | expectedStatus: HttpStatusCode.OK_200 | ||
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', | ||
52 | expectedStatus: HttpStatusCode.OK_200 | ||
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', | ||
62 | expectedStatus: HttpStatusCode.OK_200 | ||
63 | }) | ||
64 | |||
65 | expect(res.body.tracking).to.equal('N') | ||
66 | }) | ||
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', | ||
72 | expectedStatus: HttpStatusCode.FOUND_302 | ||
73 | }) | ||
74 | |||
75 | expect(res.header.location).to.equal('/my-account/settings') | ||
76 | }) | ||
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, | ||
85 | expectedStatus: HttpStatusCode.OK_200 | ||
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 | }) | ||
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 | }) | ||
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', | ||
132 | expectedStatus: HttpStatusCode.OK_200 | ||
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', | ||
142 | expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301 | ||
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', | ||
150 | expectedStatus: HttpStatusCode.OK_200 | ||
151 | }) | ||
152 | |||
153 | expect(res.body.software.name).to.equal('peertube') | ||
154 | expect(res.body.usage.users.activeMonth).to.equal(1) | ||
155 | expect(res.body.usage.users.activeHalfyear).to.equal(1) | ||
156 | }) | ||
157 | }) | ||
158 | |||
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', | ||
165 | expectedStatus: HttpStatusCode.OK_200 | ||
166 | }) | ||
167 | |||
168 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | ||
169 | expect(res.text).to.contain('<url><loc>' + server.url + '/about/instance</loc></url>') | ||
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', | ||
176 | expectedStatus: HttpStatusCode.OK_200 | ||
177 | }) | ||
178 | |||
179 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | ||
180 | expect(res.text).to.contain('<url><loc>' + server.url + '/about/instance</loc></url>') | ||
181 | }) | ||
182 | |||
183 | it('Should add videos, channel and accounts and get sitemap', async function () { | ||
184 | this.timeout(35000) | ||
185 | |||
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 } }) | ||
189 | |||
190 | await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) | ||
191 | await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) | ||
192 | |||
193 | await server.users.create({ username: 'user1', password: 'password' }) | ||
194 | await server.users.create({ username: 'user2', password: 'password' }) | ||
195 | |||
196 | const res = await makeGetRequest({ | ||
197 | url: server.url, | ||
198 | path: '/sitemap.xml?t=1', // avoid using cache | ||
199 | expectedStatus: HttpStatusCode.OK_200 | ||
200 | }) | ||
201 | |||
202 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | ||
203 | expect(res.text).to.contain('<url><loc>' + server.url + '/about/instance</loc></url>') | ||
204 | |||
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>') | ||
208 | |||
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>') | ||
211 | |||
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>') | ||
214 | }) | ||
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 | }) | ||
232 | }) | ||
233 | |||
234 | after(async function () { | ||
235 | await cleanupTests([ server ]) | ||
236 | }) | ||
237 | }) | ||