]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/misc-endpoints.ts
Introduce channels command
[github/Chocobozzz/PeerTube.git] / server / tests / misc-endpoints.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import {
7 cleanupTests,
8 createUser,
9 flushAndRunServer,
10 makeGetRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo
14 } from '../../shared/extra-utils'
15 import { VideoPrivacy } from '../../shared/models/videos'
16
17 const expect = chai.expect
18
19 describe('Test misc endpoints', function () {
20 let server: ServerInfo
21
22 before(async function () {
23 this.timeout(120000)
24
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
27 })
28
29 describe('Test a well known endpoints', function () {
30
31 it('Should get security.txt', async function () {
32 const res = await makeGetRequest({
33 url: server.url,
34 path: '/.well-known/security.txt',
35 statusCodeExpected: HttpStatusCode.OK_200
36 })
37
38 expect(res.text).to.contain('security issue')
39 })
40
41 it('Should get nodeinfo', async function () {
42 const res = await makeGetRequest({
43 url: server.url,
44 path: '/.well-known/nodeinfo',
45 statusCodeExpected: HttpStatusCode.OK_200
46 })
47
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')
51 })
52
53 it('Should get dnt policy text', async function () {
54 const res = await makeGetRequest({
55 url: server.url,
56 path: '/.well-known/dnt-policy.txt',
57 statusCodeExpected: HttpStatusCode.OK_200
58 })
59
60 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
61 })
62
63 it('Should get dnt policy', async function () {
64 const res = await makeGetRequest({
65 url: server.url,
66 path: '/.well-known/dnt',
67 statusCodeExpected: HttpStatusCode.OK_200
68 })
69
70 expect(res.body.tracking).to.equal('N')
71 })
72
73 it('Should get change-password location', async function () {
74 const res = await makeGetRequest({
75 url: server.url,
76 path: '/.well-known/change-password',
77 statusCodeExpected: HttpStatusCode.FOUND_302
78 })
79
80 expect(res.header.location).to.equal('/my-account/settings')
81 })
82
83 it('Should test webfinger', async function () {
84 const resource = 'acct:peertube@' + server.host
85 const accountUrl = server.url + '/accounts/peertube'
86
87 const res = await makeGetRequest({
88 url: server.url,
89 path: '/.well-known/webfinger?resource=' + resource,
90 statusCodeExpected: HttpStatusCode.OK_200
91 })
92
93 const data = res.body
94
95 expect(data.subject).to.equal(resource)
96 expect(data.aliases).to.contain(accountUrl)
97
98 const self = data.links.find(l => l.rel === 'self')
99 expect(self).to.exist
100 expect(self.type).to.equal('application/activity+json')
101 expect(self.href).to.equal(accountUrl)
102
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}')
106 })
107 })
108
109 describe('Test classic static endpoints', function () {
110
111 it('Should get robots.txt', async function () {
112 const res = await makeGetRequest({
113 url: server.url,
114 path: '/robots.txt',
115 statusCodeExpected: HttpStatusCode.OK_200
116 })
117
118 expect(res.text).to.contain('User-agent')
119 })
120
121 it('Should get security.txt', async function () {
122 await makeGetRequest({
123 url: server.url,
124 path: '/security.txt',
125 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
126 })
127 })
128
129 it('Should get nodeinfo', async function () {
130 const res = await makeGetRequest({
131 url: server.url,
132 path: '/nodeinfo/2.0.json',
133 statusCodeExpected: HttpStatusCode.OK_200
134 })
135
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)
139 })
140 })
141
142 describe('Test bots endpoints', function () {
143
144 it('Should get the empty sitemap', async function () {
145 const res = await makeGetRequest({
146 url: server.url,
147 path: '/sitemap.xml',
148 statusCodeExpected: HttpStatusCode.OK_200
149 })
150
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>')
153 })
154
155 it('Should get the empty cached sitemap', async function () {
156 const res = await makeGetRequest({
157 url: server.url,
158 path: '/sitemap.xml',
159 statusCodeExpected: HttpStatusCode.OK_200
160 })
161
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>')
164 })
165
166 it('Should add videos, channel and accounts and get sitemap', async function () {
167 this.timeout(35000)
168
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 })
172
173 await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
174 await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
175
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' })
178
179 const res = await makeGetRequest({
180 url: server.url,
181 path: '/sitemap.xml?t=1', // avoid using cache
182 statusCodeExpected: HttpStatusCode.OK_200
183 })
184
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>')
187
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>')
191
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>')
194
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>')
197 })
198 })
199
200 after(async function () {
201 await cleanupTests([ server ])
202 })
203 })