1 /* tslint:disable:no-unused-expression */
6 createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, flushAndRunServer, ServerInfo, setAccessTokensToServers,
8 } from '../../../../shared/extra-utils'
10 checkBadCountPagination,
11 checkBadSortPagination,
12 checkBadStartPagination
13 } from '../../../../shared/extra-utils/requests/check-api-params'
15 describe('Test server follows API validators', function () {
16 let server: ServerInfo
18 // ---------------------------------------------------------------
20 before(async function () {
23 server = await flushAndRunServer(1)
25 await setAccessTokensToServers([ server ])
28 describe('When managing following', function () {
29 let userAccessToken = null
31 before(async function () {
37 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
38 userAccessToken = await userLogin(server, user)
41 describe('When adding follows', function () {
42 const path = '/api/v1/server/following'
44 it('Should fail without hosts', async function () {
45 await makePostBodyRequest({
48 token: server.accessToken,
49 statusCodeExpected: 400
53 it('Should fail if hosts is not an array', async function () {
54 await makePostBodyRequest({
57 token: server.accessToken,
58 fields: { hosts: 'localhost:9002' },
59 statusCodeExpected: 400
63 it('Should fail if the array is not composed by hosts', async function () {
64 await makePostBodyRequest({
67 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
68 token: server.accessToken,
69 statusCodeExpected: 400
73 it('Should fail if the array is composed with http schemes', async function () {
74 await makePostBodyRequest({
77 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
78 token: server.accessToken,
79 statusCodeExpected: 400
83 it('Should fail if hosts are not unique', async function () {
84 await makePostBodyRequest({
87 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
88 token: server.accessToken,
89 statusCodeExpected: 400
93 it('Should fail with an invalid token', async function () {
94 await makePostBodyRequest({
97 fields: { hosts: [ 'localhost:9002' ] },
99 statusCodeExpected: 401
103 it('Should fail if the user is not an administrator', async function () {
104 await makePostBodyRequest({
107 fields: { hosts: [ 'localhost:9002' ] },
108 token: userAccessToken,
109 statusCodeExpected: 403
114 describe('When listing followings', function () {
115 const path = '/api/v1/server/following'
117 it('Should fail with a bad start pagination', async function () {
118 await checkBadStartPagination(server.url, path)
121 it('Should fail with a bad count pagination', async function () {
122 await checkBadCountPagination(server.url, path)
125 it('Should fail with an incorrect sort', async function () {
126 await checkBadSortPagination(server.url, path)
130 describe('When listing followers', function () {
131 const path = '/api/v1/server/followers'
133 it('Should fail with a bad start pagination', async function () {
134 await checkBadStartPagination(server.url, path)
137 it('Should fail with a bad count pagination', async function () {
138 await checkBadCountPagination(server.url, path)
141 it('Should fail with an incorrect sort', async function () {
142 await checkBadSortPagination(server.url, path)
146 describe('When removing a follower', function () {
147 const path = '/api/v1/server/followers'
149 it('Should fail with an invalid token', async function () {
150 await makeDeleteRequest({
152 path: path + '/toto@localhost:9002',
154 statusCodeExpected: 401
158 it('Should fail if the user is not an administrator', async function () {
159 await makeDeleteRequest({
161 path: path + '/toto@localhost:9002',
162 token: userAccessToken,
163 statusCodeExpected: 403
167 it('Should fail with an invalid follower', async function () {
168 await makeDeleteRequest({
170 path: path + '/toto',
171 token: server.accessToken,
172 statusCodeExpected: 400
176 it('Should fail with an unknown follower', async function () {
177 await makeDeleteRequest({
179 path: path + '/toto@localhost:9003',
180 token: server.accessToken,
181 statusCodeExpected: 404
186 describe('When accepting a follower', function () {
187 const path = '/api/v1/server/followers'
189 it('Should fail with an invalid token', async function () {
190 await makePostBodyRequest({
192 path: path + '/toto@localhost:9002/accept',
194 statusCodeExpected: 401
198 it('Should fail if the user is not an administrator', async function () {
199 await makePostBodyRequest({
201 path: path + '/toto@localhost:9002/accept',
202 token: userAccessToken,
203 statusCodeExpected: 403
207 it('Should fail with an invalid follower', async function () {
208 await makePostBodyRequest({
210 path: path + '/toto/accept',
211 token: server.accessToken,
212 statusCodeExpected: 400
216 it('Should fail with an unknown follower', async function () {
217 await makePostBodyRequest({
219 path: path + '/toto@localhost:9003/accept',
220 token: server.accessToken,
221 statusCodeExpected: 404
226 describe('When rejecting a follower', function () {
227 const path = '/api/v1/server/followers'
229 it('Should fail with an invalid token', async function () {
230 await makePostBodyRequest({
232 path: path + '/toto@localhost:9002/reject',
234 statusCodeExpected: 401
238 it('Should fail if the user is not an administrator', async function () {
239 await makePostBodyRequest({
241 path: path + '/toto@localhost:9002/reject',
242 token: userAccessToken,
243 statusCodeExpected: 403
247 it('Should fail with an invalid follower', async function () {
248 await makePostBodyRequest({
250 path: path + '/toto/reject',
251 token: server.accessToken,
252 statusCodeExpected: 400
256 it('Should fail with an unknown follower', async function () {
257 await makePostBodyRequest({
259 path: path + '/toto@localhost:9003/reject',
260 token: server.accessToken,
261 statusCodeExpected: 404
266 describe('When removing following', function () {
267 const path = '/api/v1/server/following'
269 it('Should fail with an invalid token', async function () {
270 await makeDeleteRequest({
272 path: path + '/localhost:9002',
274 statusCodeExpected: 401
278 it('Should fail if the user is not an administrator', async function () {
279 await makeDeleteRequest({
281 path: path + '/localhost:9002',
282 token: userAccessToken,
283 statusCodeExpected: 403
287 it('Should fail if we do not follow this server', async function () {
288 await makeDeleteRequest({
290 path: path + '/example.com',
291 token: server.accessToken,
292 statusCodeExpected: 404
299 killallServers([ server ])