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