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'
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: HttpStatusCode.OK_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: HttpStatusCode.OK_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: HttpStatusCode.OK_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: HttpStatusCode.OK_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: HttpStatusCode.FOUND_302
80 expect(res.header.location).to.equal('/my-account/settings')
83 it('Should test webfinger', async function () {
84 const resource = 'acct:peertube@' + server.host
85 const accountUrl = server.url + '/accounts/peertube'
87 const res = await makeGetRequest({
89 path: '/.well-known/webfinger?resource=' + resource,
90 statusCodeExpected: HttpStatusCode.OK_200
95 expect(data.subject).to.equal(resource)
96 expect(data.aliases).to.contain(accountUrl)
98 const self = data.links.find(l => l.rel === 'self')
100 expect(self.type).to.equal('application/activity+json')
101 expect(self.href).to.equal(accountUrl)
103 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
104 expect(remoteInteract).to.exist
105 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
109 describe('Test classic static endpoints', function () {
111 it('Should get robots.txt', async function () {
112 const res = await makeGetRequest({
115 statusCodeExpected: HttpStatusCode.OK_200
118 expect(res.text).to.contain('User-agent')
121 it('Should get security.txt', async function () {
122 await makeGetRequest({
124 path: '/security.txt',
125 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
129 it('Should get nodeinfo', async function () {
130 const res = await makeGetRequest({
132 path: '/nodeinfo/2.0.json',
133 statusCodeExpected: HttpStatusCode.OK_200
136 expect(res.body.software.name).to.equal('peertube')
137 expect(res.body.usage.users.activeMonth).to.equal(1)
138 expect(res.body.usage.users.activeHalfyear).to.equal(1)
142 describe('Test bots endpoints', function () {
144 it('Should get the empty sitemap', async function () {
145 const res = await makeGetRequest({
147 path: '/sitemap.xml',
148 statusCodeExpected: HttpStatusCode.OK_200
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:' + server.port + '/about/instance</loc></url>')
155 it('Should get the empty cached sitemap', async function () {
156 const res = await makeGetRequest({
158 path: '/sitemap.xml',
159 statusCodeExpected: HttpStatusCode.OK_200
162 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
163 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
166 it('Should add videos, channel and accounts and get sitemap', async function () {
169 await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
170 await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
171 await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
173 await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
174 await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
176 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
177 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
179 const res = await makeGetRequest({
181 path: '/sitemap.xml?t=1', // avoid using cache
182 statusCodeExpected: HttpStatusCode.OK_200
185 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
186 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
188 expect(res.text).to.contain('<video:title>video 1</video:title>')
189 expect(res.text).to.contain('<video:title>video 2</video:title>')
190 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
192 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
193 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
195 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
196 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
200 after(async function () {
201 await cleanupTests([ server ])