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'
7 describe('Test misc endpoints', function () {
8 let server: PeerTubeServer
10 before(async function () {
13 server = await createSingleServer(1)
14 await setAccessTokensToServers([ server ])
17 describe('Test a well known endpoints', function () {
19 it('Should get security.txt', async function () {
20 const res = await makeGetRequest({
22 path: '/.well-known/security.txt',
23 expectedStatus: HttpStatusCode.OK_200
26 expect(res.text).to.contain('security issue')
29 it('Should get nodeinfo', async function () {
30 const res = await makeGetRequest({
32 path: '/.well-known/nodeinfo',
33 expectedStatus: HttpStatusCode.OK_200
36 expect(res.body.links).to.be.an('array')
37 expect(res.body.links).to.have.lengthOf(1)
38 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
41 it('Should get dnt policy text', async function () {
42 const res = await makeGetRequest({
44 path: '/.well-known/dnt-policy.txt',
45 expectedStatus: HttpStatusCode.OK_200
48 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
51 it('Should get dnt policy', async function () {
52 const res = await makeGetRequest({
54 path: '/.well-known/dnt',
55 expectedStatus: HttpStatusCode.OK_200
58 expect(res.body.tracking).to.equal('N')
61 it('Should get change-password location', async function () {
62 const res = await makeGetRequest({
64 path: '/.well-known/change-password',
65 expectedStatus: HttpStatusCode.FOUND_302
68 expect(res.header.location).to.equal('/my-account/settings')
71 it('Should test webfinger', async function () {
72 const resource = 'acct:peertube@' + server.host
73 const accountUrl = server.url + '/accounts/peertube'
75 const res = await makeGetRequest({
77 path: '/.well-known/webfinger?resource=' + resource,
78 expectedStatus: HttpStatusCode.OK_200
83 expect(data.subject).to.equal(resource)
84 expect(data.aliases).to.contain(accountUrl)
86 const self = data.links.find(l => l.rel === 'self')
88 expect(self.type).to.equal('application/activity+json')
89 expect(self.href).to.equal(accountUrl)
91 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
92 expect(remoteInteract).to.exist
93 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
97 describe('Test classic static endpoints', function () {
99 it('Should get robots.txt', async function () {
100 const res = await makeGetRequest({
103 expectedStatus: HttpStatusCode.OK_200
106 expect(res.text).to.contain('User-agent')
109 it('Should get security.txt', async function () {
110 await makeGetRequest({
112 path: '/security.txt',
113 expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301
117 it('Should get nodeinfo', async function () {
118 const res = await makeGetRequest({
120 path: '/nodeinfo/2.0.json',
121 expectedStatus: HttpStatusCode.OK_200
124 expect(res.body.software.name).to.equal('peertube')
125 expect(res.body.usage.users.activeMonth).to.equal(1)
126 expect(res.body.usage.users.activeHalfyear).to.equal(1)
130 describe('Test bots endpoints', function () {
132 it('Should get the empty sitemap', async function () {
133 const res = await makeGetRequest({
135 path: '/sitemap.xml',
136 expectedStatus: HttpStatusCode.OK_200
139 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
140 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
143 it('Should get the empty cached sitemap', async function () {
144 const res = await makeGetRequest({
146 path: '/sitemap.xml',
147 expectedStatus: 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 add videos, channel and accounts and get sitemap', async function () {
157 await server.videos.upload({ attributes: { name: 'video 1', nsfw: false } })
158 await server.videos.upload({ attributes: { name: 'video 2', nsfw: false } })
159 await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
161 await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
162 await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
164 await server.users.create({ username: 'user1', password: 'password' })
165 await server.users.create({ username: 'user2', password: 'password' })
167 const res = await makeGetRequest({
169 path: '/sitemap.xml?t=1', // avoid using cache
170 expectedStatus: HttpStatusCode.OK_200
173 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
174 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
176 expect(res.text).to.contain('<video:title>video 1</video:title>')
177 expect(res.text).to.contain('<video:title>video 2</video:title>')
178 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
180 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
181 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
183 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
184 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
188 after(async function () {
189 await cleanupTests([ server ])