]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const pathUtils
= require('path')
8 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
9 webtorrent
.silent
= true
11 const utils
= require('./utils')
13 describe('Test users', function () {
15 let accessToken
= null
18 before(function (done
) {
23 utils
.flushTests(next
)
26 utils
.runServer(1, function (server1
) {
34 it('Should create a new client')
36 it('Should return the first client')
38 it('Should remove the last client')
40 it('Should not login with an invalid client id', function (done
) {
41 const client
= { id: 'client', password: server
.client
.secret
}
42 utils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
45 expect(res
.body
.error
).to
.equal('invalid_client')
50 it('Should not login with an invalid client password', function (done
) {
51 const client
= { id: server
.client
.id
, password: 'coucou' }
52 utils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
55 expect(res
.body
.error
).to
.equal('invalid_client')
60 it('Should not login with an invalid username', function (done
) {
61 const user
= { username: 'captain crochet', password: server
.user
.password
}
62 utils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
65 expect(res
.body
.error
).to
.equal('invalid_grant')
70 it('Should not login with an invalid password', function (done
) {
71 const user
= { username: server
.user
.username
, password: 'mewthree' }
72 utils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
75 expect(res
.body
.error
).to
.equal('invalid_grant')
80 it('Should not be able to upload a video', function (done
) {
81 accessToken
= 'mysupertoken'
82 utils
.uploadVideo(server
.url
, accessToken
, 'my super name', 'my super description', 'video_short.webm', 401, done
)
85 it('Should not be able to make friends', function (done
) {
86 accessToken
= 'mysupertoken'
87 utils
.makeFriends(server
.url
, accessToken
, 401, done
)
90 it('Should not be able to quit friends', function (done
) {
91 accessToken
= 'mysupertoken'
92 utils
.quitFriends(server
.url
, accessToken
, 401, done
)
95 it('Should be able to login', function (done
) {
96 utils
.login(server
.url
, server
.client
, server
.user
, 200, function (err
, res
) {
99 accessToken
= res
.body
.access_token
104 it('Should upload the video with the correct token', function (done
) {
105 utils
.uploadVideo(server
.url
, accessToken
, 'my super name', 'my super description', 'video_short.webm', 204, function (err
, res
) {
108 utils
.getVideosList(server
.url
, function (err
, res
) {
111 const video
= res
.body
[0]
112 expect(video
.author
).to
.equal('root')
120 it('Should upload the video again with the correct token', function (done
) {
121 utils
.uploadVideo(server
.url
, accessToken
, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done
)
124 it('Should not be able to remove the video with an incorrect token', function (done
) {
125 utils
.removeVideo(server
.url
, 'bad_token', videoId
, 401, done
)
128 it('Should not be able to remove the video with the token of another account')
130 it('Should be able to remove the video with the correct token', function (done
) {
131 utils
.removeVideo(server
.url
, accessToken
, videoId
, done
)
136 it('Should not be able to upload a video')
138 it('Should not be able to remove a video')
140 it('Should be able to login again')
142 after(function (done
) {
143 process
.kill(-server
.app
.pid
)
145 // Keep the logs if the test failed
147 utils
.flushTests(done
)