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