2016-04-14 22:06:11 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const async = require('async')
|
|
|
|
const chai = require('chai')
|
|
|
|
const expect = chai.expect
|
|
|
|
const pathUtils = require('path')
|
|
|
|
|
|
|
|
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
|
|
|
|
webtorrent.silent = true
|
|
|
|
|
|
|
|
const utils = require('./utils')
|
|
|
|
|
|
|
|
describe('Test users', function () {
|
|
|
|
let server = null
|
2016-05-11 21:19:34 +02:00
|
|
|
let accessToken = null
|
|
|
|
let videoId
|
2016-04-14 22:06:11 +02:00
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
function (next) {
|
|
|
|
utils.flushTests(next)
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
utils.runServer(1, function (server1) {
|
|
|
|
server = server1
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
], done)
|
|
|
|
})
|
|
|
|
|
2016-04-27 22:17:55 +02:00
|
|
|
it('Should create a new client')
|
|
|
|
|
|
|
|
it('Should return the first client')
|
|
|
|
|
|
|
|
it('Should remove the last client')
|
|
|
|
|
2016-04-14 22:06:11 +02:00
|
|
|
it('Should not login with an invalid client id', function (done) {
|
|
|
|
const client = { id: 'client', password: server.client.secret }
|
|
|
|
utils.login(server.url, client, server.user, 400, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_client')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with an invalid client password', function (done) {
|
|
|
|
const client = { id: server.client.id, password: 'coucou' }
|
|
|
|
utils.login(server.url, client, server.user, 400, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_client')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with an invalid username', function (done) {
|
|
|
|
const user = { username: 'captain crochet', password: server.user.password }
|
|
|
|
utils.login(server.url, server.client, user, 400, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_grant')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with an invalid password', function (done) {
|
|
|
|
const user = { username: server.user.username, password: 'mewthree' }
|
|
|
|
utils.login(server.url, server.client, user, 400, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_grant')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to upload a video', function (done) {
|
2016-05-11 21:19:34 +02:00
|
|
|
accessToken = 'mysupertoken'
|
|
|
|
utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done)
|
2016-04-14 22:06:11 +02:00
|
|
|
})
|
|
|
|
|
2016-05-13 16:31:14 +02:00
|
|
|
it('Should not be able to make friends', function (done) {
|
|
|
|
accessToken = 'mysupertoken'
|
|
|
|
utils.makeFriends(server.url, accessToken, 401, done)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to quit friends', function (done) {
|
|
|
|
accessToken = 'mysupertoken'
|
|
|
|
utils.quitFriends(server.url, accessToken, 401, done)
|
|
|
|
})
|
|
|
|
|
2016-04-14 22:06:11 +02:00
|
|
|
it('Should be able to login', function (done) {
|
|
|
|
utils.login(server.url, server.client, server.user, 200, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
2016-05-11 21:19:34 +02:00
|
|
|
accessToken = res.body.access_token
|
2016-04-14 22:06:11 +02:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload the video with the correct token', function (done) {
|
2016-05-11 21:19:34 +02:00
|
|
|
utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) {
|
2016-04-14 22:06:11 +02:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
utils.getVideosList(server.url, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
2016-05-03 21:03:51 +02:00
|
|
|
const video = res.body[0]
|
|
|
|
expect(video.author).to.equal('root')
|
|
|
|
|
2016-05-11 21:19:34 +02:00
|
|
|
videoId = video.id
|
2016-04-14 22:06:11 +02:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload the video again with the correct token', function (done) {
|
2016-05-11 21:19:34 +02:00
|
|
|
utils.uploadVideo(server.url, accessToken, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done)
|
2016-04-14 22:06:11 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to remove the video with an incorrect token', function (done) {
|
2016-05-11 21:19:34 +02:00
|
|
|
utils.removeVideo(server.url, 'bad_token', videoId, 401, done)
|
2016-04-14 22:06:11 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to remove the video with the token of another account')
|
|
|
|
|
|
|
|
it('Should be able to remove the video with the correct token', function (done) {
|
2016-05-11 21:19:34 +02:00
|
|
|
utils.removeVideo(server.url, accessToken, videoId, done)
|
2016-04-14 22:06:11 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should logout')
|
|
|
|
|
|
|
|
it('Should not be able to upload a video')
|
|
|
|
|
|
|
|
it('Should not be able to remove a video')
|
|
|
|
|
|
|
|
it('Should be able to login again')
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
process.kill(-server.app.pid)
|
|
|
|
|
|
|
|
// Keep the logs if the test failed
|
|
|
|
if (this.ok) {
|
|
|
|
utils.flushTests(done)
|
|
|
|
} else {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|