]>
Commit | Line | Data |
---|---|---|
7ad9b984 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, | |
7 | doubleFollow, | |
8 | flushAndRunMultipleServers, | |
9 | flushTests, | |
10 | killallServers, | |
11 | makeDeleteRequest, | |
12 | makeGetRequest, | |
13 | makePostBodyRequest, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers | |
16 | } from '../../utils' | |
17 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
18 | ||
19 | describe('Test blocklist API validators', function () { | |
20 | let servers: ServerInfo[] | |
21 | let server: ServerInfo | |
22 | ||
23 | before(async function () { | |
24 | this.timeout(60000) | |
25 | ||
26 | await flushTests() | |
27 | ||
28 | servers = await flushAndRunMultipleServers(2) | |
29 | await setAccessTokensToServers(servers) | |
30 | ||
31 | server = servers[0] | |
32 | ||
33 | const user = { username: 'user1', password: 'password' } | |
34 | await createUser(server.url, server.accessToken, user.username, user.password) | |
35 | ||
36 | await doubleFollow(servers[0], servers[1]) | |
37 | }) | |
38 | ||
39 | // --------------------------------------------------------------- | |
40 | ||
41 | describe('When managing user blocklist', function () { | |
42 | const path = '/api/v1/users/me/blocklist/accounts' | |
43 | ||
44 | describe('When managing user accounts blocklist', function () { | |
45 | ||
46 | describe('When listing blocked accounts', function () { | |
47 | it('Should fail with an unauthenticated user', async function () { | |
48 | await makeGetRequest({ | |
49 | url: server.url, | |
50 | path, | |
51 | statusCodeExpected: 401 | |
52 | }) | |
53 | }) | |
54 | ||
55 | it('Should fail with a bad start pagination', async function () { | |
56 | await checkBadStartPagination(server.url, path, server.accessToken) | |
57 | }) | |
58 | ||
59 | it('Should fail with a bad count pagination', async function () { | |
60 | await checkBadCountPagination(server.url, path, server.accessToken) | |
61 | }) | |
62 | ||
63 | it('Should fail with an incorrect sort', async function () { | |
64 | await checkBadSortPagination(server.url, path, server.accessToken) | |
65 | }) | |
66 | }) | |
67 | ||
68 | describe('When blocking an account', function () { | |
69 | it('Should fail with an unauthenticated user', async function () { | |
70 | await makePostBodyRequest({ | |
71 | url: server.url, | |
72 | path, | |
73 | fields: { accountName: 'user1' }, | |
74 | statusCodeExpected: 401 | |
75 | }) | |
76 | }) | |
77 | ||
78 | it('Should fail with an unknown account', async function () { | |
79 | await makePostBodyRequest({ | |
80 | url: server.url, | |
81 | token: server.accessToken, | |
82 | path, | |
83 | fields: { accountName: 'user2' }, | |
84 | statusCodeExpected: 404 | |
85 | }) | |
86 | }) | |
87 | ||
af5767ff C |
88 | it('Should fail to block ourselves', async function () { |
89 | await makePostBodyRequest({ | |
90 | url: server.url, | |
91 | token: server.accessToken, | |
92 | path, | |
93 | fields: { accountName: 'root' }, | |
94 | statusCodeExpected: 409 | |
95 | }) | |
96 | }) | |
97 | ||
7ad9b984 C |
98 | it('Should succeed with the correct params', async function () { |
99 | await makePostBodyRequest({ | |
100 | url: server.url, | |
101 | token: server.accessToken, | |
102 | path, | |
103 | fields: { accountName: 'user1' }, | |
104 | statusCodeExpected: 204 | |
105 | }) | |
106 | }) | |
107 | }) | |
108 | ||
109 | describe('When unblocking an account', function () { | |
110 | it('Should fail with an unauthenticated user', async function () { | |
111 | await makeDeleteRequest({ | |
112 | url: server.url, | |
113 | path: path + '/user1', | |
114 | statusCodeExpected: 401 | |
115 | }) | |
116 | }) | |
117 | ||
118 | it('Should fail with an unknown account block', async function () { | |
119 | await makeDeleteRequest({ | |
120 | url: server.url, | |
121 | path: path + '/user2', | |
122 | token: server.accessToken, | |
123 | statusCodeExpected: 404 | |
124 | }) | |
125 | }) | |
126 | ||
127 | it('Should succeed with the correct params', async function () { | |
128 | await makeDeleteRequest({ | |
129 | url: server.url, | |
130 | path: path + '/user1', | |
131 | token: server.accessToken, | |
132 | statusCodeExpected: 204 | |
133 | }) | |
134 | }) | |
135 | }) | |
136 | }) | |
137 | ||
138 | describe('When managing user servers blocklist', function () { | |
139 | const path = '/api/v1/users/me/blocklist/servers' | |
140 | ||
141 | describe('When listing blocked servers', function () { | |
142 | it('Should fail with an unauthenticated user', async function () { | |
143 | await makeGetRequest({ | |
144 | url: server.url, | |
145 | path, | |
146 | statusCodeExpected: 401 | |
147 | }) | |
148 | }) | |
149 | ||
150 | it('Should fail with a bad start pagination', async function () { | |
151 | await checkBadStartPagination(server.url, path, server.accessToken) | |
152 | }) | |
153 | ||
154 | it('Should fail with a bad count pagination', async function () { | |
155 | await checkBadCountPagination(server.url, path, server.accessToken) | |
156 | }) | |
157 | ||
158 | it('Should fail with an incorrect sort', async function () { | |
159 | await checkBadSortPagination(server.url, path, server.accessToken) | |
160 | }) | |
161 | }) | |
162 | ||
163 | describe('When blocking a server', function () { | |
164 | it('Should fail with an unauthenticated user', async function () { | |
165 | await makePostBodyRequest({ | |
166 | url: server.url, | |
167 | path, | |
168 | fields: { host: 'localhost:9002' }, | |
169 | statusCodeExpected: 401 | |
170 | }) | |
171 | }) | |
172 | ||
173 | it('Should fail with an unknown server', async function () { | |
174 | await makePostBodyRequest({ | |
175 | url: server.url, | |
176 | token: server.accessToken, | |
177 | path, | |
178 | fields: { host: 'localhost:9003' }, | |
179 | statusCodeExpected: 404 | |
180 | }) | |
181 | }) | |
182 | ||
af5767ff C |
183 | it('Should fail with our own server', async function () { |
184 | await makePostBodyRequest({ | |
185 | url: server.url, | |
186 | token: server.accessToken, | |
187 | path, | |
188 | fields: { host: 'localhost:9001' }, | |
189 | statusCodeExpected: 409 | |
190 | }) | |
191 | }) | |
192 | ||
7ad9b984 C |
193 | it('Should succeed with the correct params', async function () { |
194 | await makePostBodyRequest({ | |
195 | url: server.url, | |
196 | token: server.accessToken, | |
197 | path, | |
198 | fields: { host: 'localhost:9002' }, | |
199 | statusCodeExpected: 204 | |
200 | }) | |
201 | }) | |
202 | }) | |
203 | ||
204 | describe('When unblocking a server', function () { | |
205 | it('Should fail with an unauthenticated user', async function () { | |
206 | await makeDeleteRequest({ | |
207 | url: server.url, | |
208 | path: path + '/localhost:9002', | |
209 | statusCodeExpected: 401 | |
210 | }) | |
211 | }) | |
212 | ||
213 | it('Should fail with an unknown server block', async function () { | |
214 | await makeDeleteRequest({ | |
215 | url: server.url, | |
216 | path: path + '/localhost:9003', | |
217 | token: server.accessToken, | |
218 | statusCodeExpected: 404 | |
219 | }) | |
220 | }) | |
221 | ||
222 | it('Should succeed with the correct params', async function () { | |
223 | await makeDeleteRequest({ | |
224 | url: server.url, | |
225 | path: path + '/localhost:9002', | |
226 | token: server.accessToken, | |
227 | statusCodeExpected: 204 | |
228 | }) | |
229 | }) | |
230 | }) | |
231 | }) | |
232 | }) | |
233 | ||
234 | after(async function () { | |
235 | killallServers(servers) | |
236 | ||
237 | // Keep the logs if the test failed | |
238 | if (this['ok']) { | |
239 | await flushTests() | |
240 | } | |
241 | }) | |
242 | }) |