1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
12 setAccessTokensToServers,
14 } from '../../shared/extra-utils'
15 import { VideoPrivacy } from '../../shared/models/videos'
17 const expect = chai.expect
19 describe('Test misc endpoints', function () {
20 let server: ServerInfo
22 before(async function () {
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
29 describe('Test a well known endpoints', function () {
31 it('Should get security.txt', async function () {
32 const res = await makeGetRequest({
34 path: '/.well-known/security.txt',
35 statusCodeExpected: 200
38 expect(res.text).to.contain('security issue')
41 it('Should get nodeinfo', async function () {
42 const res = await makeGetRequest({
44 path: '/.well-known/nodeinfo',
45 statusCodeExpected: 200
48 expect(res.body.links).to.be.an('array')
49 expect(res.body.links).to.have.lengthOf(1)
50 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
53 it('Should get dnt policy text', async function () {
54 const res = await makeGetRequest({
56 path: '/.well-known/dnt-policy.txt',
57 statusCodeExpected: 200
60 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
63 it('Should get dnt policy', async function () {
64 const res = await makeGetRequest({
66 path: '/.well-known/dnt',
67 statusCodeExpected: 200
70 expect(res.body.tracking).to.equal('N')
73 it('Should get change-password location', async function () {
74 const res = await makeGetRequest({
76 path: '/.well-known/change-password',
77 statusCodeExpected: 302
80 expect(res.header.location).to.equal('/my-account/settings')
84 describe('Test classic static endpoints', function () {
86 it('Should get robots.txt', async function () {
87 const res = await makeGetRequest({
90 statusCodeExpected: 200
93 expect(res.text).to.contain('User-agent')
96 it('Should get security.txt', async function () {
97 await makeGetRequest({
99 path: '/security.txt',
100 statusCodeExpected: 301
104 it('Should get nodeinfo', async function () {
105 const res = await makeGetRequest({
107 path: '/nodeinfo/2.0.json',
108 statusCodeExpected: 200
111 expect(res.body.software.name).to.equal('peertube')
115 describe('Test bots endpoints', function () {
117 it('Should get the empty sitemap', async function () {
118 const res = await makeGetRequest({
120 path: '/sitemap.xml',
121 statusCodeExpected: 200
124 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
125 expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
128 it('Should get the empty cached sitemap', async function () {
129 const res = await makeGetRequest({
131 path: '/sitemap.xml',
132 statusCodeExpected: 200
135 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
136 expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
139 it('Should add videos, channel and accounts and get sitemap', async function () {
142 await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
143 await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
144 await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
146 await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
147 await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
149 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
150 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
152 const res = await makeGetRequest({
154 path: '/sitemap.xml?t=1', // avoid using cache
155 statusCodeExpected: 200
158 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
159 expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
161 expect(res.text).to.contain('<video:title><![CDATA[video 1]]></video:title>')
162 expect(res.text).to.contain('<video:title><![CDATA[video 2]]></video:title>')
163 expect(res.text).to.not.contain('<video:title><![CDATA[video 3]]></video:title>')
165 expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel1</loc></url>')
166 expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel2</loc></url>')
168 expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user1</loc></url>')
169 expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user2</loc></url>')
173 after(async function () {
174 await cleanupTests([ server ])