aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-19 08:58:34 +0100
committerChocobozzz <me@florianbigard.com>2020-11-19 09:07:20 +0100
commitfce7fe04eed39e23e76717085e92118e963def81 (patch)
tree767e5c92cbed548d2b5fb27ce1e6236da4ebdbcf /server
parent4ddcb7c3bad4e98d05d25298f7f11353a639b360 (diff)
downloadPeerTube-fce7fe04eed39e23e76717085e92118e963def81.tar.gz
PeerTube-fce7fe04eed39e23e76717085e92118e963def81.tar.zst
PeerTube-fce7fe04eed39e23e76717085e92118e963def81.zip
Update server dependencies
Diffstat (limited to 'server')
-rw-r--r--server/lib/peertube-socket.ts3
-rw-r--r--server/middlewares/oauth.ts8
-rw-r--r--server/tests/api/check-params/user-notifications.ts14
3 files changed, 11 insertions, 14 deletions
diff --git a/server/lib/peertube-socket.ts b/server/lib/peertube-socket.ts
index c4df399ca..5fc5bc20b 100644
--- a/server/lib/peertube-socket.ts
+++ b/server/lib/peertube-socket.ts
@@ -1,4 +1,3 @@
1import { Socket } from 'dgram'
2import { Server } from 'http' 1import { Server } from 'http'
3import * as SocketIO from 'socket.io' 2import * as SocketIO from 'socket.io'
4import { MVideo } from '@server/types/models' 3import { MVideo } from '@server/types/models'
@@ -18,7 +17,7 @@ class PeerTubeSocket {
18 private constructor () {} 17 private constructor () {}
19 18
20 init (server: Server) { 19 init (server: Server) {
21 const io = SocketIO(server) 20 const io = new SocketIO.Server(server)
22 21
23 io.of('/user-notifications') 22 io.of('/user-notifications')
24 .use(authenticateSocket) 23 .use(authenticateSocket)
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index b1149174b..bd60a3639 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { logger } from '../helpers/logger'
3import { Socket } from 'socket.io' 2import { Socket } from 'socket.io'
4import { getAccessToken } from '../lib/oauth-model'
5import { oAuthServer } from '@server/lib/auth' 3import { oAuthServer } from '@server/lib/auth'
4import { logger } from '../helpers/logger'
5import { getAccessToken } from '../lib/oauth-model'
6 6
7function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { 7function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) {
8 const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {} 8 const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {}
@@ -24,7 +24,7 @@ function authenticate (req: express.Request, res: express.Response, next: expres
24} 24}
25 25
26function authenticateSocket (socket: Socket, next: (err?: any) => void) { 26function authenticateSocket (socket: Socket, next: (err?: any) => void) {
27 const accessToken = socket.handshake.query.accessToken 27 const accessToken = socket.handshake.query['accessToken']
28 28
29 logger.debug('Checking socket access token %s.', accessToken) 29 logger.debug('Checking socket access token %s.', accessToken)
30 30
@@ -38,7 +38,7 @@ function authenticateSocket (socket: Socket, next: (err?: any) => void) {
38 return next(new Error('Invalid access token.')) 38 return next(new Error('Invalid access token.'))
39 } 39 }
40 40
41 socket.handshake.query.user = tokenDB.User 41 socket.handshake.query['user'] = tokenDB.User
42 42
43 return next() 43 return next()
44 }) 44 })
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 4aab7eba4..6fa0502be 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import * as io from 'socket.io-client' 4import { io } from 'socket.io-client'
5 5
6import { 6import {
7 cleanupTests, 7 cleanupTests,
@@ -235,11 +235,11 @@ describe('Test user notifications API validators', function () {
235 }) 235 })
236 236
237 describe('When connecting to my notification socket', function () { 237 describe('When connecting to my notification socket', function () {
238
238 it('Should fail with no token', function (next) { 239 it('Should fail with no token', function (next) {
239 const socket = io(`http://localhost:${server.port}/user-notifications`, { reconnection: false }) 240 const socket = io(`http://localhost:${server.port}/user-notifications`, { reconnection: false })
240 241
241 socket.on('error', function () { 242 socket.once('connect_error', function () {
242 socket.removeListener('error', this)
243 socket.disconnect() 243 socket.disconnect()
244 next() 244 next()
245 }) 245 })
@@ -256,8 +256,7 @@ describe('Test user notifications API validators', function () {
256 reconnection: false 256 reconnection: false
257 }) 257 })
258 258
259 socket.on('error', function () { 259 socket.once('connect_error', function () {
260 socket.removeListener('error', this)
261 socket.disconnect() 260 socket.disconnect()
262 next() 261 next()
263 }) 262 })
@@ -278,10 +277,9 @@ describe('Test user notifications API validators', function () {
278 next(new Error('Error in connection: ' + err)) 277 next(new Error('Error in connection: ' + err))
279 } 278 }
280 279
281 socket.on('error', errorListener) 280 socket.on('connect_error', errorListener)
282 281
283 socket.on('connect', async () => { 282 socket.once('connect', async () => {
284 socket.removeListener('error', errorListener)
285 socket.disconnect() 283 socket.disconnect()
286 284
287 await wait(500) 285 await wait(500)