aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/pods.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/pods.ts')
-rw-r--r--server/tests/api/check-params/pods.ts287
1 files changed, 0 insertions, 287 deletions
diff --git a/server/tests/api/check-params/pods.ts b/server/tests/api/check-params/pods.ts
deleted file mode 100644
index 9f9c2e4f0..000000000
--- a/server/tests/api/check-params/pods.ts
+++ /dev/null
@@ -1,287 +0,0 @@
1/* tslint:disable:no-unused-expression */
2
3import * as request from 'supertest'
4import 'mocha'
5
6import {
7 ServerInfo,
8 flushTests,
9 runServer,
10 createUser,
11 loginAndGetAccessToken,
12 setAccessTokensToServers,
13 killallServers,
14 makePostBodyRequest
15} from '../../utils'
16
17describe('Test pods API validators', function () {
18 let server: ServerInfo
19
20 // ---------------------------------------------------------------
21
22 before(async function () {
23 this.timeout(45000)
24
25 await flushTests()
26 server = await runServer(1)
27
28 await setAccessTokensToServers([ server ])
29 })
30
31 describe('When managing friends', function () {
32 const path = '/api/v1/pods/'
33 let userAccessToken = null
34
35 before(async function () {
36 await createUser(server.url, server.accessToken, 'user1', 'password')
37 server.user = {
38 username: 'user1',
39 password: 'password'
40 }
41
42 userAccessToken = await loginAndGetAccessToken(server)
43 })
44
45 describe('When making friends', function () {
46 const body = {
47 hosts: [ 'localhost:9002' ]
48 }
49
50 it('Should fail without hosts', async function () {
51 await request(server.url)
52 .post(path + '/make-friends')
53 .set('Authorization', 'Bearer ' + server.accessToken)
54 .set('Accept', 'application/json')
55 .expect(400)
56 })
57
58 it('Should fail if hosts is not an array', async function () {
59 await request(server.url)
60 .post(path + '/make-friends')
61 .send({ hosts: 'localhost:9002' })
62 .set('Authorization', 'Bearer ' + server.accessToken)
63 .set('Accept', 'application/json')
64 .expect(400)
65 })
66
67 it('Should fail if the array is not composed by hosts', async function () {
68 await request(server.url)
69 .post(path + '/make-friends')
70 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
71 .set('Authorization', 'Bearer ' + server.accessToken)
72 .set('Accept', 'application/json')
73 .expect(400)
74 })
75
76 it('Should fail if the array is composed with http schemes', async function () {
77 await request(server.url)
78 .post(path + '/make-friends')
79 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
80 .set('Authorization', 'Bearer ' + server.accessToken)
81 .set('Accept', 'application/json')
82 .expect(400)
83 })
84
85 it('Should fail if hosts are not unique', async function () {
86 await request(server.url)
87 .post(path + '/make-friends')
88 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
89 .set('Authorization', 'Bearer ' + server.accessToken)
90 .set('Accept', 'application/json')
91 .expect(400)
92 })
93
94 it('Should fail with an invalid token', async function () {
95 await request(server.url)
96 .post(path + '/make-friends')
97 .send(body)
98 .set('Authorization', 'Bearer fake_token')
99 .set('Accept', 'application/json')
100 .expect(401)
101 })
102
103 it('Should fail if the user is not an administrator', async function () {
104 await request(server.url)
105 .post(path + '/make-friends')
106 .send(body)
107 .set('Authorization', 'Bearer ' + userAccessToken)
108 .set('Accept', 'application/json')
109 .expect(403)
110 })
111 })
112
113 describe('When listing friends', function () {
114 it('Should fail with a bad start pagination', async function () {
115 await request(server.url)
116 .get(path)
117 .query({ start: 'hello' })
118 .set('Accept', 'application/json')
119 .expect(400)
120 })
121
122 it('Should fail with a bad count pagination', async function () {
123 await request(server.url)
124 .get(path)
125 .query({ count: 'hello' })
126 .set('Accept', 'application/json')
127 .expect(400)
128 })
129
130 it('Should fail with an incorrect sort', async function () {
131 await request(server.url)
132 .get(path)
133 .query({ sort: 'hello' })
134 .set('Accept', 'application/json')
135 .expect(400)
136 })
137 })
138
139 describe('When quitting friends', function () {
140 it('Should fail with an invalid token', async function () {
141 await request(server.url)
142 .get(path + '/quit-friends')
143 .query({ start: 'hello' })
144 .set('Authorization', 'Bearer faketoken')
145 .set('Accept', 'application/json')
146 .expect(401)
147 })
148
149 it('Should fail if the user is not an administrator', async function () {
150 await request(server.url)
151 .get(path + '/quit-friends')
152 .query({ start: 'hello' })
153 .set('Authorization', 'Bearer ' + userAccessToken)
154 .set('Accept', 'application/json')
155 .expect(403)
156 })
157 })
158
159 describe('When removing one friend', function () {
160 it('Should fail with an invalid token', async function () {
161 await request(server.url)
162 .delete(path + '/1')
163 .set('Authorization', 'Bearer faketoken')
164 .set('Accept', 'application/json')
165 .expect(401)
166 })
167
168 it('Should fail if the user is not an administrator', async function () {
169 await request(server.url)
170 .delete(path + '/1')
171 .set('Authorization', 'Bearer ' + userAccessToken)
172 .set('Accept', 'application/json')
173 .expect(403)
174 })
175
176 it('Should fail with an undefined id', async function () {
177 await request(server.url)
178 .delete(path + '/' + undefined)
179 .set('Authorization', 'Bearer ' + server.accessToken)
180 .set('Accept', 'application/json')
181 .expect(400)
182 })
183
184 it('Should fail with an invalid id', async function () {
185 await request(server.url)
186 .delete(path + '/foobar')
187 .set('Authorization', 'Bearer ' + server.accessToken)
188 .set('Accept', 'application/json')
189 .expect(400)
190 })
191
192 it('Should fail if the pod is not a friend', async function () {
193 await request(server.url)
194 .delete(path + '/-1')
195 .set('Authorization', 'Bearer ' + server.accessToken)
196 .set('Accept', 'application/json')
197 .expect(404)
198 })
199
200 it('Should succeed with the correct parameters')
201 })
202 })
203
204 describe('When adding a pod from remote', function () {
205 const path = '/api/v1/remote/pods/add'
206
207 it('Should fail with nothing', async function () {
208 const fields = {}
209 await makePostBodyRequest({ url: server.url, path, fields })
210 })
211
212 it('Should fail without public key', async function () {
213 const fields = {
214 email: 'test.example.com',
215 host: 'coucou.com'
216 }
217 await makePostBodyRequest({ url: server.url, path, fields })
218 })
219
220 it('Should fail without an email', async function () {
221 const fields = {
222 host: 'coucou.com',
223 publicKey: 'my super public key'
224 }
225 await makePostBodyRequest({ url: server.url, path, fields })
226 })
227
228 it('Should fail without an invalid email', async function () {
229 const fields = {
230 host: 'coucou.com',
231 email: 'test.example.com',
232 publicKey: 'my super public key'
233 }
234 await makePostBodyRequest({ url: server.url, path, fields })
235 })
236
237 it('Should fail without a host', async function () {
238 const fields = {
239 email: 'test.example.com',
240 publicKey: 'my super public key'
241 }
242 await makePostBodyRequest({ url: server.url, path, fields })
243 })
244
245 it('Should fail with an incorrect host', async function () {
246 const fields = {
247 host: 'http://coucou.com',
248 email: 'test.example.com',
249 publicKey: 'my super public key'
250 }
251 await makePostBodyRequest({ url: server.url, path, fields })
252
253 fields.host = 'http://coucou'
254 await makePostBodyRequest({ url: server.url, path, fields })
255
256 fields.host = 'coucou'
257 await makePostBodyRequest({ url: server.url, path, fields })
258 })
259
260 it('Should succeed with the correct parameters', async function () {
261 const fields = {
262 host: 'coucou.com',
263 email: 'test@example.com',
264 publicKey: 'my super public key'
265 }
266 await makePostBodyRequest({ url: server.url, path, fields, statusCodeExpected: 200 })
267 })
268
269 it('Should fail with a host that already exists', async function () {
270 const fields = {
271 host: 'coucou.com',
272 email: 'test@example.com',
273 publicKey: 'my super public key'
274 }
275 await makePostBodyRequest({ url: server.url, path, fields, statusCodeExpected: 409 })
276 })
277 })
278
279 after(async function () {
280 killallServers([ server ])
281
282 // Keep the logs if the test failed
283 if (this['ok']) {
284 await flushTests()
285 }
286 })
287})