]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users.js
506b1929959301e305e6becd8f2cf761a537b64f
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 access_token
= null
18 before(function (done
) {
23 utils
.flushTests(next
)
26 utils
.runServer(1, function (server1
) {
34 it('Should not login with an invalid client id', function (done
) {
35 const client
= { id: 'client', password: server
.client
.secret
}
36 utils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
39 expect(res
.body
.error
).to
.equal('invalid_client')
44 it('Should not login with an invalid client password', function (done
) {
45 const client
= { id: server
.client
.id
, password: 'coucou' }
46 utils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
49 expect(res
.body
.error
).to
.equal('invalid_client')
54 it('Should not login with an invalid username', function (done
) {
55 const user
= { username: 'captain crochet', password: server
.user
.password
}
56 utils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
59 expect(res
.body
.error
).to
.equal('invalid_grant')
64 it('Should not login with an invalid password', function (done
) {
65 const user
= { username: server
.user
.username
, password: 'mewthree' }
66 utils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
69 expect(res
.body
.error
).to
.equal('invalid_grant')
74 it('Should not be able to upload a video', function (done
) {
75 access_token
= 'mysupertoken'
76 utils
.uploadVideo(server
.url
, access_token
, 'my super name', 'my super description', 'video_short.webm', 401, done
)
79 it('Should be able to login', function (done
) {
80 utils
.login(server
.url
, server
.client
, server
.user
, 200, function (err
, res
) {
83 access_token
= res
.body
.access_token
88 it('Should upload the video with the correct token', function (done
) {
89 utils
.uploadVideo(server
.url
, access_token
, 'my super name', 'my super description', 'video_short.webm', 204, function (err
, res
) {
92 utils
.getVideosList(server
.url
, function (err
, res
) {
95 video_id
= res
.body
[0].id
101 it('Should upload the video again with the correct token', function (done
) {
102 utils
.uploadVideo(server
.url
, access_token
, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done
)
105 it('Should not be able to remove the video with an incorrect token', function (done
) {
106 utils
.removeVideo(server
.url
, 'bad_token', video_id
, 401, done
)
109 it('Should not be able to remove the video with the token of another account')
111 it('Should be able to remove the video with the correct token', function (done
) {
112 utils
.removeVideo(server
.url
, access_token
, video_id
, done
)
117 it('Should not be able to upload a video')
119 it('Should not be able to remove a video')
121 it('Should be able to login again')
123 after(function (done
) {
124 process
.kill(-server
.app
.pid
)
126 // Keep the logs if the test failed
128 utils
.flushTests(done
)