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