]>
Commit | Line | Data |
---|---|---|
72329aaa C |
1 | /* eslint-disable no-unused-expressions */ |
2 | ||
55fa55a9 C |
3 | 'use strict' |
4 | ||
5 | const request = require('supertest') | |
6 | const series = require('async/series') | |
7 | ||
8 | const loginUtils = require('../../utils/login') | |
9 | const requestsUtils = require('../../utils/requests') | |
10 | const serversUtils = require('../../utils/servers') | |
11 | const usersUtils = require('../../utils/users') | |
12 | const videosUtils = require('../../utils/videos') | |
13 | ||
14 | describe('Test video abuses API validators', function () { | |
15 | let server = null | |
16 | let userAccessToken = null | |
17 | ||
18 | // --------------------------------------------------------------- | |
19 | ||
20 | before(function (done) { | |
21 | this.timeout(20000) | |
22 | ||
23 | series([ | |
24 | function (next) { | |
25 | serversUtils.flushTests(next) | |
26 | }, | |
27 | function (next) { | |
28 | serversUtils.runServer(1, function (server1) { | |
29 | server = server1 | |
30 | ||
31 | next() | |
32 | }) | |
33 | }, | |
34 | function (next) { | |
35 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | |
36 | if (err) throw err | |
37 | server.accessToken = token | |
38 | ||
39 | next() | |
40 | }) | |
41 | }, | |
42 | function (next) { | |
43 | const username = 'user1' | |
44 | const password = 'my super password' | |
45 | ||
46 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | |
47 | }, | |
48 | function (next) { | |
49 | const user = { | |
50 | username: 'user1', | |
51 | password: 'my super password' | |
52 | } | |
53 | ||
54 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | |
55 | if (err) throw err | |
56 | ||
57 | userAccessToken = accessToken | |
58 | ||
59 | next() | |
60 | }) | |
61 | }, | |
62 | // Upload some videos on each pods | |
63 | function (next) { | |
64 | const name = 'my super name for pod' | |
65 | const description = 'my super description for pod' | |
66 | const tags = [ 'tag' ] | |
67 | const file = 'video_short2.webm' | |
68 | videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) | |
69 | }, | |
70 | function (next) { | |
71 | videosUtils.getVideosList(server.url, function (err, res) { | |
72 | if (err) throw err | |
73 | ||
74 | const videos = res.body.data | |
75 | server.video = videos[0] | |
76 | ||
77 | next() | |
78 | }) | |
79 | } | |
80 | ], done) | |
81 | }) | |
82 | ||
83 | describe('When listing video abuses', function () { | |
84 | const path = '/api/v1/videos/abuse' | |
85 | ||
86 | it('Should fail with a bad start pagination', function (done) { | |
87 | request(server.url) | |
88 | .get(path) | |
89 | .query({ start: 'hello' }) | |
90 | .set('Authorization', 'Bearer ' + server.accessToken) | |
91 | .set('Accept', 'application/json') | |
92 | .expect(400, done) | |
93 | }) | |
94 | ||
95 | it('Should fail with a bad count pagination', function (done) { | |
96 | request(server.url) | |
97 | .get(path) | |
98 | .query({ count: 'hello' }) | |
99 | .set('Accept', 'application/json') | |
100 | .set('Authorization', 'Bearer ' + server.accessToken) | |
101 | .expect(400, done) | |
102 | }) | |
103 | ||
104 | it('Should fail with an incorrect sort', function (done) { | |
105 | request(server.url) | |
106 | .get(path) | |
107 | .query({ sort: 'hello' }) | |
108 | .set('Accept', 'application/json') | |
109 | .set('Authorization', 'Bearer ' + server.accessToken) | |
110 | .expect(400, done) | |
111 | }) | |
112 | ||
113 | it('Should fail with a non authenticated user', function (done) { | |
114 | request(server.url) | |
115 | .get(path) | |
116 | .query({ sort: 'hello' }) | |
117 | .set('Accept', 'application/json') | |
118 | .expect(401, done) | |
119 | }) | |
120 | ||
121 | it('Should fail with a non admin user', function (done) { | |
122 | request(server.url) | |
123 | .get(path) | |
124 | .query({ sort: 'hello' }) | |
125 | .set('Accept', 'application/json') | |
126 | .set('Authorization', 'Bearer ' + userAccessToken) | |
127 | .expect(403, done) | |
128 | }) | |
129 | }) | |
130 | ||
131 | describe('When reporting a video abuse', function () { | |
132 | const basePath = '/api/v1/videos/' | |
133 | ||
134 | it('Should fail with nothing', function (done) { | |
135 | const path = basePath + server.video + '/abuse' | |
136 | const data = {} | |
137 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | |
138 | }) | |
139 | ||
140 | it('Should fail with a wrong video', function (done) { | |
141 | const wrongPath = '/api/v1/videos/blabla/abuse' | |
142 | const data = {} | |
143 | requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done) | |
144 | }) | |
145 | ||
146 | it('Should fail with a non authenticated user', function (done) { | |
147 | const data = {} | |
148 | const path = basePath + server.video + '/abuse' | |
149 | requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) | |
150 | }) | |
151 | ||
152 | it('Should fail with a reason too short', function (done) { | |
153 | const data = { | |
154 | reason: 'h' | |
155 | } | |
156 | const path = basePath + server.video + '/abuse' | |
157 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | |
158 | }) | |
159 | ||
160 | it('Should fail with a reason too big', function (done) { | |
161 | const data = { | |
162 | reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | |
163 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | |
164 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | |
165 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' | |
166 | } | |
167 | const path = basePath + server.video + '/abuse' | |
168 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | |
169 | }) | |
170 | }) | |
171 | ||
172 | after(function (done) { | |
173 | process.kill(-server.app.pid) | |
174 | ||
175 | // Keep the logs if the test failed | |
176 | if (this.ok) { | |
177 | serversUtils.flushTests(done) | |
178 | } else { | |
179 | done() | |
180 | } | |
181 | }) | |
182 | }) |