]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users.js
3 const chai
= require('chai')
4 const expect
= chai
.expect
5 const pathUtils
= require('path')
6 const series
= require('async/series')
8 const loginUtils
= require('../utils/login')
9 const podsUtils
= require('../utils/pods')
10 const serversUtils
= require('../utils/servers')
11 const usersUtils
= require('../utils/users')
12 const videosUtils
= require('../utils/videos')
13 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
14 webtorrent
.silent
= true
16 describe('Test users', function () {
18 let accessToken
= null
19 let accessTokenUser
= null
23 before(function (done
) {
28 serversUtils
.flushTests(next
)
31 serversUtils
.runServer(1, function (server1
) {
39 it('Should create a new client')
41 it('Should return the first client')
43 it('Should remove the last client')
45 it('Should not login with an invalid client id', function (done
) {
46 const client
= { id: 'client', password: server
.client
.secret
}
47 loginUtils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
50 expect(res
.body
.error
).to
.equal('invalid_client')
55 it('Should not login with an invalid client password', function (done
) {
56 const client
= { id: server
.client
.id
, password: 'coucou' }
57 loginUtils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
60 expect(res
.body
.error
).to
.equal('invalid_client')
65 it('Should not login with an invalid username', function (done
) {
66 const user
= { username: 'captain crochet', password: server
.user
.password
}
67 loginUtils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
70 expect(res
.body
.error
).to
.equal('invalid_grant')
75 it('Should not login with an invalid password', function (done
) {
76 const user
= { username: server
.user
.username
, password: 'mewthree' }
77 loginUtils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
80 expect(res
.body
.error
).to
.equal('invalid_grant')
85 it('Should not be able to upload a video', function (done
) {
86 accessToken
= 'mysupertoken'
88 const name
= 'my super name'
89 const description
= 'my super description'
90 const tags
= [ 'tag1', 'tag2' ]
91 const video
= 'video_short.webm'
92 videosUtils
.uploadVideo(server
.url
, accessToken
, name
, description
, tags
, video
, 401, done
)
95 it('Should not be able to make friends', function (done
) {
96 accessToken
= 'mysupertoken'
97 podsUtils
.makeFriends(server
.url
, accessToken
, 401, done
)
100 it('Should not be able to quit friends', function (done
) {
101 accessToken
= 'mysupertoken'
102 podsUtils
.quitFriends(server
.url
, accessToken
, 401, done
)
105 it('Should be able to login', function (done
) {
106 loginUtils
.login(server
.url
, server
.client
, server
.user
, 200, function (err
, res
) {
109 accessToken
= res
.body
.access_token
114 it('Should upload the video with the correct token', function (done
) {
115 const name
= 'my super name'
116 const description
= 'my super description'
117 const tags
= [ 'tag1', 'tag2' ]
118 const video
= 'video_short.webm'
119 videosUtils
.uploadVideo(server
.url
, accessToken
, name
, description
, tags
, video
, 204, function (err
, res
) {
122 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
125 const video
= res
.body
.data
[0]
126 expect(video
.author
).to
.equal('root')
134 it('Should upload the video again with the correct token', function (done
) {
135 const name
= 'my super name 2'
136 const description
= 'my super description 2'
137 const tags
= [ 'tag1' ]
138 const video
= 'video_short.webm'
139 videosUtils
.uploadVideo(server
.url
, accessToken
, name
, description
, tags
, video
, 204, done
)
142 it('Should not be able to remove the video with an incorrect token', function (done
) {
143 videosUtils
.removeVideo(server
.url
, 'bad_token', videoId
, 401, done
)
146 it('Should not be able to remove the video with the token of another account')
148 it('Should be able to remove the video with the correct token', function (done
) {
149 videosUtils
.removeVideo(server
.url
, accessToken
, videoId
, done
)
152 it('Should logout (revoke token)')
154 it('Should not be able to upload a video')
156 it('Should not be able to remove a video')
158 it('Should be able to login again')
160 it('Should have an expired access token')
162 it('Should refresh the token')
164 it('Should be able to upload a video again')
166 it('Should be able to create a new user', function (done
) {
167 usersUtils
.createUser(server
.url
, accessToken
, 'user_1', 'super password', done
)
170 it('Should be able to login with this user', function (done
) {
173 password: 'super password'
176 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
179 accessTokenUser
= token
185 it('Should be able to get the user informations', function (done
) {
186 usersUtils
.getUserInformation(server
.url
, accessTokenUser
, function (err
, res
) {
189 const user
= res
.body
191 expect(user
.username
).to
.equal('user_1')
192 expect(user
.id
).to
.exist
198 it('Should be able to upload a video with this user', function (done
) {
201 const name
= 'my super name'
202 const description
= 'my super description'
203 const tags
= [ 'tag1', 'tag2', 'tag3' ]
204 const file
= 'video_short.webm'
205 videosUtils
.uploadVideo(server
.url
, accessTokenUser
, name
, description
, tags
, file
, done
)
208 it('Should list all the users', function (done
) {
209 usersUtils
.getUsersList(server
.url
, function (err
, res
) {
212 const users
= res
.body
.data
214 expect(users
).to
.be
.an('array')
215 expect(users
.length
).to
.equal(2)
217 const rootUser
= users
[0]
218 expect(rootUser
.username
).to
.equal('root')
220 const user
= users
[1]
221 expect(user
.username
).to
.equal('user_1')
228 it('Should update the user password', function (done
) {
229 usersUtils
.updateUser(server
.url
, userId
, accessTokenUser
, 'new password', function (err
, res
) {
232 server
.user
.password
= 'new password'
233 loginUtils
.login(server
.url
, server
.client
, server
.user
, 200, done
)
237 it('Should be able to remove this user', function (done
) {
238 usersUtils
.removeUser(server
.url
, accessToken
, 'user_1', done
)
241 it('Should not be able to login with this user', function (done
) {
242 // server.user is already set to user 1
243 loginUtils
.login(server
.url
, server
.client
, server
.user
, 400, done
)
246 it('Should not have videos of this user', function (done
) {
247 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
250 expect(res
.body
.total
).to
.equal(1)
251 const video
= res
.body
.data
[0]
252 expect(video
.author
).to
.equal('root')
258 after(function (done
) {
259 process
.kill(-server
.app
.pid
)
261 // Keep the logs if the test failed
263 serversUtils
.flushTests(done
)