2016-04-14 15:06:11 -05:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const chai = require('chai')
|
|
|
|
const expect = chai.expect
|
|
|
|
const pathUtils = require('path')
|
2016-07-18 10:17:52 -05:00
|
|
|
const series = require('async/series')
|
2016-04-14 15:06:11 -05:00
|
|
|
|
|
|
|
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 14:19:34 -05:00
|
|
|
let accessToken = null
|
|
|
|
let videoId
|
2016-04-14 15:06:11 -05:00
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2016-07-18 10:17:52 -05:00
|
|
|
series([
|
2016-04-14 15:06:11 -05:00
|
|
|
function (next) {
|
|
|
|
utils.flushTests(next)
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
utils.runServer(1, function (server1) {
|
|
|
|
server = server1
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
], done)
|
|
|
|
})
|
|
|
|
|
2016-04-27 15:17:55 -05:00
|
|
|
it('Should create a new client')
|
|
|
|
|
|
|
|
it('Should return the first client')
|
|
|
|
|
|
|
|
it('Should remove the last client')
|
|
|
|
|
2016-04-14 15:06:11 -05: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 14:19:34 -05:00
|
|
|
accessToken = 'mysupertoken'
|
2016-06-06 07:15:03 -05:00
|
|
|
|
|
|
|
const name = 'my super name'
|
|
|
|
const description = 'my super description'
|
|
|
|
const tags = [ 'tag1', 'tag2' ]
|
|
|
|
const video = 'video_short.webm'
|
|
|
|
utils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
|
2016-04-14 15:06:11 -05:00
|
|
|
})
|
|
|
|
|
2016-05-13 09:31:14 -05: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 15:06:11 -05: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 14:19:34 -05:00
|
|
|
accessToken = res.body.access_token
|
2016-04-14 15:06:11 -05:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload the video with the correct token', function (done) {
|
2016-06-06 07:15:03 -05:00
|
|
|
const name = 'my super name'
|
|
|
|
const description = 'my super description'
|
|
|
|
const tags = [ 'tag1', 'tag2' ]
|
|
|
|
const video = 'video_short.webm'
|
|
|
|
utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
|
2016-04-14 15:06:11 -05:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
utils.getVideosList(server.url, function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
2016-05-21 12:30:22 -05:00
|
|
|
const video = res.body.data[0]
|
2016-05-03 14:03:51 -05:00
|
|
|
expect(video.author).to.equal('root')
|
|
|
|
|
2016-05-11 14:19:34 -05:00
|
|
|
videoId = video.id
|
2016-04-14 15:06:11 -05:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload the video again with the correct token', function (done) {
|
2016-06-06 07:15:03 -05:00
|
|
|
const name = 'my super name 2'
|
|
|
|
const description = 'my super description 2'
|
|
|
|
const tags = [ 'tag1' ]
|
|
|
|
const video = 'video_short.webm'
|
|
|
|
utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
|
2016-04-14 15:06:11 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to remove the video with an incorrect token', function (done) {
|
2016-05-11 14:19:34 -05:00
|
|
|
utils.removeVideo(server.url, 'bad_token', videoId, 401, done)
|
2016-04-14 15:06:11 -05: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 14:19:34 -05:00
|
|
|
utils.removeVideo(server.url, accessToken, videoId, done)
|
2016-04-14 15:06:11 -05:00
|
|
|
})
|
|
|
|
|
2016-07-20 09:23:58 -05:00
|
|
|
it('Should logout (revoke token)')
|
2016-04-14 15:06:11 -05:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2016-07-20 09:23:58 -05:00
|
|
|
it('Should have an expired access token')
|
|
|
|
|
|
|
|
it('Should refresh the token')
|
|
|
|
|
|
|
|
it('Should be able to upload a video again')
|
|
|
|
|
2016-04-14 15:06:11 -05:00
|
|
|
after(function (done) {
|
|
|
|
process.kill(-server.app.pid)
|
|
|
|
|
|
|
|
// Keep the logs if the test failed
|
|
|
|
if (this.ok) {
|
|
|
|
utils.flushTests(done)
|
|
|
|
} else {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|