]>
Commit | Line | Data |
---|---|---|
c2ad546d C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
2feebf3e C |
5 | import { |
6 | addVideoChannel, | |
7 | createUser, | |
8 | flushTests, | |
9 | killallServers, | |
10 | makeGetRequest, | |
210feb6c | 11 | flushAndRunServer, |
2feebf3e C |
12 | ServerInfo, |
13 | setAccessTokensToServers, | |
14 | uploadVideo | |
94565d52 | 15 | } from '../../shared/extra-utils' |
2feebf3e | 16 | import { VideoPrivacy } from '../../shared/models/videos' |
c2ad546d C |
17 | |
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test misc endpoints', function () { | |
21 | let server: ServerInfo | |
22 | ||
23 | before(async function () { | |
24 | this.timeout(120000) | |
25 | ||
210feb6c | 26 | server = await flushAndRunServer(1) |
2feebf3e | 27 | await setAccessTokensToServers([ server ]) |
c2ad546d C |
28 | }) |
29 | ||
30 | describe('Test a well known endpoints', function () { | |
31 | ||
32 | it('Should get security.txt', async function () { | |
33 | const res = await makeGetRequest({ | |
34 | url: server.url, | |
35 | path: '/.well-known/security.txt', | |
36 | statusCodeExpected: 200 | |
37 | }) | |
38 | ||
39 | expect(res.text).to.contain('security issue') | |
40 | }) | |
41 | ||
42 | it('Should get nodeinfo', async function () { | |
43 | const res = await makeGetRequest({ | |
44 | url: server.url, | |
45 | path: '/.well-known/nodeinfo', | |
46 | statusCodeExpected: 200 | |
47 | }) | |
48 | ||
49 | expect(res.body.links).to.be.an('array') | |
50 | expect(res.body.links).to.have.lengthOf(1) | |
51 | expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0') | |
52 | }) | |
53 | ||
54 | it('Should get dnt policy text', async function () { | |
55 | const res = await makeGetRequest({ | |
56 | url: server.url, | |
57 | path: '/.well-known/dnt-policy.txt', | |
58 | statusCodeExpected: 200 | |
59 | }) | |
60 | ||
61 | expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt') | |
62 | }) | |
63 | ||
64 | it('Should get dnt policy', async function () { | |
65 | const res = await makeGetRequest({ | |
66 | url: server.url, | |
67 | path: '/.well-known/dnt', | |
68 | statusCodeExpected: 200 | |
69 | }) | |
70 | ||
71 | expect(res.body.tracking).to.equal('N') | |
72 | }) | |
31414127 RK |
73 | |
74 | it('Should get change-password location', async function () { | |
75 | const res = await makeGetRequest({ | |
76 | url: server.url, | |
77 | path: '/.well-known/change-password', | |
78 | statusCodeExpected: 302 | |
79 | }) | |
80 | ||
81 | expect(res.header.location).to.equal('/my-account/settings') | |
82 | }) | |
c2ad546d C |
83 | }) |
84 | ||
85 | describe('Test classic static endpoints', function () { | |
86 | ||
87 | it('Should get robots.txt', async function () { | |
88 | const res = await makeGetRequest({ | |
89 | url: server.url, | |
90 | path: '/robots.txt', | |
91 | statusCodeExpected: 200 | |
92 | }) | |
93 | ||
94 | expect(res.text).to.contain('User-agent') | |
95 | }) | |
96 | ||
97 | it('Should get security.txt', async function () { | |
98 | await makeGetRequest({ | |
99 | url: server.url, | |
100 | path: '/security.txt', | |
101 | statusCodeExpected: 301 | |
102 | }) | |
103 | }) | |
104 | ||
105 | it('Should get nodeinfo', async function () { | |
106 | const res = await makeGetRequest({ | |
107 | url: server.url, | |
108 | path: '/nodeinfo/2.0.json', | |
109 | statusCodeExpected: 200 | |
110 | }) | |
111 | ||
112 | expect(res.body.software.name).to.equal('peertube') | |
113 | }) | |
114 | }) | |
115 | ||
2feebf3e C |
116 | describe('Test bots endpoints', function () { |
117 | ||
118 | it('Should get the empty sitemap', async function () { | |
119 | const res = await makeGetRequest({ | |
120 | url: server.url, | |
121 | path: '/sitemap.xml', | |
122 | statusCodeExpected: 200 | |
123 | }) | |
124 | ||
125 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
126 | expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>') | |
127 | }) | |
128 | ||
129 | it('Should get the empty cached sitemap', async function () { | |
130 | const res = await makeGetRequest({ | |
131 | url: server.url, | |
132 | path: '/sitemap.xml', | |
133 | statusCodeExpected: 200 | |
134 | }) | |
135 | ||
136 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
137 | expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>') | |
138 | }) | |
139 | ||
140 | it('Should add videos, channel and accounts and get sitemap', async function () { | |
141 | this.timeout(35000) | |
142 | ||
143 | await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false }) | |
144 | await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false }) | |
145 | await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE }) | |
146 | ||
147 | await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' }) | |
148 | await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' }) | |
149 | ||
1eddc9a7 C |
150 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) |
151 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' }) | |
2feebf3e C |
152 | |
153 | const res = await makeGetRequest({ | |
154 | url: server.url, | |
155 | path: '/sitemap.xml?t=1', // avoid using cache | |
156 | statusCodeExpected: 200 | |
157 | }) | |
158 | ||
159 | expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') | |
160 | expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>') | |
161 | ||
162 | expect(res.text).to.contain('<video:title><![CDATA[video 1]]></video:title>') | |
163 | expect(res.text).to.contain('<video:title><![CDATA[video 2]]></video:title>') | |
164 | expect(res.text).to.not.contain('<video:title><![CDATA[video 3]]></video:title>') | |
165 | ||
166 | expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel1</loc></url>') | |
167 | expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel2</loc></url>') | |
168 | ||
169 | expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user1</loc></url>') | |
170 | expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user2</loc></url>') | |
171 | }) | |
172 | }) | |
173 | ||
210feb6c | 174 | after(function () { |
c2ad546d C |
175 | killallServers([ server ]) |
176 | }) | |
177 | }) |