]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
c2ad546d C |
2 | |
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
a5461888 | 5 | import { HttpStatusCode } from '@shared/core-utils' |
2feebf3e | 6 | import { |
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 | 15 | import { VideoPrivacy } from '../../shared/models/videos' |
c2ad546d C |
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 | ||
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', | |
2d53be02 | 35 | statusCodeExpected: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
2d53be02 | 45 | statusCodeExpected: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
2d53be02 | 57 | statusCodeExpected: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
2d53be02 | 67 | statusCodeExpected: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
2d53be02 | 77 | statusCodeExpected: HttpStatusCode.FOUND_302 |
31414127 RK |
78 | }) |
79 | ||
80 | expect(res.header.location).to.equal('/my-account/settings') | |
81 | }) | |
d43c6b1f C |
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 | }) | |
c2ad546d C |
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', | |
2d53be02 | 115 | statusCodeExpected: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
2d53be02 | 125 | statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301 |
c2ad546d C |
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', | |
2d53be02 | 133 | statusCodeExpected: HttpStatusCode.OK_200 |
c2ad546d C |
134 | }) |
135 | ||
136 | expect(res.body.software.name).to.equal('peertube') | |
47d8e266 C |
137 | expect(res.body.usage.users.activeMonth).to.equal(1) |
138 | expect(res.body.usage.users.activeHalfyear).to.equal(1) | |
c2ad546d C |
139 | }) |
140 | }) | |
141 | ||
2feebf3e C |
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', | |
2d53be02 | 148 | statusCodeExpected: HttpStatusCode.OK_200 |
2feebf3e C |
149 | }) |
150 | ||
151 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 152 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e C |
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', | |
2d53be02 | 159 | statusCodeExpected: HttpStatusCode.OK_200 |
2feebf3e C |
160 | }) |
161 | ||
162 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 163 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e C |
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 | ||
a5461888 C |
173 | await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) |
174 | await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) | |
2feebf3e | 175 | |
1eddc9a7 C |
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' }) | |
2feebf3e C |
178 | |
179 | const res = await makeGetRequest({ | |
180 | url: server.url, | |
181 | path: '/sitemap.xml?t=1', // avoid using cache | |
2d53be02 | 182 | statusCodeExpected: HttpStatusCode.OK_200 |
2feebf3e C |
183 | }) |
184 | ||
185 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 186 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e | 187 | |
e39cfd1d C |
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>') | |
2feebf3e | 191 | |
f4659d73 C |
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>') | |
2feebf3e | 194 | |
f4659d73 C |
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>') | |
2feebf3e C |
197 | }) |
198 | }) | |
199 | ||
7c3b7976 C |
200 | after(async function () { |
201 | await cleanupTests([ server ]) | |
c2ad546d C |
202 | }) |
203 | }) |