]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/misc-endpoints.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / misc-endpoints.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
c2ad546d
C
2
3import 'mocha'
4import * as chai from 'chai'
a5461888 5import { HttpStatusCode } from '@shared/core-utils'
254d3579 6import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
d23dd9fb 7import { VideoPrivacy } from '@shared/models'
c2ad546d
C
8
9const expect = chai.expect
10
11describe('Test misc endpoints', function () {
254d3579 12 let server: PeerTubeServer
c2ad546d
C
13
14 before(async function () {
15 this.timeout(120000)
16
254d3579 17 server = await createSingleServer(1)
2feebf3e 18 await setAccessTokensToServers([ server ])
c2ad546d
C
19 })
20
21 describe('Test a well known endpoints', function () {
22
23 it('Should get security.txt', async function () {
24 const res = await makeGetRequest({
25 url: server.url,
26 path: '/.well-known/security.txt',
2d53be02 27 statusCodeExpected: HttpStatusCode.OK_200
c2ad546d
C
28 })
29
30 expect(res.text).to.contain('security issue')
31 })
32
33 it('Should get nodeinfo', async function () {
34 const res = await makeGetRequest({
35 url: server.url,
36 path: '/.well-known/nodeinfo',
2d53be02 37 statusCodeExpected: HttpStatusCode.OK_200
c2ad546d
C
38 })
39
40 expect(res.body.links).to.be.an('array')
41 expect(res.body.links).to.have.lengthOf(1)
42 expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
43 })
44
45 it('Should get dnt policy text', async function () {
46 const res = await makeGetRequest({
47 url: server.url,
48 path: '/.well-known/dnt-policy.txt',
2d53be02 49 statusCodeExpected: HttpStatusCode.OK_200
c2ad546d
C
50 })
51
52 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
53 })
54
55 it('Should get dnt policy', async function () {
56 const res = await makeGetRequest({
57 url: server.url,
58 path: '/.well-known/dnt',
2d53be02 59 statusCodeExpected: HttpStatusCode.OK_200
c2ad546d
C
60 })
61
62 expect(res.body.tracking).to.equal('N')
63 })
31414127
RK
64
65 it('Should get change-password location', async function () {
66 const res = await makeGetRequest({
67 url: server.url,
68 path: '/.well-known/change-password',
2d53be02 69 statusCodeExpected: HttpStatusCode.FOUND_302
31414127
RK
70 })
71
72 expect(res.header.location).to.equal('/my-account/settings')
73 })
d43c6b1f
C
74
75 it('Should test webfinger', async function () {
76 const resource = 'acct:peertube@' + server.host
77 const accountUrl = server.url + '/accounts/peertube'
78
79 const res = await makeGetRequest({
80 url: server.url,
81 path: '/.well-known/webfinger?resource=' + resource,
82 statusCodeExpected: HttpStatusCode.OK_200
83 })
84
85 const data = res.body
86
87 expect(data.subject).to.equal(resource)
88 expect(data.aliases).to.contain(accountUrl)
89
90 const self = data.links.find(l => l.rel === 'self')
91 expect(self).to.exist
92 expect(self.type).to.equal('application/activity+json')
93 expect(self.href).to.equal(accountUrl)
94
95 const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
96 expect(remoteInteract).to.exist
97 expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
98 })
c2ad546d
C
99 })
100
101 describe('Test classic static endpoints', function () {
102
103 it('Should get robots.txt', async function () {
104 const res = await makeGetRequest({
105 url: server.url,
106 path: '/robots.txt',
2d53be02 107 statusCodeExpected: HttpStatusCode.OK_200
c2ad546d
C
108 })
109
110 expect(res.text).to.contain('User-agent')
111 })
112
113 it('Should get security.txt', async function () {
114 await makeGetRequest({
115 url: server.url,
116 path: '/security.txt',
2d53be02 117 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
c2ad546d
C
118 })
119 })
120
121 it('Should get nodeinfo', async function () {
122 const res = await makeGetRequest({
123 url: server.url,
124 path: '/nodeinfo/2.0.json',
2d53be02 125 statusCodeExpected: HttpStatusCode.OK_200
c2ad546d
C
126 })
127
128 expect(res.body.software.name).to.equal('peertube')
47d8e266
C
129 expect(res.body.usage.users.activeMonth).to.equal(1)
130 expect(res.body.usage.users.activeHalfyear).to.equal(1)
c2ad546d
C
131 })
132 })
133
2feebf3e
C
134 describe('Test bots endpoints', function () {
135
136 it('Should get the empty sitemap', async function () {
137 const res = await makeGetRequest({
138 url: server.url,
139 path: '/sitemap.xml',
2d53be02 140 statusCodeExpected: HttpStatusCode.OK_200
2feebf3e
C
141 })
142
143 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
f4659d73 144 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
2feebf3e
C
145 })
146
147 it('Should get the empty cached sitemap', async function () {
148 const res = await makeGetRequest({
149 url: server.url,
150 path: '/sitemap.xml',
2d53be02 151 statusCodeExpected: HttpStatusCode.OK_200
2feebf3e
C
152 })
153
154 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
f4659d73 155 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
2feebf3e
C
156 })
157
158 it('Should add videos, channel and accounts and get sitemap', async function () {
159 this.timeout(35000)
160
89d241a7
C
161 await server.videos.upload({ attributes: { name: 'video 1', nsfw: false } })
162 await server.videos.upload({ attributes: { name: 'video 2', nsfw: false } })
163 await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
2feebf3e 164
89d241a7
C
165 await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
166 await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
2feebf3e 167
89d241a7
C
168 await server.users.create({ username: 'user1', password: 'password' })
169 await server.users.create({ username: 'user2', password: 'password' })
2feebf3e
C
170
171 const res = await makeGetRequest({
172 url: server.url,
173 path: '/sitemap.xml?t=1', // avoid using cache
2d53be02 174 statusCodeExpected: HttpStatusCode.OK_200
2feebf3e
C
175 })
176
177 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
f4659d73 178 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
2feebf3e 179
e39cfd1d
C
180 expect(res.text).to.contain('<video:title>video 1</video:title>')
181 expect(res.text).to.contain('<video:title>video 2</video:title>')
182 expect(res.text).to.not.contain('<video:title>video 3</video:title>')
2feebf3e 183
f4659d73
C
184 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
185 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
2feebf3e 186
f4659d73
C
187 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
188 expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
2feebf3e
C
189 })
190 })
191
7c3b7976
C
192 after(async function () {
193 await cleanupTests([ server ])
c2ad546d
C
194 })
195})