Merge branch 'hotfix/docker' into develop
[oweals/peertube.git] / server / tests / misc-endpoints.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6   addVideoChannel,
7   createUser,
8   flushTests,
9   killallServers,
10   makeGetRequest,
11   runServer,
12   ServerInfo,
13   setAccessTokensToServers,
14   uploadVideo
15 } from './utils'
16 import { VideoPrivacy } from '../../shared/models/videos'
17
18 const expect = chai.expect
19
20 describe('Test misc endpoints', function () {
21   let server: ServerInfo
22
23   before(async function () {
24     this.timeout(120000)
25
26     await flushTests()
27
28     server = await runServer(1)
29     await setAccessTokensToServers([ server ])
30   })
31
32   describe('Test a well known endpoints', function () {
33
34     it('Should get security.txt', async function () {
35       const res = await makeGetRequest({
36         url: server.url,
37         path: '/.well-known/security.txt',
38         statusCodeExpected: 200
39       })
40
41       expect(res.text).to.contain('security issue')
42     })
43
44     it('Should get nodeinfo', async function () {
45       const res = await makeGetRequest({
46         url: server.url,
47         path: '/.well-known/nodeinfo',
48         statusCodeExpected: 200
49       })
50
51       expect(res.body.links).to.be.an('array')
52       expect(res.body.links).to.have.lengthOf(1)
53       expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
54     })
55
56     it('Should get dnt policy text', async function () {
57       const res = await makeGetRequest({
58         url: server.url,
59         path: '/.well-known/dnt-policy.txt',
60         statusCodeExpected: 200
61       })
62
63       expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
64     })
65
66     it('Should get dnt policy', async function () {
67       const res = await makeGetRequest({
68         url: server.url,
69         path: '/.well-known/dnt',
70         statusCodeExpected: 200
71       })
72
73       expect(res.body.tracking).to.equal('N')
74     })
75   })
76
77   describe('Test classic static endpoints', function () {
78
79     it('Should get robots.txt', async function () {
80       const res = await makeGetRequest({
81         url: server.url,
82         path: '/robots.txt',
83         statusCodeExpected: 200
84       })
85
86       expect(res.text).to.contain('User-agent')
87     })
88
89     it('Should get security.txt', async function () {
90       await makeGetRequest({
91         url: server.url,
92         path: '/security.txt',
93         statusCodeExpected: 301
94       })
95     })
96
97     it('Should get nodeinfo', async function () {
98       const res = await makeGetRequest({
99         url: server.url,
100         path: '/nodeinfo/2.0.json',
101         statusCodeExpected: 200
102       })
103
104       expect(res.body.software.name).to.equal('peertube')
105     })
106   })
107
108   describe('Test bots endpoints', function () {
109
110     it('Should get the empty sitemap', async function () {
111       const res = await makeGetRequest({
112         url: server.url,
113         path: '/sitemap.xml',
114         statusCodeExpected: 200
115       })
116
117       expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
118       expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
119     })
120
121     it('Should get the empty cached sitemap', async function () {
122       const res = await makeGetRequest({
123         url: server.url,
124         path: '/sitemap.xml',
125         statusCodeExpected: 200
126       })
127
128       expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
129       expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
130     })
131
132     it('Should add videos, channel and accounts and get sitemap', async function () {
133       this.timeout(35000)
134
135       await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
136       await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
137       await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
138
139       await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
140       await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
141
142       await createUser(server.url, server.accessToken, 'user1', 'password')
143       await createUser(server.url, server.accessToken, 'user2', 'password')
144
145       const res = await makeGetRequest({
146         url: server.url,
147         path: '/sitemap.xml?t=1', // avoid using cache
148         statusCodeExpected: 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:9001/about/instance</loc></url>')
153
154       expect(res.text).to.contain('<video:title><![CDATA[video 1]]></video:title>')
155       expect(res.text).to.contain('<video:title><![CDATA[video 2]]></video:title>')
156       expect(res.text).to.not.contain('<video:title><![CDATA[video 3]]></video:title>')
157
158       expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel1</loc></url>')
159       expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel2</loc></url>')
160
161       expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user1</loc></url>')
162       expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user2</loc></url>')
163     })
164   })
165
166   after(async function () {
167     killallServers([ server ])
168   })
169 })