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