]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/misc-endpoints.ts
Use test wrapper exit function
[github/Chocobozzz/PeerTube.git] / server / tests / misc-endpoints.ts
CommitLineData
c2ad546d
C
1/* tslint:disable:no-unused-expression */
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'
c2ad546d
C
16
17const expect = chai.expect
18
19describe('Test misc endpoints', function () {
20 let server: ServerInfo
21
22 before(async function () {
23 this.timeout(120000)
24
210feb6c 25 server = await flushAndRunServer(1)
2feebf3e 26 await setAccessTokensToServers([ server ])
c2ad546d
C
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: 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: 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: 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: 200
68 })
69
70 expect(res.body.tracking).to.equal('N')
71 })
31414127
RK
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: 302
78 })
79
80 expect(res.header.location).to.equal('/my-account/settings')
81 })
c2ad546d
C
82 })
83
84 describe('Test classic static endpoints', function () {
85
86 it('Should get robots.txt', async function () {
87 const res = await makeGetRequest({
88 url: server.url,
89 path: '/robots.txt',
90 statusCodeExpected: 200
91 })
92
93 expect(res.text).to.contain('User-agent')
94 })
95
96 it('Should get security.txt', async function () {
97 await makeGetRequest({
98 url: server.url,
99 path: '/security.txt',
100 statusCodeExpected: 301
101 })
102 })
103
104 it('Should get nodeinfo', async function () {
105 const res = await makeGetRequest({
106 url: server.url,
107 path: '/nodeinfo/2.0.json',
108 statusCodeExpected: 200
109 })
110
111 expect(res.body.software.name).to.equal('peertube')
112 })
113 })
114
2feebf3e
C
115 describe('Test bots endpoints', function () {
116
117 it('Should get the empty sitemap', async function () {
118 const res = await makeGetRequest({
119 url: server.url,
120 path: '/sitemap.xml',
121 statusCodeExpected: 200
122 })
123
124 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
125 expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
126 })
127
128 it('Should get the empty cached sitemap', async function () {
129 const res = await makeGetRequest({
130 url: server.url,
131 path: '/sitemap.xml',
132 statusCodeExpected: 200
133 })
134
135 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
136 expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
137 })
138
139 it('Should add videos, channel and accounts and get sitemap', async function () {
140 this.timeout(35000)
141
142 await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
143 await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
144 await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
145
146 await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
147 await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
148
1eddc9a7
C
149 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
150 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
2feebf3e
C
151
152 const res = await makeGetRequest({
153 url: server.url,
154 path: '/sitemap.xml?t=1', // avoid using cache
155 statusCodeExpected: 200
156 })
157
158 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
159 expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
160
161 expect(res.text).to.contain('<video:title><![CDATA[video 1]]></video:title>')
162 expect(res.text).to.contain('<video:title><![CDATA[video 2]]></video:title>')
163 expect(res.text).to.not.contain('<video:title><![CDATA[video 3]]></video:title>')
164
165 expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel1</loc></url>')
166 expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel2</loc></url>')
167
168 expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user1</loc></url>')
169 expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user2</loc></url>')
170 })
171 })
172
7c3b7976
C
173 after(async function () {
174 await cleanupTests([ server ])
c2ad546d
C
175 })
176})