aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/tracker.ts17
-rw-r--r--server/tests/api/activitypub/refresher.ts2
-rw-r--r--server/tests/api/server/email.ts1
-rw-r--r--server/tests/api/users/index.ts4
-rw-r--r--server/tests/api/users/user-notifications.ts4
-rw-r--r--server/tests/api/users/users-verification.ts3
-rw-r--r--shared/utils/miscs/email.ts17
7 files changed, 34 insertions, 14 deletions
diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts
index 53f1653b5..1deb8c402 100644
--- a/server/controllers/tracker.ts
+++ b/server/controllers/tracker.ts
@@ -6,6 +6,7 @@ import * as proxyAddr from 'proxy-addr'
6import { Server as WebSocketServer } from 'ws' 6import { Server as WebSocketServer } from 'ws'
7import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' 7import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants'
8import { VideoFileModel } from '../models/video/video-file' 8import { VideoFileModel } from '../models/video/video-file'
9import { parse } from 'url'
9 10
10const TrackerServer = bitTorrentTracker.Server 11const TrackerServer = bitTorrentTracker.Server
11 12
@@ -61,14 +62,24 @@ trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { act
61 62
62function createWebsocketTrackerServer (app: express.Application) { 63function createWebsocketTrackerServer (app: express.Application) {
63 const server = http.createServer(app) 64 const server = http.createServer(app)
64 const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) 65 const wss = new WebSocketServer({ noServer: true })
66
65 wss.on('connection', function (ws, req) { 67 wss.on('connection', function (ws, req) {
66 const ip = proxyAddr(req, CONFIG.TRUST_PROXY) 68 ws['ip'] = proxyAddr(req, CONFIG.TRUST_PROXY)
67 ws['ip'] = ip
68 69
69 trackerServer.onWebSocketConnection(ws) 70 trackerServer.onWebSocketConnection(ws)
70 }) 71 })
71 72
73 server.on('upgrade', (request, socket, head) => {
74 const pathname = parse(request.url).pathname
75
76 if (pathname === '/tracker/socket') {
77 wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
78 }
79
80 // Don't destroy socket, we have Socket.IO too
81 })
82
72 return server 83 return server
73} 84}
74 85
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index 332ea7ed1..62ad8a0b5 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -22,7 +22,7 @@ describe('Test AP refresher', function () {
22 let videoUUID3: string 22 let videoUUID3: string
23 23
24 before(async function () { 24 before(async function () {
25 this.timeout(30000) 25 this.timeout(60000)
26 26
27 servers = await flushAndRunMultipleServers(2) 27 servers = await flushAndRunMultipleServers(2)
28 28
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index b8d29ef81..f96c57b66 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -251,6 +251,7 @@ describe('Test emails', function () {
251 }) 251 })
252 252
253 after(async function () { 253 after(async function () {
254 MockSmtpServer.Instance.kill()
254 killallServers([ server ]) 255 killallServers([ server ])
255 }) 256 })
256}) 257})
diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts
index 63e6e827a..52ba6984e 100644
--- a/server/tests/api/users/index.ts
+++ b/server/tests/api/users/index.ts
@@ -1,6 +1,6 @@
1import './users-verification'
2import './user-notifications'
1import './blocklist' 3import './blocklist'
2import './user-subscriptions' 4import './user-subscriptions'
3import './user-notifications'
4import './users' 5import './users'
5import './users-multiple-servers' 6import './users-multiple-servers'
6import './users-verification'
diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts
index ad68d8e69..5260d64cc 100644
--- a/server/tests/api/users/user-notifications.ts
+++ b/server/tests/api/users/user-notifications.ts
@@ -175,7 +175,7 @@ describe('Test users notifications', function () {
175 }) 175 })
176 176
177 it('Should send a new video notification if the user follows the local video publisher', async function () { 177 it('Should send a new video notification if the user follows the local video publisher', async function () {
178 this.timeout(10000) 178 this.timeout(15000)
179 179
180 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') 180 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
181 await waitJobs(servers) 181 await waitJobs(servers)
@@ -1010,6 +1010,8 @@ describe('Test users notifications', function () {
1010 }) 1010 })
1011 1011
1012 after(async function () { 1012 after(async function () {
1013 MockSmtpServer.Instance.kill()
1014
1013 killallServers(servers) 1015 killallServers(servers)
1014 }) 1016 })
1015}) 1017})
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index afc8a0059..babeda2b8 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -4,7 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, 6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers,
7 userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig 7 userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait
8} from '../../../../shared/utils' 8} from '../../../../shared/utils'
9import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 9import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
10import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 10import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
@@ -123,6 +123,7 @@ describe('Test users account verification', function () {
123 }) 123 })
124 124
125 after(async function () { 125 after(async function () {
126 MockSmtpServer.Instance.kill()
126 killallServers([ server ]) 127 killallServers([ server ])
127 128
128 // Keep the logs if the test failed 129 // Keep the logs if the test failed
diff --git a/shared/utils/miscs/email.ts b/shared/utils/miscs/email.ts
index 108f7d3d9..6fac7621f 100644
--- a/shared/utils/miscs/email.ts
+++ b/shared/utils/miscs/email.ts
@@ -1,22 +1,20 @@
1import * as child from 'child_process' 1import { fork, ChildProcess } from 'child_process'
2 2
3class MockSmtpServer { 3class MockSmtpServer {
4 4
5 private static instance: MockSmtpServer 5 private static instance: MockSmtpServer
6 private started = false 6 private started = false
7 private emailChildProcess: child.ChildProcess 7 private emailChildProcess: ChildProcess
8 private emails: object[] 8 private emails: object[]
9 9
10 private constructor () { 10 private constructor () {
11 this.emailChildProcess = child.fork(`${__dirname}/email-child-process`, [], { silent: true }) 11 this.emailChildProcess = fork(`${__dirname}/email-child-process`, [])
12
12 this.emailChildProcess.on('message', (msg) => { 13 this.emailChildProcess.on('message', (msg) => {
13 if (msg.email) { 14 if (msg.email) {
14 return this.emails.push(msg.email) 15 return this.emails.push(msg.email)
15 } 16 }
16 }) 17 })
17 process.on('exit', () => {
18 this.emailChildProcess.kill()
19 })
20 } 18 }
21 19
22 collectEmails (emailsCollection: object[]) { 20 collectEmails (emailsCollection: object[]) {
@@ -43,6 +41,13 @@ class MockSmtpServer {
43 }) 41 })
44 } 42 }
45 43
44 kill () {
45 process.kill(this.emailChildProcess.pid)
46
47 this.emailChildProcess = null
48 MockSmtpServer.instance = null
49 }
50
46 static get Instance () { 51 static get Instance () {
47 return this.instance || (this.instance = new this()) 52 return this.instance || (this.instance = new this())
48 } 53 }