]>
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' | |
254d3579 | 5 | import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' |
4c7e60bc | 6 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' |
c2ad546d C |
7 | |
8 | const expect = chai.expect | |
9 | ||
10 | describe('Test misc endpoints', function () { | |
254d3579 | 11 | let server: PeerTubeServer |
c2ad546d C |
12 | |
13 | before(async function () { | |
14 | this.timeout(120000) | |
15 | ||
254d3579 | 16 | server = await createSingleServer(1) |
2feebf3e | 17 | await setAccessTokensToServers([ server ]) |
c2ad546d C |
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', | |
c0e8b12e | 26 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 36 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 48 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 58 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
59 | }) |
60 | ||
61 | expect(res.body.tracking).to.equal('N') | |
62 | }) | |
31414127 RK |
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', | |
c0e8b12e | 68 | expectedStatus: HttpStatusCode.FOUND_302 |
31414127 RK |
69 | }) |
70 | ||
71 | expect(res.header.location).to.equal('/my-account/settings') | |
72 | }) | |
d43c6b1f C |
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, | |
c0e8b12e | 81 | expectedStatus: HttpStatusCode.OK_200 |
d43c6b1f C |
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 | }) | |
c2ad546d C |
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', | |
c0e8b12e | 106 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 116 | expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301 |
c2ad546d C |
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', | |
c0e8b12e | 124 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
125 | }) |
126 | ||
127 | expect(res.body.software.name).to.equal('peertube') | |
47d8e266 C |
128 | expect(res.body.usage.users.activeMonth).to.equal(1) |
129 | expect(res.body.usage.users.activeHalfyear).to.equal(1) | |
c2ad546d C |
130 | }) |
131 | }) | |
132 | ||
2feebf3e C |
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', | |
c0e8b12e | 139 | expectedStatus: HttpStatusCode.OK_200 |
2feebf3e C |
140 | }) |
141 | ||
142 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 143 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e C |
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', | |
c0e8b12e | 150 | expectedStatus: HttpStatusCode.OK_200 |
2feebf3e C |
151 | }) |
152 | ||
153 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 154 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e C |
155 | }) |
156 | ||
157 | it('Should add videos, channel and accounts and get sitemap', async function () { | |
158 | this.timeout(35000) | |
159 | ||
89d241a7 C |
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 } }) | |
2feebf3e | 163 | |
89d241a7 C |
164 | await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) |
165 | await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) | |
2feebf3e | 166 | |
89d241a7 C |
167 | await server.users.create({ username: 'user1', password: 'password' }) |
168 | await server.users.create({ username: 'user2', password: 'password' }) | |
2feebf3e C |
169 | |
170 | const res = await makeGetRequest({ | |
171 | url: server.url, | |
172 | path: '/sitemap.xml?t=1', // avoid using cache | |
c0e8b12e | 173 | expectedStatus: HttpStatusCode.OK_200 |
2feebf3e C |
174 | }) |
175 | ||
176 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 177 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e | 178 | |
e39cfd1d C |
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>') | |
2feebf3e | 182 | |
f4659d73 C |
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>') | |
2feebf3e | 185 | |
f4659d73 C |
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>') | |
2feebf3e C |
188 | }) |
189 | }) | |
190 | ||
7c3b7976 C |
191 | after(async function () { |
192 | await cleanupTests([ server ]) | |
c2ad546d C |
193 | }) |
194 | }) |