]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | addVideoChannel, | |
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: 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 | }) | |
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 | }) | |
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 | ||
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:' + server.port + '/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:' + server.port + '/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 | ||
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' }) | |
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:' + server.port + '/about/instance</loc></url>') | |
160 | ||
161 | expect(res.text).to.contain('<video:title>video 1</video:title>') | |
162 | expect(res.text).to.contain('<video:title>video 2</video:title>') | |
163 | expect(res.text).to.not.contain('<video:title>video 3</video:title>') | |
164 | ||
165 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>') | |
166 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>') | |
167 | ||
168 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>') | |
169 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>') | |
170 | }) | |
171 | }) | |
172 | ||
173 | after(async function () { | |
174 | await cleanupTests([ server ]) | |
175 | }) | |
176 | }) |