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