]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
c2ad546d | 2 | |
86347717 | 3 | import { expect } from 'chai' |
bf54587a | 4 | import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' |
4c7e60bc | 5 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' |
c2ad546d | 6 | |
c2ad546d | 7 | describe('Test misc endpoints', function () { |
254d3579 | 8 | let server: PeerTubeServer |
c2ad546d C |
9 | |
10 | before(async function () { | |
11 | this.timeout(120000) | |
12 | ||
254d3579 | 13 | server = await createSingleServer(1) |
2feebf3e | 14 | await setAccessTokensToServers([ server ]) |
c2ad546d C |
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', | |
c0e8b12e | 23 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 33 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 45 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 55 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
56 | }) |
57 | ||
58 | expect(res.body.tracking).to.equal('N') | |
59 | }) | |
31414127 RK |
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', | |
c0e8b12e | 65 | expectedStatus: HttpStatusCode.FOUND_302 |
31414127 RK |
66 | }) |
67 | ||
68 | expect(res.header.location).to.equal('/my-account/settings') | |
69 | }) | |
d43c6b1f C |
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, | |
c0e8b12e | 78 | expectedStatus: HttpStatusCode.OK_200 |
d43c6b1f C |
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 | }) | |
c2ad546d C |
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', | |
c0e8b12e | 103 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
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', | |
c0e8b12e | 113 | expectedStatus: HttpStatusCode.MOVED_PERMANENTLY_301 |
c2ad546d C |
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', | |
c0e8b12e | 121 | expectedStatus: HttpStatusCode.OK_200 |
c2ad546d C |
122 | }) |
123 | ||
124 | expect(res.body.software.name).to.equal('peertube') | |
47d8e266 C |
125 | expect(res.body.usage.users.activeMonth).to.equal(1) |
126 | expect(res.body.usage.users.activeHalfyear).to.equal(1) | |
c2ad546d C |
127 | }) |
128 | }) | |
129 | ||
2feebf3e C |
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', | |
c0e8b12e | 136 | expectedStatus: HttpStatusCode.OK_200 |
2feebf3e C |
137 | }) |
138 | ||
139 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 140 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e C |
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', | |
c0e8b12e | 147 | expectedStatus: HttpStatusCode.OK_200 |
2feebf3e C |
148 | }) |
149 | ||
150 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 151 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e C |
152 | }) |
153 | ||
154 | it('Should add videos, channel and accounts and get sitemap', async function () { | |
155 | this.timeout(35000) | |
156 | ||
89d241a7 C |
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 } }) | |
2feebf3e | 160 | |
89d241a7 C |
161 | await server.channels.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) |
162 | await server.channels.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) | |
2feebf3e | 163 | |
89d241a7 C |
164 | await server.users.create({ username: 'user1', password: 'password' }) |
165 | await server.users.create({ username: 'user2', password: 'password' }) | |
2feebf3e C |
166 | |
167 | const res = await makeGetRequest({ | |
168 | url: server.url, | |
169 | path: '/sitemap.xml?t=1', // avoid using cache | |
c0e8b12e | 170 | expectedStatus: HttpStatusCode.OK_200 |
2feebf3e C |
171 | }) |
172 | ||
173 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
f4659d73 | 174 | expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>') |
2feebf3e | 175 | |
e39cfd1d C |
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>') | |
2feebf3e | 179 | |
f4659d73 C |
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>') | |
2feebf3e | 182 | |
f4659d73 C |
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>') | |
2feebf3e C |
185 | }) |
186 | }) | |
187 | ||
7c3b7976 C |
188 | after(async function () { |
189 | await cleanupTests([ server ]) | |
c2ad546d C |
190 | }) |
191 | }) |