From feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 11 Dec 2016 21:50:51 +0100 Subject: First version with PostgreSQL --- server/tests/api/check-params.js | 6 +++--- server/tests/api/friends-basic.js | 4 ++-- server/tests/api/multiple-pods.js | 8 ++++---- server/tests/api/requests.js | 29 ++--------------------------- server/tests/api/single-pod.js | 16 ++++++++-------- server/tests/api/users.js | 8 ++++---- server/tests/utils/servers.js | 4 ++-- server/tests/utils/videos.js | 2 +- 8 files changed, 26 insertions(+), 51 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js index 444c2fc55..d9e51770c 100644 --- a/server/tests/api/check-params.js +++ b/server/tests/api/check-params.js @@ -465,7 +465,7 @@ describe('Test parameters validator', function () { it('Should return 404 with an incorrect video', function (done) { request(server.url) - .get(path + '123456789012345678901234') + .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') .set('Accept', 'application/json') .expect(404, done) }) @@ -490,7 +490,7 @@ describe('Test parameters validator', function () { it('Should fail with a video which does not exist', function (done) { request(server.url) - .delete(path + '123456789012345678901234') + .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') .set('Authorization', 'Bearer ' + server.accessToken) .expect(404, done) }) @@ -711,7 +711,7 @@ describe('Test parameters validator', function () { it('Should return 404 with a non existing id', function (done) { request(server.url) - .delete(path + '579f982228c99c221d8092b8') + .delete(path + '45') .set('Authorization', 'Bearer ' + server.accessToken) .expect(404, done) }) diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js index a871f9838..3a904dbd7 100644 --- a/server/tests/api/friends-basic.js +++ b/server/tests/api/friends-basic.js @@ -97,7 +97,7 @@ describe('Test basic friends', function () { const pod = result[0] expect(pod.host).to.equal(servers[2].host) expect(pod.score).to.equal(20) - expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true next() }) @@ -114,7 +114,7 @@ describe('Test basic friends', function () { const pod = result[0] expect(pod.host).to.equal(servers[1].host) expect(pod.score).to.equal(20) - expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true next() }) diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index be278d7c5..f0fe59c5f 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -104,7 +104,7 @@ describe('Test multiple pods', function () { expect(video.magnetUri).to.exist expect(video.duration).to.equal(10) expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true expect(video.author).to.equal('root') if (server.url !== 'http://localhost:9001') { @@ -166,7 +166,7 @@ describe('Test multiple pods', function () { expect(video.magnetUri).to.exist expect(video.duration).to.equal(5) expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true expect(video.author).to.equal('root') if (server.url !== 'http://localhost:9002') { @@ -246,7 +246,7 @@ describe('Test multiple pods', function () { expect(video1.duration).to.equal(5) expect(video1.tags).to.deep.equal([ 'tag1p3' ]) expect(video1.author).to.equal('root') - expect(miscsUtils.dateIsValid(video1.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true expect(video2.name).to.equal('my super name for pod 3-2') expect(video2.description).to.equal('my super description for pod 3-2') @@ -255,7 +255,7 @@ describe('Test multiple pods', function () { expect(video2.duration).to.equal(5) expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) expect(video2.author).to.equal('root') - expect(miscsUtils.dateIsValid(video2.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true if (server.url !== 'http://localhost:9003') { expect(video1.isLocal).to.be.false diff --git a/server/tests/api/requests.js b/server/tests/api/requests.js index af36f6e34..7e790b54b 100644 --- a/server/tests/api/requests.js +++ b/server/tests/api/requests.js @@ -69,7 +69,7 @@ describe('Test requests stats', function () { }) }) - it('Should have the correct request', function (done) { + it('Should have the correct total request', function (done) { this.timeout(15000) const server = servers[0] @@ -83,11 +83,7 @@ describe('Test requests stats', function () { if (err) throw err const body = res.body - expect(body.requests).to.have.lengthOf(1) - - const request = body.requests[0] - expect(request.to).to.have.lengthOf(1) - expect(request.request.type).to.equal('add') + expect(body.totalRequests).to.equal(1) // Wait one cycle setTimeout(done, 10000) @@ -95,27 +91,6 @@ describe('Test requests stats', function () { }) }) - it('Should have the correct requests', function (done) { - const server = servers[0] - - uploadVideo(server, function (err) { - if (err) throw err - - getRequestsStats(server, function (err, res) { - if (err) throw err - - const body = res.body - expect(body.requests).to.have.lengthOf(2) - - const request = body.requests[1] - expect(request.to).to.have.lengthOf(1) - expect(request.request.type).to.equal('add') - - done() - }) - }) - }) - after(function (done) { process.kill(-servers[0].app.pid) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 65d1a7a65..aedecacf3 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -82,7 +82,7 @@ describe('Test a single pod', function () { expect(video.author).to.equal('root') expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -116,7 +116,7 @@ describe('Test a single pod', function () { expect(video.author).to.equal('root') expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -142,7 +142,7 @@ describe('Test a single pod', function () { expect(video.author).to.equal('root') expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -154,7 +154,7 @@ describe('Test a single pod', function () { }) it('Should search the video by podHost', function (done) { - videosUtils.searchVideo(server.url, '9001', 'podHost', function (err, res) { + videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { if (err) throw err expect(res.body.total).to.equal(1) @@ -168,7 +168,7 @@ describe('Test a single pod', function () { expect(video.author).to.equal('root') expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -194,7 +194,7 @@ describe('Test a single pod', function () { expect(video.author).to.equal('root') expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -425,7 +425,7 @@ describe('Test a single pod', function () { }) it('Should search all the 9001 port videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, '9001', 'podHost', 0, 15, function (err, res) { + videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { if (err) throw err const videos = res.body.data @@ -437,7 +437,7 @@ describe('Test a single pod', function () { }) it('Should search all the localhost videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podHost', 0, 15, function (err, res) { + videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { if (err) throw err const videos = res.body.data diff --git a/server/tests/api/users.js b/server/tests/api/users.js index 94267f104..e6d937eb0 100644 --- a/server/tests/api/users.js +++ b/server/tests/api/users.js @@ -261,8 +261,8 @@ describe('Test users', function () { }) }) - it('Should list only the second user by createdDate desc', function (done) { - usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdDate', function (err, res) { + it('Should list only the second user by createdAt desc', function (done) { + usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt', function (err, res) { if (err) throw err const result = res.body @@ -279,8 +279,8 @@ describe('Test users', function () { }) }) - it('Should list all the users by createdDate asc', function (done) { - usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdDate', function (err, res) { + it('Should list all the users by createdAt asc', function (done) { + usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt', function (err, res) { if (err) throw err const result = res.body diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js index 01c9a2f39..4e55f8f5c 100644 --- a/server/tests/utils/servers.js +++ b/server/tests/utils/servers.js @@ -60,12 +60,12 @@ function runServer (number, callback) { // These actions are async so we need to be sure that they have both been done const serverRunString = { - 'Connected to mongodb': false, + 'Database is ready': false, 'Server listening on port': false } const regexps = { - client_id: 'Client id: ([a-f0-9]+)', + client_id: 'Client id: (.+)', client_secret: 'Client secret: (.+)', user_username: 'Username: (.+)', user_password: 'User password: (.+)' diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js index 536093db1..5c120597f 100644 --- a/server/tests/utils/videos.js +++ b/server/tests/utils/videos.js @@ -25,7 +25,7 @@ function getAllVideosListBy (url, end) { request(url) .get(path) - .query({ sort: 'createdDate' }) + .query({ sort: 'createdAt' }) .query({ start: 0 }) .query({ count: 10000 }) .set('Accept', 'application/json') -- cgit v1.2.3 From 7920c273a204e2469416a30b752b12ccd3160102 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 24 Dec 2016 16:59:17 +0100 Subject: Move tags in another table --- server/tests/api/check-params.js | 4 +- server/tests/api/requests.js | 15 +++---- server/tests/api/single-pod.js | 90 ++++++++++++++++++++-------------------- 3 files changed, 56 insertions(+), 53 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js index d9e51770c..9aecc3720 100644 --- a/server/tests/api/check-params.js +++ b/server/tests/api/check-params.js @@ -456,7 +456,7 @@ describe('Test parameters validator', function () { }) }) - it('Should fail without a mongodb id', function (done) { + it('Should fail without a correct uuid', function (done) { request(server.url) .get(path + 'coucou') .set('Accept', 'application/json') @@ -481,7 +481,7 @@ describe('Test parameters validator', function () { .expect(400, done) }) - it('Should fail without a mongodb id', function (done) { + it('Should fail without a correct uuid', function (done) { request(server.url) .delete(path + 'hello') .set('Authorization', 'Bearer ' + server.accessToken) diff --git a/server/tests/api/requests.js b/server/tests/api/requests.js index 7e790b54b..933ed29b4 100644 --- a/server/tests/api/requests.js +++ b/server/tests/api/requests.js @@ -79,15 +79,16 @@ describe('Test requests stats', function () { uploadVideo(server, function (err) { if (err) throw err - getRequestsStats(server, function (err, res) { - if (err) throw err + setTimeout(function () { + getRequestsStats(server, function (err, res) { + if (err) throw err - const body = res.body - expect(body.totalRequests).to.equal(1) + const body = res.body + expect(body.totalRequests).to.equal(1) - // Wait one cycle - setTimeout(done, 10000) - }) + done() + }) + }, 1000) }) }) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index aedecacf3..66b762f82 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -153,31 +153,32 @@ describe('Test a single pod', function () { }) }) - it('Should search the video by podHost', function (done) { - videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) - - const video = res.body.data[0] - expect(video.name).to.equal('my super name') - expect(video.description).to.equal('my super description') - expect(video.podHost).to.equal('localhost:9001') - expect(video.author).to.equal('root') - expect(video.isLocal).to.be.true - expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true - - videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - done() - }) - }) - }) + // Not implemented yet + // it('Should search the video by podHost', function (done) { + // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { + // if (err) throw err + + // expect(res.body.total).to.equal(1) + // expect(res.body.data).to.be.an('array') + // expect(res.body.data.length).to.equal(1) + + // const video = res.body.data[0] + // expect(video.name).to.equal('my super name') + // expect(video.description).to.equal('my super description') + // expect(video.podHost).to.equal('localhost:9001') + // expect(video.author).to.equal('root') + // expect(video.isLocal).to.be.true + // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) + // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + + // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { + // if (err) throw err + // expect(test).to.equal(true) + + // done() + // }) + // }) + // }) it('Should search the video by tag', function (done) { videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { @@ -230,7 +231,7 @@ describe('Test a single pod', function () { }) it('Should not find a search by tag', function (done) { - videosUtils.searchVideo(server.url, 'tag', 'tags', function (err, res) { + videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) { if (err) throw err expect(res.body.total).to.equal(0) @@ -424,29 +425,30 @@ describe('Test a single pod', function () { }) }) - it('Should search all the 9001 port videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { - if (err) throw err + // Not implemented yet + // it('Should search all the 9001 port videos', function (done) { + // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { + // if (err) throw err - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) + // const videos = res.body.data + // expect(res.body.total).to.equal(6) + // expect(videos.length).to.equal(6) - done() - }) - }) + // done() + // }) + // }) - it('Should search all the localhost videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { - if (err) throw err + // it('Should search all the localhost videos', function (done) { + // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { + // if (err) throw err - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) + // const videos = res.body.data + // expect(res.body.total).to.equal(6) + // expect(videos.length).to.equal(6) - done() - }) - }) + // done() + // }) + // }) it('Should search the good magnetUri video', function (done) { const video = videosListBase[0] -- cgit v1.2.3 From b769007f733769d3afe2d29a3eb23e2e7693f301 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 25 Dec 2016 09:44:57 +0100 Subject: Update migrations code --- server/tests/utils/servers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests') diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js index 4e55f8f5c..e7c756499 100644 --- a/server/tests/utils/servers.js +++ b/server/tests/utils/servers.js @@ -103,7 +103,7 @@ function runServer (number, callback) { if (serverRunString[key] === false) dontContinue = true } - // If no, there is maybe one thing not already initialized (mongodb...) + // If no, there is maybe one thing not already initialized (client/user credentials generation...) if (dontContinue === true) return server.app.stdout.removeListener('data', onStdout) -- cgit v1.2.3 From 56ac84d0a32844c7b7df4c584dccb6e6c17e35de Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 25 Dec 2016 12:05:47 +0100 Subject: Fix real world script --- server/tests/real-world/real-world.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'server/tests') diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index dba1970c5..2ae3dc15b 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -30,9 +30,9 @@ let integrityInterval = parseInt(program.integrity) || 60000 const numberOfPods = 6 // Wait requests between pods -const requestsMaxPerInterval = constants.INTERVAL / actionInterval +const requestsMaxPerInterval = constants.REQUESTS_INTERVAL / actionInterval const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) -const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.INTERVAL) + 1000 +const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 integrityInterval += waitForBeforeIntegrityCheck @@ -160,9 +160,9 @@ function exitServers (servers, callback) { function upload (servers, numServer, callback) { if (!callback) callback = function () {} - const name = 'my super name for pod 1' - const description = 'my super description for pod 1' - const tags = [ 'tag1p1', 'tag2p1' ] + const name = Date.now() + ' name' + const description = Date.now() + ' description' + const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] const file = 'video_short1.webm' console.log('Upload video to server ' + numServer) @@ -205,6 +205,7 @@ function checkIntegrity (servers, callback) { for (const video of videos) { if (!isEqual(video, videos[0])) { console.error('Integrity not ok!') + process.exit(-1) } } -- cgit v1.2.3 From 7b1f49de22c40ae121ddb3c399b2540ba56fd414 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Dec 2016 19:07:05 +0100 Subject: Server: add ability to update a video --- server/tests/api/check-params.js | 101 +++++++++++++++++++++++++++++++++++++++ server/tests/api/single-pod.js | 76 +++++++++++++++++++++++++++++ server/tests/utils/videos.js | 28 ++++++++++- 3 files changed, 204 insertions(+), 1 deletion(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js index 9aecc3720..e8f2aa821 100644 --- a/server/tests/api/check-params.js +++ b/server/tests/api/check-params.js @@ -10,6 +10,7 @@ const loginUtils = require('../utils/login') const requestsUtils = require('../utils/requests') const serversUtils = require('../utils/servers') const usersUtils = require('../utils/users') +const videosUtils = require('../utils/videos') describe('Test parameters validator', function () { let server = null @@ -439,6 +440,106 @@ describe('Test parameters validator', function () { }) }) + describe('When updating a video', function () { + let videoId + + before(function (done) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + videoId = res.body.data[0].id + + return done() + }) + }) + + it('Should fail with nothing', function (done) { + const data = {} + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail without a valid uuid', function (done) { + const data = { + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) + }) + + it('Should fail with an unknown id', function (done) { + const data = { + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done) + }) + + it('Should fail with a long name', function (done) { + const data = { + name: 'My very very very very very very very very very very very very very very very very long name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with a long description', function (done) { + const data = { + name: 'my super name', + description: 'my super description which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very long', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with too many tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with not enough tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with a tag length too low', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 't' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with a tag length too big', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'mysupertagtoolong', 'tag1' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with malformed tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'my tag' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + }) + describe('When getting a video', function () { it('Should return the list of the videos with nothing', function (done) { request(server.url) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 66b762f82..57146900d 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -495,10 +495,86 @@ describe('Test a single pod', function () { expect(videos[2].name === 'video_short2.webm name') expect(videos[3].name === 'video_short3.webm name') + videoId = videos[3].id + done() }) }) + it('Should update a video', function (done) { + const name = 'my super video updated' + const description = 'my super description updated' + const tags = [ 'tagup1', 'tagup2' ] + + videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done) + }) + + it('Should have the video updated', function (done) { + videosUtils.getVideo(server.url, videoId, function (err, res) { + if (err) throw err + + const video = res.body + + expect(video.name).to.equal('my super video updated') + expect(video.description).to.equal('my super description updated') + expect(video.podHost).to.equal('localhost:9001') + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + + done() + }) + }) + + it('Should update only the tags of a video', function (done) { + const tags = [ 'tag1', 'tag2', 'supertag' ] + + videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) { + if (err) throw err + + videosUtils.getVideo(server.url, videoId, function (err, res) { + if (err) throw err + + const video = res.body + + expect(video.name).to.equal('my super video updated') + expect(video.description).to.equal('my super description updated') + expect(video.podHost).to.equal('localhost:9001') + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + + done() + }) + }) + }) + + it('Should update only the description of a video', function (done) { + const description = 'hello everybody' + + videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) { + if (err) throw err + + videosUtils.getVideo(server.url, videoId, function (err, res) { + if (err) throw err + + const video = res.body + + expect(video.name).to.equal('my super video updated') + expect(video.description).to.equal('hello everybody') + expect(video.podHost).to.equal('localhost:9001') + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) + expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + + done() + }) + }) + }) + after(function (done) { process.kill(-server.app.pid) diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js index 5c120597f..beafd3cf5 100644 --- a/server/tests/utils/videos.js +++ b/server/tests/utils/videos.js @@ -15,7 +15,8 @@ const videosUtils = { searchVideoWithPagination, searchVideoWithSort, testVideoImage, - uploadVideo + uploadVideo, + updateVideo } // ---------------------- Export functions -------------------- @@ -194,6 +195,31 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia .end(end) } +function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) { + if (!end) { + end = specialStatus + specialStatus = 204 + } + + const path = '/api/v1/videos/' + id + + const req = request(url) + .put(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + + if (name) req.field('name', name) + if (description) req.field('description', description) + + if (tags) { + for (let i = 0; i < tags.length; i++) { + req.field('tags[' + i + ']', tags[i]) + } + } + + req.expect(specialStatus).end(end) +} + // --------------------------------------------------------------------------- module.exports = videosUtils -- cgit v1.2.3 From 3d118fb501f576a298f6bb059167e4c7f4dd8dcc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2016 11:27:42 +0100 Subject: Server: propagate video update to other pods --- server/tests/api/multiple-pods.js | 55 ++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index f0fe59c5f..672187068 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -299,8 +299,8 @@ describe('Test multiple pods', function () { if (err) throw err const video = res.body.data[0] - toRemove.push(res.body.data[2].id) - toRemove.push(res.body.data[3].id) + toRemove.push(res.body.data[2]) + toRemove.push(res.body.data[3]) webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist @@ -368,16 +368,51 @@ describe('Test multiple pods', function () { }) }) }) + }) + + describe('Should manipulate these videos', function () { + it('Should update the video 3 by asking pod 3', function (done) { + this.timeout(15000) + + const name = 'my super video updated' + const description = 'my super description updated' + const tags = [ 'tagup1', 'tagup2' ] + + videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) { + if (err) throw err + + setTimeout(done, 11000) + }) + }) + + it('Should have the video 3 updated on each pod', function (done) { + each(servers, function (server, callback) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + const videoUpdated = videos.find(function (video) { + return video.name === 'my super video updated' + }) + + expect(!!videoUpdated).to.be.true + expect(videoUpdated.description).to.equal('my super description updated') + expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) + + callback() + }) + }, done) + }) - it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { + it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) { this.timeout(15000) series([ function (next) { - videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) + videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next) }, function (next) { - videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) + videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next) }], function (err) { if (err) throw err @@ -394,11 +429,11 @@ describe('Test multiple pods', function () { const videos = res.body.data expect(videos).to.be.an('array') expect(videos.length).to.equal(2) - expect(videos[0].id).not.to.equal(videos[1].id) - expect(videos[0].id).not.to.equal(toRemove[0]) - expect(videos[1].id).not.to.equal(toRemove[0]) - expect(videos[0].id).not.to.equal(toRemove[1]) - expect(videos[1].id).not.to.equal(toRemove[1]) + expect(videos[0].name).not.to.equal(videos[1].name) + expect(videos[0].name).not.to.equal(toRemove[0].name) + expect(videos[1].name).not.to.equal(toRemove[0].name) + expect(videos[0].name).not.to.equal(toRemove[1].name) + expect(videos[1].name).not.to.equal(toRemove[1].name) callback() }) -- cgit v1.2.3 From 79066fdf33f79d2d41394f10881e2c226ca26b49 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2016 11:45:00 +0100 Subject: Server: add updatedAt attribute to videos --- server/tests/api/multiple-pods.js | 5 +++++ server/tests/api/single-pod.js | 8 ++++++++ server/tests/utils/miscs.js | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 672187068..4442a7ff7 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -105,6 +105,7 @@ describe('Test multiple pods', function () { expect(video.duration).to.equal(10) expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true expect(video.author).to.equal('root') if (server.url !== 'http://localhost:9001') { @@ -167,6 +168,7 @@ describe('Test multiple pods', function () { expect(video.duration).to.equal(5) expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true expect(video.author).to.equal('root') if (server.url !== 'http://localhost:9002') { @@ -247,6 +249,7 @@ describe('Test multiple pods', function () { expect(video1.tags).to.deep.equal([ 'tag1p3' ]) expect(video1.author).to.equal('root') expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true expect(video2.name).to.equal('my super name for pod 3-2') expect(video2.description).to.equal('my super description for pod 3-2') @@ -256,6 +259,7 @@ describe('Test multiple pods', function () { expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) expect(video2.author).to.equal('root') expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true if (server.url !== 'http://localhost:9003') { expect(video1.isLocal).to.be.false @@ -398,6 +402,7 @@ describe('Test multiple pods', function () { expect(!!videoUpdated).to.be.true expect(videoUpdated.description).to.equal('my super description updated') expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) + expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true callback() }) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 57146900d..29512dfc6 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -83,6 +83,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -117,6 +118,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -143,6 +145,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -170,6 +173,7 @@ describe('Test a single pod', function () { // expect(video.isLocal).to.be.true // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { // if (err) throw err @@ -196,6 +200,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { if (err) throw err @@ -522,6 +527,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true done() }) @@ -545,6 +551,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true done() }) @@ -569,6 +576,7 @@ describe('Test a single pod', function () { expect(video.isLocal).to.be.true expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true + expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true done() }) diff --git a/server/tests/utils/miscs.js b/server/tests/utils/miscs.js index 4ceff65df..c4b661496 100644 --- a/server/tests/utils/miscs.js +++ b/server/tests/utils/miscs.js @@ -6,12 +6,14 @@ const miscsUtils = { // ---------------------- Export functions -------------------- -function dateIsValid (dateString) { +function dateIsValid (dateString, interval) { const dateToCheck = new Date(dateString) const now = new Date() // Check if the interval is more than 2 minutes - if (now - dateToCheck > 120000) return false + if (!interval) interval = 120000 + + if (now - dateToCheck > interval) return false return true } -- cgit v1.2.3 From efe923bcdaf15b47593ad8583df09a92c715ac6c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2016 12:23:53 +0100 Subject: Server: split check params tests --- server/tests/api/check-params.js | 865 ------------------------------ server/tests/api/check-params/index.js | 8 + server/tests/api/check-params/pods.js | 204 +++++++ server/tests/api/check-params/remotes.js | 60 +++ server/tests/api/check-params/requests.js | 87 +++ server/tests/api/check-params/users.js | 284 ++++++++++ server/tests/api/check-params/videos.js | 456 ++++++++++++++++ server/tests/utils/login.js | 11 +- server/tests/utils/servers.js | 2 +- 9 files changed, 1110 insertions(+), 867 deletions(-) delete mode 100644 server/tests/api/check-params.js create mode 100644 server/tests/api/check-params/index.js create mode 100644 server/tests/api/check-params/pods.js create mode 100644 server/tests/api/check-params/remotes.js create mode 100644 server/tests/api/check-params/requests.js create mode 100644 server/tests/api/check-params/users.js create mode 100644 server/tests/api/check-params/videos.js (limited to 'server/tests') diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js deleted file mode 100644 index e8f2aa821..000000000 --- a/server/tests/api/check-params.js +++ /dev/null @@ -1,865 +0,0 @@ -'use strict' - -const chai = require('chai') -const expect = chai.expect -const pathUtils = require('path') -const request = require('supertest') -const series = require('async/series') - -const loginUtils = require('../utils/login') -const requestsUtils = require('../utils/requests') -const serversUtils = require('../utils/servers') -const usersUtils = require('../utils/users') -const videosUtils = require('../utils/videos') - -describe('Test parameters validator', function () { - let server = null - let userAccessToken = null - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(20000) - - series([ - function (next) { - serversUtils.flushTests(next) - }, - function (next) { - serversUtils.runServer(1, function (server1) { - server = server1 - - next() - }) - }, - function (next) { - loginUtils.loginAndGetAccessToken(server, function (err, token) { - if (err) throw err - server.accessToken = token - - next() - }) - } - ], done) - }) - - describe('Of the pods API', function () { - const path = '/api/v1/pods/' - - describe('When making friends', function () { - let userAccessToken = null - - before(function (done) { - usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { - server.user = { - username: 'user1', - password: 'password' - } - - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) throw err - - userAccessToken = accessToken - - done() - }) - }) - }) - - describe('When making friends', function () { - const body = { - hosts: [ 'localhost:9002' ] - } - - it('Should fail without hosts', function (done) { - request(server.url) - .post(path + '/makefriends') - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail if hosts is not an array', function (done) { - request(server.url) - .post(path + '/makefriends') - .send({ hosts: 'localhost:9002' }) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail if the array is not composed by hosts', function (done) { - request(server.url) - .post(path + '/makefriends') - .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail if the array is composed with http schemes', function (done) { - request(server.url) - .post(path + '/makefriends') - .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail if hosts are not unique', function (done) { - request(server.url) - .post(path + '/makefriends') - .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a invalid token', function (done) { - request(server.url) - .post(path + '/makefriends') - .send(body) - .set('Authorization', 'Bearer faketoken') - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should fail if the user is not an administrator', function (done) { - request(server.url) - .post(path + '/makefriends') - .send(body) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403, done) - }) - }) - - describe('When quitting friends', function () { - it('Should fail with a invalid token', function (done) { - request(server.url) - .get(path + '/quitfriends') - .query({ start: 'hello' }) - .set('Authorization', 'Bearer faketoken') - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should fail if the user is not an administrator', function (done) { - request(server.url) - .get(path + '/quitfriends') - .query({ start: 'hello' }) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403, done) - }) - }) - }) - - describe('When adding a pod', function () { - it('Should fail with nothing', function (done) { - const data = {} - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail without public key', function (done) { - const data = { - host: 'coucou.com' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail without an host', function (done) { - const data = { - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail with an incorrect host', function (done) { - const data = { - host: 'http://coucou.com', - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { - data.host = 'http://coucou' - requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { - data.host = 'coucou' - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - }) - }) - - it('Should succeed with the correct parameters', function (done) { - const data = { - host: 'coucou.com', - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) - }) - }) - }) - - describe('Of the videos API', function () { - const path = '/api/v1/videos/' - - describe('When listing a video', function () { - it('Should fail with a bad start pagination', function (done) { - request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad count pagination', function (done) { - request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with an incorrect sort', function (done) { - request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - }) - - describe('When searching a video', function () { - it('Should fail with nothing', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search')) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad start pagination', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search', 'test')) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad count pagination', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search', 'test')) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with an incorrect sort', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search', 'test')) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - }) - - describe('When adding a video', function () { - it('Should fail with nothing', function (done) { - const data = {} - const attach = {} - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without name', function (done) { - const data = { - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a long name', function (done) { - const data = { - name: 'My very very very very very very very very very very very very very very very very long name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without description', function (done) { - const data = { - name: 'my super name', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a long description', function (done) { - const data = { - name: 'my super name', - description: 'my super description which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very long', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description' - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with too many tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with not enough tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a tag length too low', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 't' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a tag length too big', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'mysupertagtoolong', 'tag1' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with malformed tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'my tag' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without an input file', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = {} - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without an incorrect input file', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a too big duration', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should succeed with the correct parameters', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { - attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { - attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) - }, false) - }, false) - }) - }) - - describe('When updating a video', function () { - let videoId - - before(function (done) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - videoId = res.body.data[0].id - - return done() - }) - }) - - it('Should fail with nothing', function (done) { - const data = {} - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail without a valid uuid', function (done) { - const data = { - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) - }) - - it('Should fail with an unknown id', function (done) { - const data = { - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done) - }) - - it('Should fail with a long name', function (done) { - const data = { - name: 'My very very very very very very very very very very very very very very very very long name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail with a long description', function (done) { - const data = { - name: 'my super name', - description: 'my super description which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very long', - tags: [ 'tag1', 'tag2' ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail with too many tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail with not enough tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail with a tag length too low', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 't' ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail with a tag length too big', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'mysupertagtoolong', 'tag1' ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - - it('Should fail with malformed tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'my tag' ] - } - requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) - }) - }) - - describe('When getting a video', function () { - it('Should return the list of the videos with nothing', function (done) { - request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(function (err, res) { - if (err) throw err - - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(3) - - done() - }) - }) - - it('Should fail without a correct uuid', function (done) { - request(server.url) - .get(path + 'coucou') - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should return 404 with an incorrect video', function (done) { - request(server.url) - .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') - .set('Accept', 'application/json') - .expect(404, done) - }) - - it('Should succeed with the correct parameters') - }) - - describe('When removing a video', function () { - it('Should have 404 with nothing', function (done) { - request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should fail without a correct uuid', function (done) { - request(server.url) - .delete(path + 'hello') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should fail with a video which does not exist', function (done) { - request(server.url) - .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(404, done) - }) - - it('Should fail with a video of another user') - - it('Should fail with a video of another pod') - - it('Should succeed with the correct parameters') - }) - }) - - describe('Of the users API', function () { - const path = '/api/v1/users/' - let userId = null - let rootId = null - - describe('When listing users', function () { - it('Should fail with a bad start pagination', function (done) { - request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad count pagination', function (done) { - request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with an incorrect sort', function (done) { - request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - }) - - describe('When adding a new user', function () { - it('Should fail with a too small username', function (done) { - const data = { - username: 'ji', - password: 'mysuperpassword' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with a too long username', function (done) { - const data = { - username: 'mysuperusernamewhichisverylong', - password: 'mysuperpassword' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with an incorrect username', function (done) { - const data = { - username: 'my username', - password: 'mysuperpassword' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with a too small password', function (done) { - const data = { - username: 'myusername', - password: 'bla' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with a too long password', function (done) { - const data = { - username: 'myusername', - password: 'my super long password which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very veryv very very very very' + - 'very very very very very very very very very very very very very very very very very very very very long' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with an non authenticated user', function (done) { - const data = { - username: 'myusername', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) - }) - - it('Should fail if we add a user with the same username', function (done) { - const data = { - username: 'user1', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) - }) - - it('Should succeed with the correct params', function (done) { - const data = { - username: 'user2', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) - }) - - it('Should fail with a non admin user', function (done) { - server.user = { - username: 'user1', - password: 'password' - } - - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) throw err - - userAccessToken = accessToken - - const data = { - username: 'user3', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) - }) - }) - }) - - describe('When updating a user', function () { - before(function (done) { - usersUtils.getUsersList(server.url, function (err, res) { - if (err) throw err - - userId = res.body.data[1].id - rootId = res.body.data[2].id - done() - }) - }) - - it('Should fail with a too small password', function (done) { - const data = { - password: 'bla' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) - }) - - it('Should fail with a too long password', function (done) { - const data = { - password: 'my super long password which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very veryv very very very very' + - 'very very very very very very very very very very very very very very very very very very very very long' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) - }) - - it('Should fail with an non authenticated user', function (done) { - const data = { - password: 'my super password' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) - }) - - it('Should succeed with the correct params', function (done) { - const data = { - password: 'my super password' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) - }) - }) - - describe('When getting my information', function () { - it('Should fail with a non authenticated user', function (done) { - request(server.url) - .get(path + 'me') - .set('Authorization', 'Bearer faketoken') - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should success with the correct parameters', function (done) { - request(server.url) - .get(path + 'me') - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(200, done) - }) - }) - - describe('When removing an user', function () { - it('Should fail with an incorrect id', function (done) { - request(server.url) - .delete(path + 'bla-bla') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should fail with the root user', function (done) { - request(server.url) - .delete(path + rootId) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should return 404 with a non existing id', function (done) { - request(server.url) - .delete(path + '45') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(404, done) - }) - }) - }) - - describe('Of the remote videos API', function () { - describe('When making a secure request', function () { - it('Should check a secure request') - }) - - describe('When adding a video', function () { - it('Should check when adding a video') - }) - - describe('When removing a video', function () { - it('Should check when removing a video') - }) - }) - - describe('Of the requests API', function () { - const path = '/api/v1/requests/stats' - - it('Should fail with an non authenticated user', function (done) { - request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should fail with a non admin user', function (done) { - request(server.url) - .get(path) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403, done) - }) - }) - - after(function (done) { - process.kill(-server.app.pid) - - // Keep the logs if the test failed - if (this.ok) { - serversUtils.flushTests(done) - } else { - done() - } - }) -}) diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js new file mode 100644 index 000000000..3d6f09267 --- /dev/null +++ b/server/tests/api/check-params/index.js @@ -0,0 +1,8 @@ +'use strict' + +// Order of the tests we want to execute +require('./pods') +require('./remotes') +require('./users') +require('./requests') +require('./videos') diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js new file mode 100644 index 000000000..2f85af644 --- /dev/null +++ b/server/tests/api/check-params/pods.js @@ -0,0 +1,204 @@ +'use strict' + +const request = require('supertest') +const series = require('async/series') + +const loginUtils = require('../../utils/login') +const requestsUtils = require('../../utils/requests') +const serversUtils = require('../../utils/servers') +const usersUtils = require('../../utils/users') + +describe('Test pods API validators', function () { + const path = '/api/v1/pods/' + let server = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + } + ], done) + }) + + describe('When making friends', function () { + let userAccessToken = null + + before(function (done) { + usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { + server.user = { + username: 'user1', + password: 'password' + } + + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + done() + }) + }) + }) + + describe('When making friends', function () { + const body = { + hosts: [ 'localhost:9002' ] + } + + it('Should fail without hosts', function (done) { + request(server.url) + .post(path + '/makefriends') + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail if hosts is not an array', function (done) { + request(server.url) + .post(path + '/makefriends') + .send({ hosts: 'localhost:9002' }) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail if the array is not composed by hosts', function (done) { + request(server.url) + .post(path + '/makefriends') + .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail if the array is composed with http schemes', function (done) { + request(server.url) + .post(path + '/makefriends') + .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail if hosts are not unique', function (done) { + request(server.url) + .post(path + '/makefriends') + .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a invalid token', function (done) { + request(server.url) + .post(path + '/makefriends') + .send(body) + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail if the user is not an administrator', function (done) { + request(server.url) + .post(path + '/makefriends') + .send(body) + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(403, done) + }) + }) + + describe('When quitting friends', function () { + it('Should fail with a invalid token', function (done) { + request(server.url) + .get(path + '/quitfriends') + .query({ start: 'hello' }) + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail if the user is not an administrator', function (done) { + request(server.url) + .get(path + '/quitfriends') + .query({ start: 'hello' }) + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(403, done) + }) + }) + }) + + describe('When adding a pod', function () { + it('Should fail with nothing', function (done) { + const data = {} + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without public key', function (done) { + const data = { + host: 'coucou.com' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without an host', function (done) { + const data = { + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail with an incorrect host', function (done) { + const data = { + host: 'http://coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { + data.host = 'http://coucou' + requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { + data.host = 'coucou' + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + }) + }) + + it('Should succeed with the correct parameters', function (done) { + const data = { + host: 'coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) + }) + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js new file mode 100644 index 000000000..30ba3b697 --- /dev/null +++ b/server/tests/api/check-params/remotes.js @@ -0,0 +1,60 @@ +'use strict' + +const series = require('async/series') + +const loginUtils = require('../../utils/login') +const serversUtils = require('../../utils/servers') + +describe('Test remote videos API validators', function () { + let server = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + } + ], done) + }) + + describe('When making a secure request', function () { + it('Should check a secure request') + }) + + describe('When adding a video', function () { + it('Should check when adding a video') + }) + + describe('When removing a video', function () { + it('Should check when removing a video') + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/check-params/requests.js b/server/tests/api/check-params/requests.js new file mode 100644 index 000000000..08f58db43 --- /dev/null +++ b/server/tests/api/check-params/requests.js @@ -0,0 +1,87 @@ +'use strict' + +const request = require('supertest') +const series = require('async/series') + +const loginUtils = require('../../utils/login') +const usersUtils = require('../../utils/users') +const serversUtils = require('../../utils/servers') + +describe('Test requests API validators', function () { + const path = '/api/v1/requests/stats' + let server = null + let userAccessToken = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + }, + function (next) { + const username = 'user' + const password = 'my super password' + + usersUtils.createUser(server.url, server.accessToken, username, password, next) + }, + function (next) { + const user = { + username: 'user', + password: 'my super password' + } + + loginUtils.getUserAccessToken(server, user, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + next() + }) + } + ], done) + }) + + it('Should fail with an non authenticated user', function (done) { + request(server.url) + .get(path) + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail with a non admin user', function (done) { + request(server.url) + .get(path) + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(403, done) + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js new file mode 100644 index 000000000..c1fcf34a4 --- /dev/null +++ b/server/tests/api/check-params/users.js @@ -0,0 +1,284 @@ +'use strict' + +const request = require('supertest') +const series = require('async/series') + +const loginUtils = require('../../utils/login') +const requestsUtils = require('../../utils/requests') +const serversUtils = require('../../utils/servers') +const usersUtils = require('../../utils/users') + +describe('Test users API validators', function () { + const path = '/api/v1/users/' + let userId = null + let rootId = null + let server = null + let userAccessToken = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + }, + function (next) { + const username = 'user1' + const password = 'my super password' + + usersUtils.createUser(server.url, server.accessToken, username, password, next) + }, + function (next) { + const user = { + username: 'user1', + password: 'my super password' + } + + loginUtils.getUserAccessToken(server, user, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + next() + }) + } + ], done) + }) + + describe('When listing users', function () { + it('Should fail with a bad start pagination', function (done) { + request(server.url) + .get(path) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad count pagination', function (done) { + request(server.url) + .get(path) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with an incorrect sort', function (done) { + request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + }) + + describe('When adding a new user', function () { + it('Should fail with a too small username', function (done) { + const data = { + username: 'ji', + password: 'mysuperpassword' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a too long username', function (done) { + const data = { + username: 'mysuperusernamewhichisverylong', + password: 'mysuperpassword' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with an incorrect username', function (done) { + const data = { + username: 'my username', + password: 'mysuperpassword' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a too small password', function (done) { + const data = { + username: 'myusername', + password: 'bla' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a too long password', function (done) { + const data = { + username: 'myusername', + password: 'my super long password which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very veryv very very very very' + + 'very very very very very very very very very very very very very very very very very very very very long' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with an non authenticated user', function (done) { + const data = { + username: 'myusername', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) + }) + + it('Should fail if we add a user with the same username', function (done) { + const data = { + username: 'user1', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) + }) + + it('Should succeed with the correct params', function (done) { + const data = { + username: 'user2', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) + }) + + it('Should fail with a non admin user', function (done) { + server.user = { + username: 'user1', + password: 'my super password' + } + + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + const data = { + username: 'user3', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) + }) + }) + }) + + describe('When updating a user', function () { + before(function (done) { + usersUtils.getUsersList(server.url, function (err, res) { + if (err) throw err + + userId = res.body.data[1].id + rootId = res.body.data[2].id + done() + }) + }) + + it('Should fail with a too small password', function (done) { + const data = { + password: 'bla' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) + }) + + it('Should fail with a too long password', function (done) { + const data = { + password: 'my super long password which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very veryv very very very very' + + 'very very very very very very very very very very very very very very very very very very very very long' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) + }) + + it('Should fail with an non authenticated user', function (done) { + const data = { + password: 'my super password' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) + }) + + it('Should succeed with the correct params', function (done) { + const data = { + password: 'my super password' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) + }) + }) + + describe('When getting my information', function () { + it('Should fail with a non authenticated user', function (done) { + request(server.url) + .get(path + 'me') + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should success with the correct parameters', function (done) { + request(server.url) + .get(path + 'me') + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(200, done) + }) + }) + + describe('When removing an user', function () { + it('Should fail with an incorrect id', function (done) { + request(server.url) + .delete(path + 'bla-bla') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail with the root user', function (done) { + request(server.url) + .delete(path + rootId) + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should return 404 with a non existing id', function (done) { + request(server.url) + .delete(path + '45') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(404, done) + }) + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js new file mode 100644 index 000000000..d18305291 --- /dev/null +++ b/server/tests/api/check-params/videos.js @@ -0,0 +1,456 @@ +'use strict' + +const chai = require('chai') +const expect = chai.expect +const pathUtils = require('path') +const request = require('supertest') +const series = require('async/series') + +const loginUtils = require('../../utils/login') +const requestsUtils = require('../../utils/requests') +const serversUtils = require('../../utils/servers') +const videosUtils = require('../../utils/videos') + +describe('Test videos API validator', function () { + const path = '/api/v1/videos/' + let server = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + } + ], done) + }) + + describe('When listing a video', function () { + it('Should fail with a bad start pagination', function (done) { + request(server.url) + .get(path) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad count pagination', function (done) { + request(server.url) + .get(path) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with an incorrect sort', function (done) { + request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + }) + + describe('When searching a video', function () { + it('Should fail with nothing', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search')) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad start pagination', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search', 'test')) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad count pagination', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search', 'test')) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with an incorrect sort', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search', 'test')) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + }) + + describe('When adding a video', function () { + it('Should fail with nothing', function (done) { + const data = {} + const attach = {} + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without name', function (done) { + const data = { + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a long name', function (done) { + const data = { + name: 'My very very very very very very very very very very very very very very very very long name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without description', function (done) { + const data = { + name: 'my super name', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a long description', function (done) { + const data = { + name: 'my super name', + description: 'my super description which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very long', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description' + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with too many tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with not enough tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a tag length too low', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 't' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a tag length too big', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'mysupertagtoolong', 'tag1' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with malformed tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'my tag' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without an input file', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = {} + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without an incorrect input file', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a too big duration', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should succeed with the correct parameters', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { + attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4') + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { + attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv') + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) + }, false) + }, false) + }) + }) + + describe('When updating a video', function () { + let videoId + + before(function (done) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + videoId = res.body.data[0].id + + return done() + }) + }) + + it('Should fail with nothing', function (done) { + const data = {} + requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail without a valid uuid', function (done) { + const data = { + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) + }) + + it('Should fail with an unknown id', function (done) { + const data = { + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404) + }) + + it('Should fail with a long name', function (done) { + const data = { + name: 'My very very very very very very very very very very very very very very very very long name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with a long description', function (done) { + const data = { + name: 'my super name', + description: 'my super description which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very long', + tags: [ 'tag1', 'tag2' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with too many tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with not enough tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with a tag length too low', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 't' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with a tag length too big', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'mysupertagtoolong', 'tag1' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + + it('Should fail with malformed tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'my tag' ] + } + requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) + }) + }) + + describe('When getting a video', function () { + it('Should return the list of the videos with nothing', function (done) { + request(server.url) + .get(path) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(function (err, res) { + if (err) throw err + + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(3) + + done() + }) + }) + + it('Should fail without a correct uuid', function (done) { + request(server.url) + .get(path + 'coucou') + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should return 404 with an incorrect video', function (done) { + request(server.url) + .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') + .set('Accept', 'application/json') + .expect(404, done) + }) + + it('Should succeed with the correct parameters') + }) + + describe('When removing a video', function () { + it('Should have 404 with nothing', function (done) { + request(server.url) + .delete(path) + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail without a correct uuid', function (done) { + request(server.url) + .delete(path + 'hello') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail with a video which does not exist', function (done) { + request(server.url) + .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(404, done) + }) + + it('Should fail with a video of another user') + + it('Should fail with a video of another pod') + + it('Should succeed with the correct parameters') + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/utils/login.js b/server/tests/utils/login.js index 465564e14..c984c0baf 100644 --- a/server/tests/utils/login.js +++ b/server/tests/utils/login.js @@ -4,7 +4,8 @@ const request = require('supertest') const loginUtils = { login, - loginAndGetAccessToken + loginAndGetAccessToken, + getUserAccessToken } // ---------------------- Export functions -------------------- @@ -43,6 +44,14 @@ function loginAndGetAccessToken (server, callback) { }) } +function getUserAccessToken (server, user, callback) { + login(server.url, server.client, user, 200, function (err, res) { + if (err) return callback(err) + + return callback(null, res.body.access_token) + }) +} + // --------------------------------------------------------------------------- module.exports = loginUtils diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js index e7c756499..1946ef49a 100644 --- a/server/tests/utils/servers.js +++ b/server/tests/utils/servers.js @@ -34,7 +34,7 @@ function flushAndRunMultipleServers (totalServers, serversRun) { runServer(j, function (app, url) { anotherServerDone(j, app, url) }) - }, 1000 * j) + }, 1000 * (j - 1)) } }) } -- cgit v1.2.3 From 55fa55a9be566cca2ba95322f2ae23b434aed62a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Jan 2017 20:59:23 +0100 Subject: Server: add video abuse support --- server/tests/api/check-params/index.js | 1 + server/tests/api/check-params/remotes.js | 4 + server/tests/api/check-params/video-abuses.js | 180 ++++++++++++++++++++++++ server/tests/api/friends-advanced.js | 10 +- server/tests/api/friends-basic.js | 12 +- server/tests/api/video-abuse.js | 191 ++++++++++++++++++++++++++ server/tests/utils/video-abuses.js | 73 ++++++++++ 7 files changed, 460 insertions(+), 11 deletions(-) create mode 100644 server/tests/api/check-params/video-abuses.js create mode 100644 server/tests/api/video-abuse.js create mode 100644 server/tests/utils/video-abuses.js (limited to 'server/tests') diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js index 3d6f09267..d0824f08a 100644 --- a/server/tests/api/check-params/index.js +++ b/server/tests/api/check-params/index.js @@ -6,3 +6,4 @@ require('./remotes') require('./users') require('./requests') require('./videos') +require('./video-abuses') diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js index 30ba3b697..c1ab9fb2b 100644 --- a/server/tests/api/check-params/remotes.js +++ b/server/tests/api/check-params/remotes.js @@ -47,6 +47,10 @@ describe('Test remote videos API validators', function () { it('Should check when removing a video') }) + describe('When reporting abuse on a video', function () { + it('Should check when reporting a video abuse') + }) + after(function (done) { process.kill(-server.app.pid) diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js new file mode 100644 index 000000000..8cb4ccdc1 --- /dev/null +++ b/server/tests/api/check-params/video-abuses.js @@ -0,0 +1,180 @@ +'use strict' + +const request = require('supertest') +const series = require('async/series') + +const loginUtils = require('../../utils/login') +const requestsUtils = require('../../utils/requests') +const serversUtils = require('../../utils/servers') +const usersUtils = require('../../utils/users') +const videosUtils = require('../../utils/videos') + +describe('Test video abuses API validators', function () { + let server = null + let userAccessToken = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + }, + function (next) { + const username = 'user1' + const password = 'my super password' + + usersUtils.createUser(server.url, server.accessToken, username, password, next) + }, + function (next) { + const user = { + username: 'user1', + password: 'my super password' + } + + loginUtils.getUserAccessToken(server, user, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + next() + }) + }, + // Upload some videos on each pods + function (next) { + const name = 'my super name for pod' + const description = 'my super description for pod' + const tags = [ 'tag' ] + const file = 'video_short2.webm' + videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) + }, + function (next) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + server.video = videos[0] + + next() + }) + } + ], done) + }) + + describe('When listing video abuses', function () { + const path = '/api/v1/videos/abuse' + + it('Should fail with a bad start pagination', function (done) { + request(server.url) + .get(path) + .query({ start: 'hello' }) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad count pagination', function (done) { + request(server.url) + .get(path) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail with an incorrect sort', function (done) { + request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail with a non authenticated user', function (done) { + request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail with a non admin user', function (done) { + request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + userAccessToken) + .expect(403, done) + }) + }) + + describe('When reporting a video abuse', function () { + const basePath = '/api/v1/videos/' + + it('Should fail with nothing', function (done) { + const path = basePath + server.video + '/abuse' + const data = {} + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a wrong video', function (done) { + const wrongPath = '/api/v1/videos/blabla/abuse' + const data = {} + requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done) + }) + + it('Should fail with a non authenticated user', function (done) { + const data = {} + const path = basePath + server.video + '/abuse' + requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) + }) + + it('Should fail with a reason too short', function (done) { + const data = { + reason: 'h' + } + const path = basePath + server.video + '/abuse' + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a reason too big', function (done) { + const data = { + reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + + '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + + '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + + '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + } + const path = basePath + server.video + '/abuse' + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js index 0a2d58d82..708138bc9 100644 --- a/server/tests/api/friends-advanced.js +++ b/server/tests/api/friends-advanced.js @@ -86,7 +86,7 @@ describe('Test advanced friends', function () { getFriendsList(5, function (err, res) { if (err) throw err - expect(res.body.length).to.equal(0) + expect(res.body.data.length).to.equal(0) done() }) @@ -111,7 +111,7 @@ describe('Test advanced friends', function () { getFriendsList(i, function (err, res) { if (err) throw err - expect(res.body.length).to.equal(0) + expect(res.body.data.length).to.equal(0) callback() }) @@ -140,7 +140,7 @@ describe('Test advanced friends', function () { getFriendsList(i, function (err, res) { if (err) throw err - expect(res.body.length).to.equal(3) + expect(res.body.data.length).to.equal(3) callback() }) @@ -182,7 +182,7 @@ describe('Test advanced friends', function () { if (err) throw err // Pod 4 didn't know pod 1 and 2 removed it - expect(res.body.length).to.equal(3) + expect(res.body.data.length).to.equal(3) next() }) }, @@ -200,7 +200,7 @@ describe('Test advanced friends', function () { if (err) throw err // Pod 4 should not be our friend - const result = res.body + const result = res.body.data expect(result.length).to.equal(3) for (const pod of result) { expect(pod.host).not.equal(servers[3].host) diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js index 3a904dbd7..6f37ff291 100644 --- a/server/tests/api/friends-basic.js +++ b/server/tests/api/friends-basic.js @@ -28,7 +28,7 @@ describe('Test basic friends', function () { podsUtils.getFriendsList(serverToTest.url, function (err, res) { if (err) throw err - const result = res.body + const result = res.body.data expect(result).to.be.an('array') expect(result.length).to.equal(2) @@ -65,7 +65,7 @@ describe('Test basic friends', function () { podsUtils.getFriendsList(server.url, function (err, res) { if (err) throw err - const result = res.body + const result = res.body.data expect(result).to.be.an('array') expect(result.length).to.equal(0) callback() @@ -90,7 +90,7 @@ describe('Test basic friends', function () { podsUtils.getFriendsList(servers[1].url, function (err, res) { if (err) throw err - const result = res.body + const result = res.body.data expect(result).to.be.an('array') expect(result.length).to.equal(1) @@ -107,7 +107,7 @@ describe('Test basic friends', function () { podsUtils.getFriendsList(servers[2].url, function (err, res) { if (err) throw err - const result = res.body + const result = res.body.data expect(result).to.be.an('array') expect(result.length).to.equal(1) @@ -154,7 +154,7 @@ describe('Test basic friends', function () { podsUtils.getFriendsList(servers[1].url, function (err, res) { if (err) throw err - const result = res.body + const result = res.body.data expect(result).to.be.an('array') expect(result.length).to.equal(0) @@ -167,7 +167,7 @@ describe('Test basic friends', function () { podsUtils.getFriendsList(url, function (err, res) { if (err) throw err - const result = res.body + const result = res.body.data expect(result).to.be.an('array') expect(result.length).to.equal(1) expect(result[0].host).not.to.be.equal(servers[1].host) diff --git a/server/tests/api/video-abuse.js b/server/tests/api/video-abuse.js new file mode 100644 index 000000000..58db17c42 --- /dev/null +++ b/server/tests/api/video-abuse.js @@ -0,0 +1,191 @@ +'use strict' + +const chai = require('chai') +const each = require('async/each') +const expect = chai.expect +const series = require('async/series') + +const loginUtils = require('../utils/login') +const podsUtils = require('../utils/pods') +const serversUtils = require('../utils/servers') +const videosUtils = require('../utils/videos') +const videoAbusesUtils = require('../utils/video-abuses') + +describe('Test video abuses', function () { + let servers = [] + + before(function (done) { + this.timeout(30000) + + series([ + // Run servers + function (next) { + serversUtils.flushAndRunMultipleServers(2, function (serversRun) { + servers = serversRun + next() + }) + }, + // Get the access tokens + function (next) { + each(servers, function (server, callbackEach) { + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) return callbackEach(err) + + server.accessToken = accessToken + callbackEach() + }) + }, next) + }, + // Pod 1 make friends too + function (next) { + const server = servers[0] + podsUtils.makeFriends(server.url, server.accessToken, next) + }, + // Upload some videos on each pods + function (next) { + const name = 'my super name for pod 1' + const description = 'my super description for pod 1' + const tags = [ 'tag' ] + const file = 'video_short2.webm' + videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) + }, + function (next) { + const name = 'my super name for pod 2' + const description = 'my super description for pod 2' + const tags = [ 'tag' ] + const file = 'video_short2.webm' + videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) + }, + // Wait videos propagation + function (next) { + setTimeout(next, 11000) + }, + function (next) { + videosUtils.getVideosList(servers[0].url, function (err, res) { + if (err) throw err + + const videos = res.body.data + + expect(videos.length).to.equal(2) + + servers[0].video = videos.find(function (video) { return video.name === 'my super name for pod 1' }) + servers[1].video = videos.find(function (video) { return video.name === 'my super name for pod 2' }) + + next() + }) + } + ], done) + }) + + it('Should not have video abuses', function (done) { + videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + + it('Should report abuse on a local video', function (done) { + this.timeout(15000) + + const reason = 'my super bad reason' + videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason, function (err) { + if (err) throw err + + // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2 + setTimeout(done, 11000) + }) + }) + + it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done) { + videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + const abuse = res.body.data[0] + expect(abuse.reason).to.equal('my super bad reason') + expect(abuse.reporterUsername).to.equal('root') + expect(abuse.reporterPodHost).to.equal('localhost:9001') + expect(abuse.videoId).to.equal(servers[0].video.id) + + videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + }) + + it('Should report abuse on a remote video', function (done) { + this.timeout(15000) + + const reason = 'my super bad reason 2' + videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason, function (err) { + if (err) throw err + + // We wait requests propagation + setTimeout(done, 11000) + }) + }) + + it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done) { + videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(2) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(2) + + let abuse = res.body.data[0] + expect(abuse.reason).to.equal('my super bad reason') + expect(abuse.reporterUsername).to.equal('root') + expect(abuse.reporterPodHost).to.equal('localhost:9001') + expect(abuse.videoId).to.equal(servers[0].video.id) + + abuse = res.body.data[1] + expect(abuse.reason).to.equal('my super bad reason 2') + expect(abuse.reporterUsername).to.equal('root') + expect(abuse.reporterPodHost).to.equal('localhost:9001') + expect(abuse.videoId).to.equal(servers[1].video.id) + + videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + let abuse = res.body.data[0] + expect(abuse.reason).to.equal('my super bad reason 2') + expect(abuse.reporterUsername).to.equal('root') + expect(abuse.reporterPodHost).to.equal('localhost:9001') + + done() + }) + }) + }) + + after(function (done) { + servers.forEach(function (server) { + process.kill(-server.app.pid) + }) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/utils/video-abuses.js b/server/tests/utils/video-abuses.js new file mode 100644 index 000000000..596c824b3 --- /dev/null +++ b/server/tests/utils/video-abuses.js @@ -0,0 +1,73 @@ +'use strict' + +const request = require('supertest') + +const videosUtils = { + getVideoAbusesList, + getVideoAbusesListPagination, + getVideoAbusesListSort, + reportVideoAbuse +} + +// ---------------------- Export functions -------------------- + +function reportVideoAbuse (url, token, videoId, reason, specialStatus, end) { + if (!end) { + end = specialStatus + specialStatus = 204 + } + + const path = '/api/v1/videos/' + videoId + '/abuse' + + request(url) + .post(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + token) + .send({ reason }) + .expect(specialStatus) + .end(end) +} + +function getVideoAbusesList (url, token, end) { + const path = '/api/v1/videos/abuse' + + request(url) + .get(path) + .query({ sort: 'createdAt' }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + token) + .expect(200) + .expect('Content-Type', /json/) + .end(end) +} + +function getVideoAbusesListPagination (url, token, start, count, end) { + const path = '/api/v1/videos/abuse' + + request(url) + .get(path) + .query({ start: start }) + .query({ count: count }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + token) + .expect(200) + .expect('Content-Type', /json/) + .end(end) +} + +function getVideoAbusesListSort (url, token, sort, end) { + const path = '/api/v1/videos/abuse' + + request(url) + .get(path) + .query({ sort: sort }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + token) + .expect(200) + .expect('Content-Type', /json/) + .end(end) +} + +// --------------------------------------------------------------------------- + +module.exports = videosUtils -- cgit v1.2.3 From bb0b243c92577872a5f4d98f707e078082af4d2a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 Jan 2017 23:24:20 +0100 Subject: Server: improve real world script --- server/tests/real-world/real-world.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'server/tests') diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index 2ae3dc15b..751d3923f 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -2,6 +2,7 @@ const each = require('async/each') const isEqual = require('lodash/isEqual') +const differenceWith = require('lodash/differenceWith') const program = require('commander') const series = require('async/series') @@ -20,28 +21,35 @@ program .option('-a, --action [interval]', 'Interval in ms for an action') .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') .option('-f, --flush', 'Flush datas on exit') + .option('-d, --difference', 'Display difference if integrity is not okay') .parse(process.argv) -const createWeight = parseInt(program.create) || 5 -const removeWeight = parseInt(program.remove) || 4 +const createWeight = program.create !== undefined ? parseInt(program.create) : 5 +const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 const flushAtExit = program.flush || false -const actionInterval = parseInt(program.action) || 500 -let integrityInterval = parseInt(program.integrity) || 60000 +const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 +let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 +const displayDiffOnFail = program.integrity || false const numberOfPods = 6 + // Wait requests between pods -const requestsMaxPerInterval = constants.REQUESTS_INTERVAL / actionInterval +const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL +const requestsMaxPerInterval = baseRequestInterval / actionInterval const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 -integrityInterval += waitForBeforeIntegrityCheck - console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) if (flushAtExit) { console.log('Program will flush data on exit.') } else { console.log('Program will not flush data on exit.') } +if (displayDiffOnFail) { + console.log('Program will display diff on failure.') +} else { + console.log('Program will not display diff on failure') +} console.log('Interval in ms for each action: %d.', actionInterval) console.log('Interval in ms for each integrity check: %d.', integrityInterval) console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) @@ -73,6 +81,8 @@ runServers(numberOfPods, function (err, servers) { }, actionInterval) setInterval(function () { + if (checking === true) return + console.log('Checking integrity...') checking = true @@ -196,6 +206,7 @@ function checkIntegrity (servers, callback) { delete serverVideo.id delete serverVideo.isLocal delete serverVideo.thumbnailPath + delete serverVideo.updatedAt } videos.push(serverVideos) @@ -206,6 +217,10 @@ function checkIntegrity (servers, callback) { if (!isEqual(video, videos[0])) { console.error('Integrity not ok!') + if (displayDiffOnFail) { + console.log(differenceWith(videos[0], video, isEqual)) + } + process.exit(-1) } } -- cgit v1.2.3 From d8cc063e9775688a1631eda9203411a2dba0333c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Jan 2017 18:06:51 +0100 Subject: Server: do not break remote videos processing on error --- server/tests/real-world/real-world.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests') diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index 751d3923f..9a63860ad 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -36,7 +36,7 @@ const numberOfPods = 6 // Wait requests between pods const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL const requestsMaxPerInterval = baseRequestInterval / actionInterval -const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) +const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) -- cgit v1.2.3 From 45abb8b97b8313f8f58a4a73b527882ad7b4af9c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Jan 2017 18:41:09 +0100 Subject: Server: rights check for update a video --- server/tests/api/check-params/videos.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'server/tests') diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js index d18305291..fac903715 100644 --- a/server/tests/api/check-params/videos.js +++ b/server/tests/api/check-params/videos.js @@ -378,6 +378,10 @@ describe('Test videos API validator', function () { } requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) }) + + it('Should fail with a video of another user') + + it('Should fail with a video of another pod') }) describe('When getting a video', function () { -- cgit v1.2.3 From f2cdb86675c3783ee903640b5b6f794fa09cdff2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Jan 2017 18:41:28 +0100 Subject: Server: add update case to real world script --- server/tests/real-world/real-world.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'server/tests') diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index 9a63860ad..896ba6cce 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -17,6 +17,7 @@ const videosUtils = require('../utils/videos') program .option('-c, --create [weight]', 'Weight for creating videos') .option('-r, --remove [weight]', 'Weight for removing videos') + .option('-u, --update [weight]', 'Weight for updating videos') .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3) .option('-a, --action [interval]', 'Interval in ms for an action') .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') @@ -26,6 +27,7 @@ program const createWeight = program.create !== undefined ? parseInt(program.create) : 5 const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 +const updateWeight = program.update !== undefined ? parseInt(program.update) : 4 const flushAtExit = program.flush || false const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 @@ -39,7 +41,7 @@ const requestsMaxPerInterval = baseRequestInterval / actionInterval const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 -console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) +console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight) if (flushAtExit) { console.log('Program will flush data on exit.') } else { @@ -71,10 +73,12 @@ runServers(numberOfPods, function (err, servers) { setInterval(function () { if (checking === true) return - const rand = getRandomInt(0, createWeight + removeWeight) + const rand = getRandomInt(0, createWeight + updateWeight + removeWeight) if (rand < createWeight) { upload(servers, getRandomNumServer(servers)) + } else if (rand < createWeight + updateWeight) { + update(servers, getRandomNumServer(servers)) } else { remove(servers, getRandomNumServer(servers)) } @@ -180,6 +184,26 @@ function upload (servers, numServer, callback) { videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) } +function update (servers, numServer, callback) { + if (!callback) callback = function () {} + + videosUtils.getVideosList(servers[numServer].url, function (err, res) { + if (err) throw err + + const videos = res.body.data.filter(function (video) { return video.isLocal }) + if (videos.length === 0) return callback() + + const toUpdate = videos[getRandomInt(0, videos.length)].id + const name = Date.now() + ' name' + const description = Date.now() + ' description' + const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] + + console.log('Updating video of server ' + numServer) + + videosUtils.updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, name, description, tags, callback) + }) +} + function remove (servers, numServer, callback) { if (!callback) callback = function () {} -- cgit v1.2.3 From 7f4e7c36373217b8e92cf227c71999a0ce9a15d9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Jan 2017 09:47:21 +0100 Subject: Server: fix update remote video infohash --- server/tests/api/multiple-pods.js | 29 +++++++++++++++++++++++------ server/tests/api/single-pod.js | 19 +++++++++++++++++-- server/tests/real-world/real-world.js | 2 +- 3 files changed, 41 insertions(+), 9 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 4442a7ff7..169a9f2e0 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -4,7 +4,8 @@ const chai = require('chai') const each = require('async/each') const expect = chai.expect const series = require('async/series') -const webtorrent = new (require('webtorrent'))() +const WebTorrent = require('webtorrent') +const webtorrent = new WebTorrent() const loginUtils = require('../utils/login') const miscsUtils = require('../utils/miscs') @@ -311,7 +312,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -330,7 +331,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -349,7 +350,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -368,7 +369,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -390,7 +391,12 @@ describe('Test multiple pods', function () { }) it('Should have the video 3 updated on each pod', function (done) { + this.timeout(200000) + each(servers, function (server, callback) { + // Avoid "duplicate torrent" errors + const webtorrent = new WebTorrent() + videosUtils.getVideosList(server.url, function (err, res) { if (err) throw err @@ -404,7 +410,18 @@ describe('Test multiple pods', function () { expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true - callback() + videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + webtorrent.add(videoUpdated.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + webtorrent.remove(videoUpdated.magnetUri, callback) + }) + }) }) }, done) }) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 29512dfc6..04b93fac7 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -96,7 +96,7 @@ describe('Test a single pod', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -515,6 +515,8 @@ describe('Test a single pod', function () { }) it('Should have the video updated', function (done) { + this.timeout(60000) + videosUtils.getVideo(server.url, videoId, function (err, res) { if (err) throw err @@ -529,7 +531,20 @@ describe('Test a single pod', function () { expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true - done() + videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + videoId = video.id + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + done() + }) + }) }) }) diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index 896ba6cce..941e43a2e 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -38,7 +38,7 @@ const numberOfPods = 6 // Wait requests between pods const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL const requestsMaxPerInterval = baseRequestInterval / actionInterval -const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) +const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD) const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight) -- cgit v1.2.3 From 790e65fcf7a0a9f065ecc68c5982efb80cd2e1ca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Jan 2017 10:06:03 +0100 Subject: Try to fix travis build --- server/tests/api/multiple-pods.js | 10 +++++----- server/tests/api/single-pod.js | 2 +- server/tests/real-world/real-world.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 169a9f2e0..df12ba0e9 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -312,7 +312,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -331,7 +331,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -350,7 +350,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -369,7 +369,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -419,7 +419,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(videoUpdated.magnetUri, callback) + callback() }) }) }) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 04b93fac7..2ac83bbf4 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -96,7 +96,7 @@ describe('Test a single pod', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index 941e43a2e..12ab06d6d 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -30,16 +30,16 @@ const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 const updateWeight = program.update !== undefined ? parseInt(program.update) : 4 const flushAtExit = program.flush || false const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 -let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 +const integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 const displayDiffOnFail = program.integrity || false const numberOfPods = 6 // Wait requests between pods -const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL +const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? constants.REQUESTS_INTERVAL : integrityInterval const requestsMaxPerInterval = baseRequestInterval / actionInterval const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD) -const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 +const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) - integrityInterval + 1000 console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight) if (flushAtExit) { -- cgit v1.2.3 From 91cc839af88730ba55f84997c56b85ea100070a7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Jan 2017 13:08:47 +0100 Subject: Server: fix single pod tests --- server/tests/api/single-pod.js | 52 +++++++++++++++++++--------------------- server/tests/utils/videos.js | 54 +++++++++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 46 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 2ac83bbf4..2db60448f 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -338,69 +338,69 @@ describe('Test a single pod', function () { }) it('Should list only the two first videos', function (done) { - videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) { + videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(2) - expect(videos[0].name === videosListBase[0].name) - expect(videos[1].name === videosListBase[1].name) + expect(videos[0].name).to.equal(videosListBase[0].name) + expect(videos[1].name).to.equal(videosListBase[1].name) done() }) }) it('Should list only the next three videos', function (done) { - videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) { + videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(3) - expect(videos[0].name === videosListBase[2].name) - expect(videos[1].name === videosListBase[3].name) - expect(videos[2].name === videosListBase[4].name) + expect(videos[0].name).to.equal(videosListBase[2].name) + expect(videos[1].name).to.equal(videosListBase[3].name) + expect(videos[2].name).to.equal(videosListBase[4].name) done() }) }) it('Should list the last video', function (done) { - videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) { + videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(1) - expect(videos[0].name === videosListBase[5].name) + expect(videos[0].name).to.equal(videosListBase[5].name) done() }) }) it('Should search the first video', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(4) expect(videos.length).to.equal(1) - expect(videos[0].name === 'video_short.webm name') + expect(videos[0].name).to.equal('video_short1.webm name') done() }) }) it('Should search the last two videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(4) expect(videos.length).to.equal(2) - expect(videos[0].name === 'video_short2.webm name') - expect(videos[1].name === 'video_short3.webm name') + expect(videos[0].name).to.equal('video_short3.webm name') + expect(videos[1].name).to.equal('video_short.webm name') done() }) @@ -476,12 +476,12 @@ describe('Test a single pod', function () { const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(6) - expect(videos[5].name === 'video_short.mp4 name') - expect(videos[4].name === 'video_short.ogv name') - expect(videos[3].name === 'video_short.webm name') - expect(videos[2].name === 'video_short1.webm name') - expect(videos[1].name === 'video_short2.webm name') - expect(videos[0].name === 'video_short3.webm name') + expect(videos[0].name).to.equal('video_short.webm name') + expect(videos[1].name).to.equal('video_short.ogv name') + expect(videos[2].name).to.equal('video_short.mp4 name') + expect(videos[3].name).to.equal('video_short3.webm name') + expect(videos[4].name).to.equal('video_short2.webm name') + expect(videos[5].name).to.equal('video_short1.webm name') done() }) @@ -495,12 +495,12 @@ describe('Test a single pod', function () { expect(res.body.total).to.equal(4) expect(videos.length).to.equal(4) - expect(videos[0].name === 'video_short.webm name') - expect(videos[1].name === 'video_short1.webm name') - expect(videos[2].name === 'video_short2.webm name') - expect(videos[3].name === 'video_short3.webm name') + expect(videos[0].name).to.equal('video_short1.webm name') + expect(videos[1].name).to.equal('video_short2.webm name') + expect(videos[2].name).to.equal('video_short3.webm name') + expect(videos[3].name).to.equal('video_short.webm name') - videoId = videos[3].id + videoId = videos[2].id done() }) @@ -535,8 +535,6 @@ describe('Test a single pod', function () { if (err) throw err expect(test).to.equal(true) - videoId = video.id - webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist expect(torrent.files.length).to.equal(1) diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js index beafd3cf5..f94368437 100644 --- a/server/tests/utils/videos.js +++ b/server/tests/utils/videos.js @@ -58,17 +58,25 @@ function getVideosList (url, end) { .end(end) } -function getVideosListPagination (url, start, count, end) { +function getVideosListPagination (url, start, count, sort, end) { + if (!end) { + end = sort + sort = null + } + const path = '/api/v1/videos' - request(url) - .get(path) - .query({ start: start }) - .query({ count: count }) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(end) + const req = request(url) + .get(path) + .query({ start: start }) + .query({ count: count }) + + if (sort) req.query({ sort }) + + req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) } function getVideosListSort (url, sort, end) { @@ -116,18 +124,26 @@ function searchVideo (url, search, field, end) { .end(end) } -function searchVideoWithPagination (url, search, field, start, count, end) { +function searchVideoWithPagination (url, search, field, start, count, sort, end) { + if (!end) { + end = sort + sort = null + } + const path = '/api/v1/videos' - request(url) - .get(path + '/search/' + search) - .query({ start: start }) - .query({ count: count }) - .query({ field: field }) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(end) + const req = request(url) + .get(path + '/search/' + search) + .query({ start: start }) + .query({ count: count }) + .query({ field: field }) + + if (sort) req.query({ sort }) + + req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) } function searchVideoWithSort (url, search, sort, end) { -- cgit v1.2.3