aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/requests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
commit99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch)
treec9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/tests/api/check-params/requests.js
parentfcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff)
parent91cc839af88730ba55f84997c56b85ea100070a7 (diff)
downloadPeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip
Merge branch 'postgresql'
Diffstat (limited to 'server/tests/api/check-params/requests.js')
-rw-r--r--server/tests/api/check-params/requests.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/server/tests/api/check-params/requests.js b/server/tests/api/check-params/requests.js
new file mode 100644
index 000000000..08f58db43
--- /dev/null
+++ b/server/tests/api/check-params/requests.js
@@ -0,0 +1,87 @@
1'use strict'
2
3const request = require('supertest')
4const series = require('async/series')
5
6const loginUtils = require('../../utils/login')
7const usersUtils = require('../../utils/users')
8const serversUtils = require('../../utils/servers')
9
10describe('Test requests API validators', function () {
11 const path = '/api/v1/requests/stats'
12 let server = null
13 let userAccessToken = null
14
15 // ---------------------------------------------------------------
16
17 before(function (done) {
18 this.timeout(20000)
19
20 series([
21 function (next) {
22 serversUtils.flushTests(next)
23 },
24 function (next) {
25 serversUtils.runServer(1, function (server1) {
26 server = server1
27
28 next()
29 })
30 },
31 function (next) {
32 loginUtils.loginAndGetAccessToken(server, function (err, token) {
33 if (err) throw err
34 server.accessToken = token
35
36 next()
37 })
38 },
39 function (next) {
40 const username = 'user'
41 const password = 'my super password'
42
43 usersUtils.createUser(server.url, server.accessToken, username, password, next)
44 },
45 function (next) {
46 const user = {
47 username: 'user',
48 password: 'my super password'
49 }
50
51 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
52 if (err) throw err
53
54 userAccessToken = accessToken
55
56 next()
57 })
58 }
59 ], done)
60 })
61
62 it('Should fail with an non authenticated user', function (done) {
63 request(server.url)
64 .get(path)
65 .set('Accept', 'application/json')
66 .expect(401, done)
67 })
68
69 it('Should fail with a non admin user', function (done) {
70 request(server.url)
71 .get(path)
72 .set('Authorization', 'Bearer ' + userAccessToken)
73 .set('Accept', 'application/json')
74 .expect(403, done)
75 })
76
77 after(function (done) {
78 process.kill(-server.app.pid)
79
80 // Keep the logs if the test failed
81 if (this.ok) {
82 serversUtils.flushTests(done)
83 } else {
84 done()
85 }
86 })
87})