diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-12 15:26:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-16 16:41:36 +0200 |
commit | 7ad9b9846c44d198a736183fb186c2039f5236b5 (patch) | |
tree | 9c8456882a261c0522efb507f20e323c2741a0f8 /server/tests/api/check-params | |
parent | dffd5d127f49eb63d2b2b3133aec75ec1d7e4dcb (diff) | |
download | PeerTube-7ad9b9846c44d198a736183fb186c2039f5236b5.tar.gz PeerTube-7ad9b9846c44d198a736183fb186c2039f5236b5.tar.zst PeerTube-7ad9b9846c44d198a736183fb186c2039f5236b5.zip |
Add ability for users to block an account/instance on server side
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/blocklist.ts | 222 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 |
2 files changed, 223 insertions, 0 deletions
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts new file mode 100644 index 000000000..8117c46a6 --- /dev/null +++ b/server/tests/api/check-params/blocklist.ts | |||
@@ -0,0 +1,222 @@ | |||
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 | |||
88 | it('Should succeed with the correct params', async function () { | ||
89 | await makePostBodyRequest({ | ||
90 | url: server.url, | ||
91 | token: server.accessToken, | ||
92 | path, | ||
93 | fields: { accountName: 'user1' }, | ||
94 | statusCodeExpected: 204 | ||
95 | }) | ||
96 | }) | ||
97 | }) | ||
98 | |||
99 | describe('When unblocking an account', function () { | ||
100 | it('Should fail with an unauthenticated user', async function () { | ||
101 | await makeDeleteRequest({ | ||
102 | url: server.url, | ||
103 | path: path + '/user1', | ||
104 | statusCodeExpected: 401 | ||
105 | }) | ||
106 | }) | ||
107 | |||
108 | it('Should fail with an unknown account block', async function () { | ||
109 | await makeDeleteRequest({ | ||
110 | url: server.url, | ||
111 | path: path + '/user2', | ||
112 | token: server.accessToken, | ||
113 | statusCodeExpected: 404 | ||
114 | }) | ||
115 | }) | ||
116 | |||
117 | it('Should succeed with the correct params', async function () { | ||
118 | await makeDeleteRequest({ | ||
119 | url: server.url, | ||
120 | path: path + '/user1', | ||
121 | token: server.accessToken, | ||
122 | statusCodeExpected: 204 | ||
123 | }) | ||
124 | }) | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | describe('When managing user servers blocklist', function () { | ||
129 | const path = '/api/v1/users/me/blocklist/servers' | ||
130 | |||
131 | describe('When listing blocked servers', function () { | ||
132 | it('Should fail with an unauthenticated user', async function () { | ||
133 | await makeGetRequest({ | ||
134 | url: server.url, | ||
135 | path, | ||
136 | statusCodeExpected: 401 | ||
137 | }) | ||
138 | }) | ||
139 | |||
140 | it('Should fail with a bad start pagination', async function () { | ||
141 | await checkBadStartPagination(server.url, path, server.accessToken) | ||
142 | }) | ||
143 | |||
144 | it('Should fail with a bad count pagination', async function () { | ||
145 | await checkBadCountPagination(server.url, path, server.accessToken) | ||
146 | }) | ||
147 | |||
148 | it('Should fail with an incorrect sort', async function () { | ||
149 | await checkBadSortPagination(server.url, path, server.accessToken) | ||
150 | }) | ||
151 | }) | ||
152 | |||
153 | describe('When blocking a server', function () { | ||
154 | it('Should fail with an unauthenticated user', async function () { | ||
155 | await makePostBodyRequest({ | ||
156 | url: server.url, | ||
157 | path, | ||
158 | fields: { host: 'localhost:9002' }, | ||
159 | statusCodeExpected: 401 | ||
160 | }) | ||
161 | }) | ||
162 | |||
163 | it('Should fail with an unknown server', async function () { | ||
164 | await makePostBodyRequest({ | ||
165 | url: server.url, | ||
166 | token: server.accessToken, | ||
167 | path, | ||
168 | fields: { host: 'localhost:9003' }, | ||
169 | statusCodeExpected: 404 | ||
170 | }) | ||
171 | }) | ||
172 | |||
173 | it('Should succeed with the correct params', async function () { | ||
174 | await makePostBodyRequest({ | ||
175 | url: server.url, | ||
176 | token: server.accessToken, | ||
177 | path, | ||
178 | fields: { host: 'localhost:9002' }, | ||
179 | statusCodeExpected: 204 | ||
180 | }) | ||
181 | }) | ||
182 | }) | ||
183 | |||
184 | describe('When unblocking a server', function () { | ||
185 | it('Should fail with an unauthenticated user', async function () { | ||
186 | await makeDeleteRequest({ | ||
187 | url: server.url, | ||
188 | path: path + '/localhost:9002', | ||
189 | statusCodeExpected: 401 | ||
190 | }) | ||
191 | }) | ||
192 | |||
193 | it('Should fail with an unknown server block', async function () { | ||
194 | await makeDeleteRequest({ | ||
195 | url: server.url, | ||
196 | path: path + '/localhost:9003', | ||
197 | token: server.accessToken, | ||
198 | statusCodeExpected: 404 | ||
199 | }) | ||
200 | }) | ||
201 | |||
202 | it('Should succeed with the correct params', async function () { | ||
203 | await makeDeleteRequest({ | ||
204 | url: server.url, | ||
205 | path: path + '/localhost:9002', | ||
206 | token: server.accessToken, | ||
207 | statusCodeExpected: 204 | ||
208 | }) | ||
209 | }) | ||
210 | }) | ||
211 | }) | ||
212 | }) | ||
213 | |||
214 | after(async function () { | ||
215 | killallServers(servers) | ||
216 | |||
217 | // Keep the logs if the test failed | ||
218 | if (this['ok']) { | ||
219 | await flushTests() | ||
220 | } | ||
221 | }) | ||
222 | }) | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index bfc550ae5..877ceb0a7 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | import './accounts' | 2 | import './accounts' |
3 | import './blocklist' | ||
3 | import './config' | 4 | import './config' |
4 | import './follows' | 5 | import './follows' |
5 | import './jobs' | 6 | import './jobs' |