]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { | |
5 | checkBadCountPagination, | |
6 | checkBadSortPagination, | |
7 | checkBadStartPagination, | |
8 | cleanupTests, | |
9 | createMultipleServers, | |
10 | doubleFollow, | |
11 | makeDeleteRequest, | |
12 | makeGetRequest, | |
13 | makePostBodyRequest, | |
14 | makePutBodyRequest, | |
15 | PeerTubeServer, | |
16 | setAccessTokensToServers, | |
17 | waitJobs | |
18 | } from '@shared/extra-utils' | |
19 | import { HttpStatusCode, VideoCreateResult } from '@shared/models' | |
20 | ||
21 | describe('Test server redundancy API validators', function () { | |
22 | let servers: PeerTubeServer[] | |
23 | let userAccessToken = null | |
24 | let videoIdLocal: number | |
25 | let videoRemote: VideoCreateResult | |
26 | ||
27 | // --------------------------------------------------------------- | |
28 | ||
29 | before(async function () { | |
30 | this.timeout(80000) | |
31 | ||
32 | servers = await createMultipleServers(2) | |
33 | ||
34 | await setAccessTokensToServers(servers) | |
35 | await doubleFollow(servers[0], servers[1]) | |
36 | ||
37 | const user = { | |
38 | username: 'user1', | |
39 | password: 'password' | |
40 | } | |
41 | ||
42 | await servers[0].users.create({ username: user.username, password: user.password }) | |
43 | userAccessToken = await servers[0].login.getAccessToken(user) | |
44 | ||
45 | videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id | |
46 | ||
47 | const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid | |
48 | ||
49 | await waitJobs(servers) | |
50 | ||
51 | videoRemote = await servers[0].videos.get({ id: remoteUUID }) | |
52 | }) | |
53 | ||
54 | describe('When listing redundancies', function () { | |
55 | const path = '/api/v1/server/redundancy/videos' | |
56 | ||
57 | let url: string | |
58 | let token: string | |
59 | ||
60 | before(function () { | |
61 | url = servers[0].url | |
62 | token = servers[0].accessToken | |
63 | }) | |
64 | ||
65 | it('Should fail with an invalid token', async function () { | |
66 | await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
67 | }) | |
68 | ||
69 | it('Should fail if the user is not an administrator', async function () { | |
70 | await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
71 | }) | |
72 | ||
73 | it('Should fail with a bad start pagination', async function () { | |
74 | await checkBadStartPagination(url, path, servers[0].accessToken) | |
75 | }) | |
76 | ||
77 | it('Should fail with a bad count pagination', async function () { | |
78 | await checkBadCountPagination(url, path, servers[0].accessToken) | |
79 | }) | |
80 | ||
81 | it('Should fail with an incorrect sort', async function () { | |
82 | await checkBadSortPagination(url, path, servers[0].accessToken) | |
83 | }) | |
84 | ||
85 | it('Should fail with a bad target', async function () { | |
86 | await makeGetRequest({ url, path, token, query: { target: 'bad target' } }) | |
87 | }) | |
88 | ||
89 | it('Should fail without target', async function () { | |
90 | await makeGetRequest({ url, path, token }) | |
91 | }) | |
92 | ||
93 | it('Should succeed with the correct params', async function () { | |
94 | await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 }) | |
95 | }) | |
96 | }) | |
97 | ||
98 | describe('When manually adding a redundancy', function () { | |
99 | const path = '/api/v1/server/redundancy/videos' | |
100 | ||
101 | let url: string | |
102 | let token: string | |
103 | ||
104 | before(function () { | |
105 | url = servers[0].url | |
106 | token = servers[0].accessToken | |
107 | }) | |
108 | ||
109 | it('Should fail with an invalid token', async function () { | |
110 | await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
111 | }) | |
112 | ||
113 | it('Should fail if the user is not an administrator', async function () { | |
114 | await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
115 | }) | |
116 | ||
117 | it('Should fail without a video id', async function () { | |
118 | await makePostBodyRequest({ url, path, token }) | |
119 | }) | |
120 | ||
121 | it('Should fail with an incorrect video id', async function () { | |
122 | await makePostBodyRequest({ url, path, token, fields: { videoId: 'peertube' } }) | |
123 | }) | |
124 | ||
125 | it('Should fail with a not found video id', async function () { | |
126 | await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
127 | }) | |
128 | ||
129 | it('Should fail with a local a video id', async function () { | |
130 | await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdLocal } }) | |
131 | }) | |
132 | ||
133 | it('Should succeed with the correct params', async function () { | |
134 | await makePostBodyRequest({ | |
135 | url, | |
136 | path, | |
137 | token, | |
138 | fields: { videoId: videoRemote.shortUUID }, | |
139 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
140 | }) | |
141 | }) | |
142 | ||
143 | it('Should fail if the video is already duplicated', async function () { | |
144 | this.timeout(30000) | |
145 | ||
146 | await waitJobs(servers) | |
147 | ||
148 | await makePostBodyRequest({ | |
149 | url, | |
150 | path, | |
151 | token, | |
152 | fields: { videoId: videoRemote.uuid }, | |
153 | expectedStatus: HttpStatusCode.CONFLICT_409 | |
154 | }) | |
155 | }) | |
156 | }) | |
157 | ||
158 | describe('When manually removing a redundancy', function () { | |
159 | const path = '/api/v1/server/redundancy/videos/' | |
160 | ||
161 | let url: string | |
162 | let token: string | |
163 | ||
164 | before(function () { | |
165 | url = servers[0].url | |
166 | token = servers[0].accessToken | |
167 | }) | |
168 | ||
169 | it('Should fail with an invalid token', async function () { | |
170 | await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
171 | }) | |
172 | ||
173 | it('Should fail if the user is not an administrator', async function () { | |
174 | await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
175 | }) | |
176 | ||
177 | it('Should fail with an incorrect video id', async function () { | |
178 | await makeDeleteRequest({ url, path: path + 'toto', token }) | |
179 | }) | |
180 | ||
181 | it('Should fail with a not found video redundancy', async function () { | |
182 | await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
183 | }) | |
184 | }) | |
185 | ||
186 | describe('When updating server redundancy', function () { | |
187 | const path = '/api/v1/server/redundancy' | |
188 | ||
189 | it('Should fail with an invalid token', async function () { | |
190 | await makePutBodyRequest({ | |
191 | url: servers[0].url, | |
192 | path: path + '/localhost:' + servers[1].port, | |
193 | fields: { redundancyAllowed: true }, | |
194 | token: 'fake_token', | |
195 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
196 | }) | |
197 | }) | |
198 | ||
199 | it('Should fail if the user is not an administrator', async function () { | |
200 | await makePutBodyRequest({ | |
201 | url: servers[0].url, | |
202 | path: path + '/localhost:' + servers[1].port, | |
203 | fields: { redundancyAllowed: true }, | |
204 | token: userAccessToken, | |
205 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
206 | }) | |
207 | }) | |
208 | ||
209 | it('Should fail if we do not follow this server', async function () { | |
210 | await makePutBodyRequest({ | |
211 | url: servers[0].url, | |
212 | path: path + '/example.com', | |
213 | fields: { redundancyAllowed: true }, | |
214 | token: servers[0].accessToken, | |
215 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
216 | }) | |
217 | }) | |
218 | ||
219 | it('Should fail without de redundancyAllowed param', async function () { | |
220 | await makePutBodyRequest({ | |
221 | url: servers[0].url, | |
222 | path: path + '/localhost:' + servers[1].port, | |
223 | fields: { blabla: true }, | |
224 | token: servers[0].accessToken, | |
225 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
226 | }) | |
227 | }) | |
228 | ||
229 | it('Should succeed with the correct parameters', async function () { | |
230 | await makePutBodyRequest({ | |
231 | url: servers[0].url, | |
232 | path: path + '/localhost:' + servers[1].port, | |
233 | fields: { redundancyAllowed: true }, | |
234 | token: servers[0].accessToken, | |
235 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
236 | }) | |
237 | }) | |
238 | }) | |
239 | ||
240 | after(async function () { | |
241 | await cleanupTests(servers) | |
242 | }) | |
243 | }) |