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