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