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