const logger = require('../../../helpers/logger')
const friends = require('../../../lib/friends')
-const middleware = require('../../../middlewares')
+const middlewares = require('../../../middlewares')
const Pods = require('../../../models/pods')
-const reqValidator = middleware.reqValidators.pods
-const secureMiddleware = middleware.secure
-const secureRequest = middleware.reqValidators.remote.secureRequest
+const oAuth2 = middlewares.oauth2
+const reqValidator = middlewares.reqValidators.pods
+const secureMiddleware = middlewares.secure
+const secureRequest = middlewares.reqValidators.remote.secureRequest
const videos = require('../../../lib/videos')
const Videos = require('../../../models/videos')
router.get('/', listPods)
router.post('/', reqValidator.podsAdd, addPods)
-router.get('/makefriends', reqValidator.makeFriends, makeFriends)
-router.get('/quitfriends', quitFriends)
+router.get('/makefriends', oAuth2.authenticate, reqValidator.makeFriends, makeFriends)
+router.get('/quitfriends', oAuth2.authenticate, quitFriends)
// Post because this is a secured request
router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods)
const express = require('express')
const map = require('lodash/map')
-const middleware = require('../../../middlewares')
-const secureMiddleware = middleware.secure
-const reqValidator = middleware.reqValidators.remote
+const middlewares = require('../../../middlewares')
+const secureMiddleware = middlewares.secure
+const reqValidator = middlewares.reqValidators.remote
const logger = require('../../../helpers/logger')
const Videos = require('../../../models/videos')
const videos = require('../../../lib/videos')
const config = require('config')
const express = require('express')
-const oAuth2 = require('../../../middlewares/oauth2')
+const oAuth2 = require('../../../middlewares').oauth2
const Users = require('../../../models/users')
const constants = require('../../../initializers/constants')
const logger = require('../../../helpers/logger')
const friends = require('../../../lib/friends')
-const middleware = require('../../../middlewares')
-const oAuth2 = require('../../../middlewares/oauth2')
-const reqValidator = middleware.reqValidators.videos
+const middlewares = require('../../../middlewares')
+const oAuth2 = middlewares.oauth2
+const reqValidator = middlewares.reqValidators.videos
const utils = require('../../../helpers/utils')
const Videos = require('../../../models/videos') // model
const videos = require('../../../lib/videos')
'use strict'
+const oauth2 = require('./oauth2')
const reqValidatorsMiddleware = require('./reqValidators')
const secureMiddleware = require('./secure')
const middlewares = {
+ oauth2: oauth2,
reqValidators: reqValidatorsMiddleware,
secure: secureMiddleware
}
let servers = []
function makeFriends (podNumber, callback) {
- return utils.makeFriends(servers[podNumber - 1].url, callback)
+ const server = servers[podNumber - 1]
+ return utils.makeFriends(server.url, server.accessToken, callback)
}
function quitFriends (podNumber, callback) {
- return utils.quitFriends(servers[podNumber - 1].url, callback)
+ const server = servers[podNumber - 1]
+ return utils.quitFriends(server.url, server.accessToken, callback)
}
function getFriendsList (podNumber, end) {
- return utils.getFriendsList(servers[podNumber - 1].url, end)
+ const server = servers[podNumber - 1]
+ return utils.getFriendsList(server.url, end)
}
function uploadVideo (podNumber, callback) {
const async = require('async')
const chai = require('chai')
const expect = chai.expect
-const request = require('supertest')
const utils = require('./utils')
describe('Test basic friends', function () {
let servers = []
+ function makeFriends (podNumber, callback) {
+ const server = servers[podNumber - 1]
+ return utils.makeFriends(server.url, server.accessToken, callback)
+ }
+
function testMadeFriends (servers, serverToTest, callback) {
const friends = []
for (let i = 0; i < servers.length; i++) {
this.timeout(20000)
utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
servers = serversRun
- done()
+
+ async.each(servers, function (server, callbackEach) {
+ utils.loginAndGetAccessToken(server, function (err, accessToken) {
+ if (err) return callbackEach(err)
+
+ server.accessToken = accessToken
+ callbackEach()
+ })
+ }, done)
})
})
it('Should make friends', function (done) {
this.timeout(10000)
- const path = '/api/v1/pods/makefriends'
-
async.series([
// The second pod make friend with the third
function (next) {
- request(servers[1].url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(204)
- .end(next)
+ makeFriends(2, next)
},
// Wait for the request between pods
function (next) {
},
// Finally the first pod make friend with the second pod
function (next) {
- request(servers[0].url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(204)
- .end(next)
+ makeFriends(1, next)
},
// Wait for the request between pods
function (next) {
})
it('Should not be allowed to make friend again', function (done) {
- utils.makeFriends(servers[1].url, 409, done)
+ const server = servers[1]
+ utils.makeFriends(server.url, server.accessToken, 409, done)
})
it('Should quit friends of pod 2', function (done) {
async.series([
// Pod 1 quit friends
function (next) {
- utils.quitFriends(servers[1].url, next)
+ const server = servers[1]
+ utils.quitFriends(server.url, server.accessToken, next)
},
// Pod 1 should not have friends anymore
function (next) {
})
it('Should allow pod 2 to make friend again', function (done) {
- utils.makeFriends(servers[1].url, function () {
+ const server = servers[1]
+ utils.makeFriends(server.url, server.accessToken, function () {
async.each(servers, function (server, callback) {
testMadeFriends(servers, server, callback)
}, done)
},
// The second pod make friend with the third
function (next) {
- utils.makeFriends(servers[1].url, next)
+ const server = servers[1]
+ utils.makeFriends(server.url, server.accessToken, next)
},
// Wait for the request between pods
function (next) {
},
// Pod 1 make friends too
function (next) {
- utils.makeFriends(servers[0].url, next)
+ const server = servers[0]
+ utils.makeFriends(server.url, server.accessToken, next)
},
function (next) {
webtorrent.create({ host: 'client', port: '1' }, next)
utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done)
})
+ it('Should not be able to make friends', function (done) {
+ accessToken = 'mysupertoken'
+ utils.makeFriends(server.url, accessToken, 401, done)
+ })
+
+ it('Should not be able to quit friends', function (done) {
+ accessToken = 'mysupertoken'
+ utils.quitFriends(server.url, accessToken, 401, done)
+ })
+
it('Should be able to login', function (done) {
utils.login(server.url, server.client, server.user, 200, function (err, res) {
if (err) throw err
})
}
-function makeFriends (url, expectedStatus, callback) {
+function makeFriends (url, accessToken, expectedStatus, callback) {
if (!callback) {
callback = expectedStatus
expectedStatus = 204
request(url)
.get(path)
.set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
.end(function (err, res) {
if (err) throw err
})
}
-function quitFriends (url, callback) {
+function quitFriends (url, accessToken, expectedStatus, callback) {
+ if (!callback) {
+ callback = expectedStatus
+ expectedStatus = 204
+ }
+
const path = '/api/v1/pods/quitfriends'
// The first pod make friend with the third
request(url)
.get(path)
.set('Accept', 'application/json')
- .expect(204)
+ .set('Authorization', 'Bearer ' + accessToken)
+ .expect(expectedStatus)
.end(function (err, res) {
if (err) throw err