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