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