1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 setAccessTokensToServers,
14 } from '../../shared/extra-utils'
15 import { VideoPrivacy } from '../../shared/models/videos'
16 import { HttpStatusCode } from '@shared/core-utils'
18 const expect = chai.expect
20 describe('Test misc endpoints', function () {
21 let server: ServerInfo
23 before(async function () {
26 server = await flushAndRunServer(1)
27 await setAccessTokensToServers([ server ])
30 describe('Test a well known endpoints', function () {
32 it('Should get security.txt', async function () {
33 const res = await makeGetRequest({
35 path: '/.well-known/security.txt',
36 statusCodeExpected: HttpStatusCode.OK_200
39 expect(res.text).to.contain('security issue')
42 it('Should get nodeinfo', async function () {
43 const res = await makeGetRequest({
45 path: '/.well-known/nodeinfo',
46 statusCodeExpected: HttpStatusCode.OK_200
49 expect(res.body.links).to.be.an('array')
50 expect(res.body.links).to.have.lengthOf(1)
51 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
54 it('Should get dnt policy text', async function () {
55 const res = await makeGetRequest({
57 path: '/.well-known/dnt-policy.txt',
58 statusCodeExpected: HttpStatusCode.OK_200
61 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
64 it('Should get dnt policy', async function () {
65 const res = await makeGetRequest({
67 path: '/.well-known/dnt',
68 statusCodeExpected: HttpStatusCode.OK_200
71 expect(res.body.tracking).to.equal('N')
74 it('Should get change-password location', async function () {
75 const res = await makeGetRequest({
77 path: '/.well-known/change-password',
78 statusCodeExpected: HttpStatusCode.FOUND_302
81 expect(res.header.location).to.equal('/my-account/settings')
85 describe('Test classic static endpoints', function () {
87 it('Should get robots.txt', async function () {
88 const res = await makeGetRequest({
91 statusCodeExpected: HttpStatusCode.OK_200
94 expect(res.text).to.contain('User-agent')
97 it('Should get security.txt', async function () {
98 await makeGetRequest({
100 path: '/security.txt',
101 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
105 it('Should get nodeinfo', async function () {
106 const res = await makeGetRequest({
108 path: '/nodeinfo/2.0.json',
109 statusCodeExpected: HttpStatusCode.OK_200
112 expect(res.body.software.name).to.equal('peertube')
113 expect(res.body.usage.users.activeMonth).to.equal(1)
114 expect(res.body.usage.users.activeHalfyear).to.equal(1)
118 describe('Test bots endpoints', function () {
120 it('Should get the empty sitemap', async function () {
121 const res = await makeGetRequest({
123 path: '/sitemap.xml',
124 statusCodeExpected: HttpStatusCode.OK_200
127 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
128 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
131 it('Should get the empty cached sitemap', async function () {
132 const res = await makeGetRequest({
134 path: '/sitemap.xml',
135 statusCodeExpected: HttpStatusCode.OK_200
138 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
139 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
142 it('Should add videos, channel and accounts and get sitemap', async function () {
145 await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
146 await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
147 await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
149 await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
150 await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
152 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
153 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
155 const res = await makeGetRequest({
157 path: '/sitemap.xml?t=1', // avoid using cache
158 statusCodeExpected: HttpStatusCode.OK_200
161 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
162 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
164 expect(res.text).to.contain('<video:title>video 1</video:title>')
165 expect(res.text).to.contain('<video:title>video 2</video:title>')
166 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
168 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
169 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
171 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
172 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
176 after(async function () {
177 await cleanupTests([ server ])