]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
c48e82b5 C |
2 | |
3 | import 'mocha' | |
c48e82b5 | 4 | import { |
b764380a C |
5 | checkBadCountPagination, |
6 | checkBadSortPagination, | |
7 | checkBadStartPagination, | |
7c3b7976 | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
c0e8b12e | 10 | doubleFollow, |
d4a8e7a6 C |
11 | makeDeleteRequest, |
12 | makeGetRequest, | |
13 | makePostBodyRequest, | |
c48e82b5 | 14 | makePutBodyRequest, |
254d3579 | 15 | PeerTubeServer, |
d4a8e7a6 | 16 | setAccessTokensToServers, |
d4a8e7a6 | 17 | waitJobs |
c0e8b12e C |
18 | } from '@shared/extra-utils' |
19 | import { HttpStatusCode, VideoCreateResult } from '@shared/models' | |
c48e82b5 C |
20 | |
21 | describe('Test server redundancy API validators', function () { | |
254d3579 | 22 | let servers: PeerTubeServer[] |
c48e82b5 | 23 | let userAccessToken = null |
b764380a | 24 | let videoIdLocal: number |
d4a8e7a6 | 25 | let videoRemote: VideoCreateResult |
c48e82b5 C |
26 | |
27 | // --------------------------------------------------------------- | |
28 | ||
29 | before(async function () { | |
496b5a5b | 30 | this.timeout(80000) |
c48e82b5 | 31 | |
254d3579 | 32 | servers = await createMultipleServers(2) |
c48e82b5 C |
33 | |
34 | await setAccessTokensToServers(servers) | |
35 | await doubleFollow(servers[0], servers[1]) | |
36 | ||
37 | const user = { | |
38 | username: 'user1', | |
39 | password: 'password' | |
40 | } | |
41 | ||
89d241a7 C |
42 | await servers[0].users.create({ username: user.username, password: user.password }) |
43 | userAccessToken = await servers[0].login.getAccessToken(user) | |
b764380a | 44 | |
89d241a7 | 45 | videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id |
f9b6d51f | 46 | |
89d241a7 | 47 | const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid |
b764380a C |
48 | |
49 | await waitJobs(servers) | |
f9b6d51f | 50 | |
89d241a7 | 51 | videoRemote = await servers[0].videos.get({ id: remoteUUID }) |
b764380a C |
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 () { | |
c0e8b12e | 66 | await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
b764380a C |
67 | }) |
68 | ||
69 | it('Should fail if the user is not an administrator', async function () { | |
c0e8b12e | 70 | await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
b764380a C |
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 () { | |
c0e8b12e | 94 | await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 }) |
b764380a C |
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 () { | |
c0e8b12e | 110 | await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
b764380a C |
111 | }) |
112 | ||
113 | it('Should fail if the user is not an administrator', async function () { | |
c0e8b12e | 114 | await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
b764380a C |
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 () { | |
c0e8b12e | 126 | await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
b764380a C |
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 () { | |
d4a8e7a6 C |
134 | await makePostBodyRequest({ |
135 | url, | |
136 | path, | |
137 | token, | |
138 | fields: { videoId: videoRemote.shortUUID }, | |
c0e8b12e | 139 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
d4a8e7a6 | 140 | }) |
b764380a C |
141 | }) |
142 | ||
143 | it('Should fail if the video is already duplicated', async function () { | |
144 | this.timeout(30000) | |
145 | ||
146 | await waitJobs(servers) | |
147 | ||
d4a8e7a6 C |
148 | await makePostBodyRequest({ |
149 | url, | |
150 | path, | |
151 | token, | |
152 | fields: { videoId: videoRemote.uuid }, | |
c0e8b12e | 153 | expectedStatus: HttpStatusCode.CONFLICT_409 |
d4a8e7a6 | 154 | }) |
b764380a C |
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 () { | |
c0e8b12e | 170 | await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
b764380a C |
171 | }) |
172 | ||
173 | it('Should fail if the user is not an administrator', async function () { | |
c0e8b12e | 174 | await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
b764380a C |
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 () { | |
c0e8b12e | 182 | await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
b764380a | 183 | }) |
c48e82b5 C |
184 | }) |
185 | ||
b764380a | 186 | describe('When updating server redundancy', function () { |
c48e82b5 C |
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, | |
7c3b7976 | 192 | path: path + '/localhost:' + servers[1].port, |
c48e82b5 C |
193 | fields: { redundancyAllowed: true }, |
194 | token: 'fake_token', | |
c0e8b12e | 195 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
c48e82b5 C |
196 | }) |
197 | }) | |
198 | ||
199 | it('Should fail if the user is not an administrator', async function () { | |
200 | await makePutBodyRequest({ | |
201 | url: servers[0].url, | |
7c3b7976 | 202 | path: path + '/localhost:' + servers[1].port, |
c48e82b5 C |
203 | fields: { redundancyAllowed: true }, |
204 | token: userAccessToken, | |
c0e8b12e | 205 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
c48e82b5 C |
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, | |
c0e8b12e | 215 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
c48e82b5 C |
216 | }) |
217 | }) | |
218 | ||
219 | it('Should fail without de redundancyAllowed param', async function () { | |
220 | await makePutBodyRequest({ | |
221 | url: servers[0].url, | |
7c3b7976 | 222 | path: path + '/localhost:' + servers[1].port, |
c48e82b5 C |
223 | fields: { blabla: true }, |
224 | token: servers[0].accessToken, | |
c0e8b12e | 225 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
c48e82b5 C |
226 | }) |
227 | }) | |
228 | ||
229 | it('Should succeed with the correct parameters', async function () { | |
230 | await makePutBodyRequest({ | |
231 | url: servers[0].url, | |
7c3b7976 | 232 | path: path + '/localhost:' + servers[1].port, |
c48e82b5 C |
233 | fields: { redundancyAllowed: true }, |
234 | token: servers[0].accessToken, | |
c0e8b12e | 235 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
c48e82b5 C |
236 | }) |
237 | }) | |
238 | }) | |
239 | ||
7c3b7976 C |
240 | after(async function () { |
241 | await cleanupTests(servers) | |
c48e82b5 C |
242 | }) |
243 | }) |