]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/users.ts
Make some fields optional when uploading a video
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / users.ts
index ef78c8262408ac11f07412bf01b68df3d1769cf5..1e3533bf3cc5a3b83fb17507969e63fda3b711af 100644 (file)
@@ -19,6 +19,7 @@ import {
   makePostBodyRequest,
   getUserAccessToken
 } from '../../utils'
+import { UserRole } from '../../../../shared'
 
 describe('Test users API validators', function () {
   const path = '/api/v1/users/'
@@ -66,6 +67,7 @@ describe('Test users API validators', function () {
               .get(path)
               .query({ start: 'hello' })
               .set('Accept', 'application/json')
+              .set('Authorization', 'Bearer ' + server.accessToken)
               .expect(400)
     })
 
@@ -74,6 +76,7 @@ describe('Test users API validators', function () {
               .get(path)
               .query({ count: 'hello' })
               .set('Accept', 'application/json')
+              .set('Authorization', 'Bearer ' + server.accessToken)
               .expect(400)
     })
 
@@ -82,8 +85,24 @@ describe('Test users API validators', function () {
               .get(path)
               .query({ sort: 'hello' })
               .set('Accept', 'application/json')
+              .set('Authorization', 'Bearer ' + server.accessToken)
               .expect(400)
     })
+
+    it('Should fail with a non authenticated user', async function () {
+      await request(server.url)
+        .get(path)
+        .set('Accept', 'application/json')
+        .expect(401)
+    })
+
+    it('Should fail with a non admin user', async function () {
+      await request(server.url)
+        .get(path)
+        .set('Accept', 'application/json')
+        .set('Authorization', 'Bearer ' + userAccessToken)
+        .expect(403)
+    })
   })
 
   describe('When adding a new user', function () {
@@ -92,6 +111,7 @@ describe('Test users API validators', function () {
         username: 'ji',
         email: 'test@example.com',
         password: 'my_super_password',
+        role: UserRole.USER,
         videoQuota: 42000000
       }
 
@@ -103,7 +123,20 @@ describe('Test users API validators', function () {
         username: 'my_super_username_which_is_very_long',
         email: 'test@example.com',
         password: 'my_super_password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
+      }
+
+      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+    })
+
+    it('Should fail with a not lowercase username', async function () {
+      const fields = {
+        username: 'Toto',
+        email: 'test@example.com',
+        password: 'my_super_password',
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -114,7 +147,8 @@ describe('Test users API validators', function () {
         username: 'my username',
         email: 'test@example.com',
         password: 'my_super_password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -124,7 +158,8 @@ describe('Test users API validators', function () {
       const fields = {
         username: 'ji',
         password: 'my_super_password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -135,7 +170,8 @@ describe('Test users API validators', function () {
         username: 'my_super_username_which_is_very_long',
         email: 'test_example.com',
         password: 'my_super_password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -146,7 +182,8 @@ describe('Test users API validators', function () {
         username: 'my_username',
         email: 'test@example.com',
         password: 'bla',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -159,7 +196,8 @@ describe('Test users API validators', function () {
         password: 'my super long password which is very very very very very very very very very very very very very very' +
                   'very very very very very very very very very very very very very very very veryv very very very very' +
                   'very very very very very very very very very very very very very very very very very very very very long',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -170,7 +208,8 @@ describe('Test users API validators', function () {
         username: 'my_username',
         email: 'test@example.com',
         password: 'my super password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: 'super token', fields, statusCodeExpected: 401 })
@@ -181,7 +220,8 @@ describe('Test users API validators', function () {
         username: 'user1',
         email: 'test@example.com',
         password: 'my super password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
@@ -192,7 +232,8 @@ describe('Test users API validators', function () {
         username: 'my_username',
         email: 'user1@example.com',
         password: 'my super password',
-        videoQuota: 42000000
+        videoQuota: 42000000,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
@@ -202,7 +243,8 @@ describe('Test users API validators', function () {
       const fields = {
         username: 'my_username',
         email: 'user1@example.com',
-        password: 'my super password'
+        password: 'my super password',
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -213,7 +255,31 @@ describe('Test users API validators', function () {
         username: 'my_username',
         email: 'user1@example.com',
         password: 'my super password',
-        videoQuota: -5
+        videoQuota: -5,
+        role: UserRole.USER
+      }
+
+      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+    })
+
+    it('Should fail without a user role', async function () {
+      const fields = {
+        username: 'my_username',
+        email: 'user1@example.com',
+        password: 'my super password',
+        videoQuota: 0
+      }
+
+      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+    })
+
+    it('Should fail with an invalid user role', async function () {
+      const fields = {
+        username: 'my_username',
+        email: 'user1@example.com',
+        password: 'my super password',
+        videoQuota: 0,
+        role: 88989
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
@@ -224,7 +290,8 @@ describe('Test users API validators', function () {
         username: 'user2',
         email: 'test@example.com',
         password: 'my super password',
-        videoQuota: -1
+        videoQuota: -1,
+        role: UserRole.USER
       }
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
@@ -305,7 +372,7 @@ describe('Test users API validators', function () {
   describe('When updating a user', function () {
 
     before(async function () {
-      const res = await getUsersList(server.url)
+      const res = await getUsersList(server.url, server.accessToken)
 
       userId = res.body.data[1].id
       rootId = res.body.data[2].id
@@ -327,6 +394,14 @@ describe('Test users API validators', function () {
       await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
     })
 
+    it('Should fail with an invalid user role attribute', async function () {
+      const fields = {
+        role: 54878
+      }
+
+      await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
+    })
+
     it('Should fail with an non authenticated user', async function () {
       const fields = {
         videoQuota: 42
@@ -338,7 +413,8 @@ describe('Test users API validators', function () {
     it('Should succeed with the correct params', async function () {
       const fields = {
         email: 'email@example.com',
-        videoQuota: 42
+        videoQuota: 42,
+        role: UserRole.MODERATOR
       }
 
       await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })