]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params.js
Move tags in another table
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params.js
index f060b2ad4d97fca8b7655a31f9740f797de90a95..9aecc372077c69daab3fd3640d14c18e3788e2c9 100644 (file)
@@ -13,6 +13,7 @@ const usersUtils = require('../utils/users')
 
 describe('Test parameters validator', function () {
   let server = null
+  let userAccessToken = null
 
   // ---------------------------------------------------------------
 
@@ -66,10 +67,10 @@ describe('Test parameters validator', function () {
 
       describe('When making friends', function () {
         const body = {
-          urls: [ 'http://localhost:9002' ]
+          hosts: [ 'localhost:9002' ]
         }
 
-        it('Should fail without urls', function (done) {
+        it('Should fail without hosts', function (done) {
           request(server.url)
             .post(path + '/makefriends')
             .set('Authorization', 'Bearer ' + server.accessToken)
@@ -77,28 +78,37 @@ describe('Test parameters validator', function () {
             .expect(400, done)
         })
 
-        it('Should fail with urls is not an array', function (done) {
+        it('Should fail if hosts is not an array', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: 'http://localhost:9002' })
+            .send({ hosts: 'localhost:9002' })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
         })
 
-        it('Should fail if the array is not composed by urls', function (done) {
+        it('Should fail if the array is not composed by hosts', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: [ 'http://localhost:9002', 'localhost:coucou' ] })
+            .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
         })
 
-        it('Should fail if urls are not unique', function (done) {
+        it('Should fail if the array is composed with http schemes', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: [ 'http://localhost:9002', 'http://localhost:9002' ] })
+            .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
+            .set('Authorization', 'Bearer ' + server.accessToken)
+            .set('Accept', 'application/json')
+            .expect(400, done)
+        })
+
+        it('Should fail if hosts are not unique', function (done) {
+          request(server.url)
+            .post(path + '/makefriends')
+            .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
@@ -152,27 +162,27 @@ describe('Test parameters validator', function () {
 
       it('Should fail without public key', function (done) {
         const data = {
-          url: 'http://coucou.com'
+          host: 'coucou.com'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
       })
 
-      it('Should fail without an url', function (done) {
+      it('Should fail without an host', function (done) {
         const data = {
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
       })
 
-      it('Should fail with an incorrect url', function (done) {
+      it('Should fail with an incorrect host', function (done) {
         const data = {
-          url: 'coucou.com',
+          host: 'http://coucou.com',
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
-          data.url = 'http://coucou'
+          data.host = 'http://coucou'
           requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
-            data.url = 'coucou'
+            data.host = 'coucou'
             requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
           })
         })
@@ -180,7 +190,7 @@ describe('Test parameters validator', function () {
 
       it('Should succeed with the correct parameters', function (done) {
         const data = {
-          url: 'http://coucou.com',
+          host: 'coucou.com',
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)
@@ -446,7 +456,7 @@ describe('Test parameters validator', function () {
           })
       })
 
-      it('Should fail without a mongodb id', function (done) {
+      it('Should fail without a correct uuid', function (done) {
         request(server.url)
           .get(path + 'coucou')
           .set('Accept', 'application/json')
@@ -455,7 +465,7 @@ describe('Test parameters validator', function () {
 
       it('Should return 404 with an incorrect video', function (done) {
         request(server.url)
-          .get(path + '123456789012345678901234')
+          .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
           .set('Accept', 'application/json')
           .expect(404, done)
       })
@@ -471,7 +481,7 @@ describe('Test parameters validator', function () {
           .expect(400, done)
       })
 
-      it('Should fail without a mongodb id', function (done) {
+      it('Should fail without a correct uuid', function (done) {
         request(server.url)
           .delete(path + 'hello')
           .set('Authorization', 'Bearer ' + server.accessToken)
@@ -480,7 +490,7 @@ describe('Test parameters validator', function () {
 
       it('Should fail with a video which does not exist', function (done) {
         request(server.url)
-          .delete(path + '123456789012345678901234')
+          .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
           .set('Authorization', 'Bearer ' + server.accessToken)
           .expect(404, done)
       })
@@ -496,7 +506,7 @@ describe('Test parameters validator', function () {
   describe('Of the users API', function () {
     const path = '/api/v1/users/'
     let userId = null
-    let userAccessToken = null
+    let rootId = null
 
     describe('When listing users', function () {
       it('Should fail with a bad start pagination', function (done) {
@@ -626,6 +636,7 @@ describe('Test parameters validator', function () {
           if (err) throw err
 
           userId = res.body.data[1].id
+          rootId = res.body.data[2].id
           done()
         })
       })
@@ -691,18 +702,18 @@ describe('Test parameters validator', function () {
           .expect(400, done)
       })
 
-      it('Should return 404 with a non existing id', function (done) {
+      it('Should fail with the root user', function (done) {
         request(server.url)
-          .delete(path + '579f982228c99c221d8092b8')
+          .delete(path + rootId)
           .set('Authorization', 'Bearer ' + server.accessToken)
-          .expect(404, done)
+          .expect(400, done)
       })
 
-      it('Should success with the correct parameters', function (done) {
+      it('Should return 404 with a non existing id', function (done) {
         request(server.url)
-          .delete(path + userId)
+          .delete(path + '45')
           .set('Authorization', 'Bearer ' + server.accessToken)
-          .expect(204, done)
+          .expect(404, done)
       })
     })
   })
@@ -721,6 +732,25 @@ describe('Test parameters validator', function () {
     })
   })
 
+  describe('Of the requests API', function () {
+    const path = '/api/v1/requests/stats'
+
+    it('Should fail with an non authenticated user', function (done) {
+      request(server.url)
+        .get(path)
+        .set('Accept', 'application/json')
+        .expect(401, done)
+    })
+
+    it('Should fail with a non admin user', function (done) {
+      request(server.url)
+        .get(path)
+        .set('Authorization', 'Bearer ' + userAccessToken)
+        .set('Accept', 'application/json')
+        .expect(403, done)
+    })
+  })
+
   after(function (done) {
     process.kill(-server.app.pid)