1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
11 setAccessTokensToServers,
13 } from '../../shared/extra-utils'
14 import { VideoPrivacy } from '../../shared/models/videos'
16 const expect = chai.expect
18 describe('Test misc endpoints', function () {
19 let server: ServerInfo
21 before(async function () {
24 server = await flushAndRunServer(1)
25 await setAccessTokensToServers([ server ])
28 describe('Test a well known endpoints', function () {
30 it('Should get security.txt', async function () {
31 const res = await makeGetRequest({
33 path: '/.well-known/security.txt',
34 statusCodeExpected: HttpStatusCode.OK_200
37 expect(res.text).to.contain('security issue')
40 it('Should get nodeinfo', async function () {
41 const res = await makeGetRequest({
43 path: '/.well-known/nodeinfo',
44 statusCodeExpected: HttpStatusCode.OK_200
47 expect(res.body.links).to.be.an('array')
48 expect(res.body.links).to.have.lengthOf(1)
49 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
52 it('Should get dnt policy text', async function () {
53 const res = await makeGetRequest({
55 path: '/.well-known/dnt-policy.txt',
56 statusCodeExpected: HttpStatusCode.OK_200
59 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
62 it('Should get dnt policy', async function () {
63 const res = await makeGetRequest({
65 path: '/.well-known/dnt',
66 statusCodeExpected: HttpStatusCode.OK_200
69 expect(res.body.tracking).to.equal('N')
72 it('Should get change-password location', async function () {
73 const res = await makeGetRequest({
75 path: '/.well-known/change-password',
76 statusCodeExpected: HttpStatusCode.FOUND_302
79 expect(res.header.location).to.equal('/my-account/settings')
82 it('Should test webfinger', async function () {
83 const resource = 'acct:peertube@' + server.host
84 const accountUrl = server.url + '/accounts/peertube'
86 const res = await makeGetRequest({
88 path: '/.well-known/webfinger?resource=' + resource,
89 statusCodeExpected: HttpStatusCode.OK_200
94 expect(data.subject).to.equal(resource)
95 expect(data.aliases).to.contain(accountUrl)
97 const self = data.links.find(l => l.rel === 'self')
99 expect(self.type).to.equal('application/activity+json')
100 expect(self.href).to.equal(accountUrl)
102 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
103 expect(remoteInteract).to.exist
104 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
108 describe('Test classic static endpoints', function () {
110 it('Should get robots.txt', async function () {
111 const res = await makeGetRequest({
114 statusCodeExpected: HttpStatusCode.OK_200
117 expect(res.text).to.contain('User-agent')
120 it('Should get security.txt', async function () {
121 await makeGetRequest({
123 path: '/security.txt',
124 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
128 it('Should get nodeinfo', async function () {
129 const res = await makeGetRequest({
131 path: '/nodeinfo/2.0.json',
132 statusCodeExpected: HttpStatusCode.OK_200
135 expect(res.body.software.name).to.equal('peertube')
136 expect(res.body.usage.users.activeMonth).to.equal(1)
137 expect(res.body.usage.users.activeHalfyear).to.equal(1)
141 describe('Test bots endpoints', function () {
143 it('Should get the empty sitemap', async function () {
144 const res = await makeGetRequest({
146 path: '/sitemap.xml',
147 statusCodeExpected: HttpStatusCode.OK_200
150 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
151 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
154 it('Should get the empty cached sitemap', async function () {
155 const res = await makeGetRequest({
157 path: '/sitemap.xml',
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>')
165 it('Should add videos, channel and accounts and get sitemap', async function () {
168 await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
169 await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
170 await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
172 await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
173 await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
175 await server.usersCommand.create({ username: 'user1', password: 'password' })
176 await server.usersCommand.create({ username: 'user2', password: 'password' })
178 const res = await makeGetRequest({
180 path: '/sitemap.xml?t=1', // avoid using cache
181 statusCodeExpected: HttpStatusCode.OK_200
184 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
185 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
187 expect(res.text).to.contain('<video:title>video 1</video:title>')
188 expect(res.text).to.contain('<video:title>video 2</video:title>')
189 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
191 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
192 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
194 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
195 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
199 after(async function () {
200 await cleanupTests([ server ])