1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
6 import { expectLogDoesNotContain } from './shared'
8 describe('Test misc endpoints', function () {
9 let server: PeerTubeServer
11 before(async function () {
14 server = await createSingleServer(1)
15 await setAccessTokensToServers([ server ])
18 describe('Test a well known endpoints', function () {
20 it('Should get security.txt', async function () {
21 const res = await makeGetRequest({
23 path: '/.well-known/security.txt',
24 expectedStatus: HttpStatusCode.OK_200
27 expect(res.text).to.contain('security issue')
30 it('Should get nodeinfo', async function () {
31 const res = await makeGetRequest({
33 path: '/.well-known/nodeinfo',
34 expectedStatus: HttpStatusCode.OK_200
37 expect(res.body.links).to.be.an('array')
38 expect(res.body.links).to.have.lengthOf(1)
39 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
42 it('Should get dnt policy text', async function () {
43 const res = await makeGetRequest({
45 path: '/.well-known/dnt-policy.txt',
46 expectedStatus: HttpStatusCode.OK_200
49 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
52 it('Should get dnt policy', async function () {
53 const res = await makeGetRequest({
55 path: '/.well-known/dnt',
56 expectedStatus: HttpStatusCode.OK_200
59 expect(res.body.tracking).to.equal('N')
62 it('Should get change-password location', async function () {
63 const res = await makeGetRequest({
65 path: '/.well-known/change-password',
66 expectedStatus: HttpStatusCode.FOUND_302
69 expect(res.header.location).to.equal('/my-account/settings')
72 it('Should test webfinger', async function () {
73 const resource = 'acct:peertube@' + server.host
74 const accountUrl = server.url + '/accounts/peertube'
76 const res = await makeGetRequest({
78 path: '/.well-known/webfinger?resource=' + resource,
79 expectedStatus: HttpStatusCode.OK_200
84 expect(data.subject).to.equal(resource)
85 expect(data.aliases).to.contain(accountUrl)
87 const self = data.links.find(l => l.rel === 'self')
89 expect(self.type).to.equal('application/activity+json')
90 expect(self.href).to.equal(accountUrl)
92 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
93 expect(remoteInteract).to.exist
94 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
98 describe('Test classic static endpoints', function () {
100 it('Should get robots.txt', async function () {
101 const res = await makeGetRequest({
104 expectedStatus: HttpStatusCode.OK_200
107 expect(res.text).to.contain('User-agent')
110 it('Should get security.txt', async function () {
111 await makeGetRequest({
113 path: '/security.txt',
114 expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301
118 it('Should get nodeinfo', async function () {
119 const res = await makeGetRequest({
121 path: '/nodeinfo/2.0.json',
122 expectedStatus: HttpStatusCode.OK_200
125 expect(res.body.software.name).to.equal('peertube')
126 expect(res.body.usage.users.activeMonth).to.equal(1)
127 expect(res.body.usage.users.activeHalfyear).to.equal(1)
131 describe('Test bots endpoints', function () {
133 it('Should get the empty sitemap', async function () {
134 const res = await makeGetRequest({
136 path: '/sitemap.xml',
137 expectedStatus: HttpStatusCode.OK_200
140 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
141 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
144 it('Should get the empty cached sitemap', async function () {
145 const res = await makeGetRequest({
147 path: '/sitemap.xml',
148 expectedStatus: 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 add videos, channel and accounts and get sitemap', async function () {
158 await server.videos.upload({ attributes: { name: 'video 1', nsfw: false } })
159 await server.videos.upload({ attributes: { name: 'video 2', nsfw: false } })
160 await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
162 await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
163 await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
165 await server.users.create({ username: 'user1', password: 'password' })
166 await server.users.create({ username: 'user2', password: 'password' })
168 const res = await makeGetRequest({
170 path: '/sitemap.xml?t=1', // avoid using cache
171 expectedStatus: HttpStatusCode.OK_200
174 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
175 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
177 expect(res.text).to.contain('<video:title>video 1</video:title>')
178 expect(res.text).to.contain('<video:title>video 2</video:title>')
179 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
181 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
182 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
184 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
185 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
188 it('Should not fail with big title/description videos', async function () {
189 const name = 'v'.repeat(115)
191 await server.videos.upload({ attributes: { name, description: 'd'.repeat(2500), nsfw: false } })
193 const res = await makeGetRequest({
195 path: '/sitemap.xml?t=2', // avoid using cache
196 expectedStatus: HttpStatusCode.OK_200
199 await expectLogDoesNotContain(server, 'Warning in sitemap generation')
200 await expectLogDoesNotContain(server, 'Error in sitemap generation')
202 expect(res.text).to.contain(`<video:title>${'v'.repeat(97)}...</video:title>`)
206 after(async function () {
207 await cleanupTests([ server ])